|
|
@ -122,16 +122,11 @@ func (s *Server) accept(nc net.Conn, brw *bufio.ReadWriter) error {
|
|
|
|
if clientInfo != nil {
|
|
|
|
if clientInfo != nil {
|
|
|
|
c.info = *clientInfo
|
|
|
|
c.info = *clientInfo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
if err := c.keepAlive(ctx); err != nil {
|
|
|
|
|
|
|
|
s.logf("derp: %s: client %x: keep alive failed: %v", nc.RemoteAddr(), c.key, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
s.mu.Lock()
|
|
|
|
s.mu.Lock()
|
|
|
|
curClient := s.clients[c.key]
|
|
|
|
curClient := s.clients[c.key]
|
|
|
|
if curClient != nil && curClient.nc == nc {
|
|
|
|
if curClient == c {
|
|
|
|
s.logf("derp: %s: client %x: removing connection", nc.RemoteAddr(), c.key)
|
|
|
|
s.logf("derp: %s: client %x: removing connection", nc.RemoteAddr(), c.key)
|
|
|
|
delete(s.clients, c.key)
|
|
|
|
delete(s.clients, c.key)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -159,6 +154,12 @@ func (s *Server) accept(nc net.Conn, brw *bufio.ReadWriter) error {
|
|
|
|
s.logf("derp: %s: client %x: adding connection, replacing %s", nc.RemoteAddr(), c.key, oldClient.nc.RemoteAddr())
|
|
|
|
s.logf("derp: %s: client %x: adding connection, replacing %s", nc.RemoteAddr(), c.key, oldClient.nc.RemoteAddr())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
if err := c.keepAlive(ctx); err != nil {
|
|
|
|
|
|
|
|
s.logf("derp: %s: client %x: keep alive failed: %v", nc.RemoteAddr(), c.key, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
dstKey, contents, err := s.recvPacket(c.br)
|
|
|
|
dstKey, contents, err := s.recvPacket(c.br)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|