Remove obsolete code

This commit is contained in:
Viktor Liu
2025-09-01 14:10:42 +02:00
parent 6d99d451d6
commit 96e95856cf
3 changed files with 16 additions and 106 deletions
+9 -19
View File
@@ -223,10 +223,10 @@ func (c *Client) OpenConn(ctx context.Context, dstPeerID string) (net.Conn, erro
c.mu.Unlock()
return nil, fmt.Errorf("relay connection is not established")
}
existingContainer, ok := c.conns[peerID]
_, ok := c.conns[peerID]
if ok {
c.mu.Unlock()
return existingContainer.conn, nil
return nil, ErrConnAlreadyExists
}
c.mu.Unlock()
@@ -235,6 +235,7 @@ func (c *Client) OpenConn(ctx context.Context, dstPeerID string) (net.Conn, erro
return nil, err
}
c.log.Infof("remote peer is available, prepare the relayed connection: %s", peerID)
msgChannel := make(chan Msg, 100)
c.mu.Lock()
@@ -248,11 +249,11 @@ func (c *Client) OpenConn(ctx context.Context, dstPeerID string) (net.Conn, erro
c.muInstanceURL.Unlock()
conn := NewConn(c, peerID, msgChannel, instanceURL)
existingContainer, ok = c.conns[peerID]
_, ok = c.conns[peerID]
if ok {
c.mu.Unlock()
_ = conn.Close()
return existingContainer.conn, nil
return nil, ErrConnAlreadyExists
}
c.conns[peerID] = newConnContainer(c.log, conn, msgChannel)
c.mu.Unlock()
@@ -376,6 +377,7 @@ func (c *Client) readLoop(hc *healthcheck.Receiver, relayConn net.Conn, internal
buf := *bufPtr
n, errExit = relayConn.Read(buf)
if errExit != nil {
c.log.Infof("start to Relay read loop exit")
c.mu.Lock()
if c.serviceIsRunning && !internallyStoppedFlag.isSet() {
c.log.Errorf("failed to read message from relay server: %s", errExit)
@@ -466,24 +468,12 @@ func (c *Client) handleTransportMsg(buf []byte, bufPtr *[]byte, internallyStoppe
c.bufPool.Put(bufPtr)
return false
}
container, ok := c.conns[*peerID]
c.mu.Unlock()
if !ok {
// Try to create a connection for this peer to handle incoming messages
msgChannel := make(chan Msg, 100)
c.muInstanceURL.Lock()
instanceURL := c.instanceURL
c.muInstanceURL.Unlock()
conn := NewConn(c, *peerID, msgChannel, instanceURL)
c.mu.Lock()
// Check again if connection was created while we were creating it
if _, exists := c.conns[*peerID]; !exists {
c.conns[*peerID] = newConnContainer(c.log, conn, msgChannel)
}
container = c.conns[*peerID]
c.mu.Unlock()
c.log.Errorf("peer not found: %s", peerID.String())
c.bufPool.Put(bufPtr)
return true
}
msg := Msg{
bufPool: c.bufPool,