Skip to content

Commit

Permalink
better peer close error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed May 5, 2024
1 parent a0c60c2 commit ffa75d4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions p2p/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (me *Peer) connectRelayer(relayer *Peer) error {
if err != nil {
return err
}
defer client.Close()
defer client.Close("connectRelayer")
defer relayer.disconnect()

auth := me.handle.BuildAuthenticationMessage(relayer.IdForNetwork)
Expand Down Expand Up @@ -211,7 +211,7 @@ func (me *Peer) ListenConsumers() error {
continue
}
go func(c Client) {
defer c.Close()
defer c.Close("authenticateNeighbor")

peer, err := me.authenticateNeighbor(c)
logger.Printf("me.authenticateNeighbor(%s, %s) => %v %v", me.Address, c.RemoteAddr().String(), peer, err)
Expand All @@ -237,7 +237,7 @@ func (me *Peer) ListenConsumers() error {

func (me *Peer) loopSendingStream(p *Peer, consumer Client) (*ChanMsg, error) {
defer close(p.ops)
defer consumer.Close()
defer consumer.Close("loopSendingStream")

graphTicker := time.NewTicker(time.Duration(config.SnapshotRoundGap / 2))
defer graphTicker.Stop()
Expand Down Expand Up @@ -306,10 +306,10 @@ func (me *Peer) loopReceiveMessage(peer *Peer, client Client) {
logger.Printf("me.loopReceiveMessage(%s, %s)", me.Address, client.RemoteAddr().String())
receive := make(chan *PeerMessage, 1024)
defer close(receive)
defer client.Close()
defer client.Close("loopReceiveMessage")

go func() {
defer client.Close()
defer client.Close("handlePeerMessage")

for msg := range receive {
err := me.handlePeerMessage(peer.IdForNetwork, msg)
Expand Down
4 changes: 2 additions & 2 deletions p2p/quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ func (c *QuicClient) Send(data []byte) error {
return err
}

func (c *QuicClient) Close() error {
func (c *QuicClient) Close(code string) error {
c.stream.Close()
return c.session.CloseWithError(0, "DONE")
return c.session.CloseWithError(0, code)
}

func generateTLSConfig() *tls.Config {
Expand Down
2 changes: 1 addition & 1 deletion p2p/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Client interface {
RemoteAddr() net.Addr
Receive() (*TransportMessage, error)
Send([]byte) error
Close() error
Close(string) error
}

type Transport interface {
Expand Down

0 comments on commit ffa75d4

Please sign in to comment.