Skip to content

Commit

Permalink
dkg/sync: move connected logs to server (#771)
Browse files Browse the repository at this point in the history
Moves connected logs to server and removes inbound and outbound logs from client and server.

category: bug
ticket: #762
  • Loading branch information
dB2510 committed Jul 7, 2022
1 parent ccdba1e commit d6f6951
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 0 additions & 1 deletion dkg/sync/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func (c *Client) Run(ctx context.Context) error {
return err
}

log.Info(ctx, "Connected to peer (outbound)")
c.setConnected()

reconnect, err := c.sendMsgs(ctx, stream)
Expand Down
9 changes: 6 additions & 3 deletions dkg/sync/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package sync
import (
"context"
"encoding/binary"
"fmt"
"io"
"sync"
"time"
Expand Down Expand Up @@ -122,11 +123,13 @@ func (s *Server) isConnected(pID peer.ID) bool {
}

// setConnected sets the shared connected state for the peer.
func (s *Server) setConnected(pID peer.ID) {
func (s *Server) setConnected(pID peer.ID) int {
s.mu.Lock()
defer s.mu.Unlock()

s.connected[pID] = struct{}{}

return len(s.connected)
}

// clearConnected clears the shared connected state for the peer.
Expand Down Expand Up @@ -202,8 +205,8 @@ func (s *Server) handleStream(ctx context.Context, stream network.Stream) error

log.Error(ctx, "Received mismatching cluster definition hash from peer", nil)
} else if ok && !s.isConnected(pID) {
log.Info(ctx, "Connected to peer (inbound)")
s.setConnected(pID)
count := s.setConnected(pID)
log.Info(ctx, fmt.Sprintf("Connected to peer %d of %d", count, s.allCount))
}

// Write response message
Expand Down

0 comments on commit d6f6951

Please sign in to comment.