Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-sirotin committed Jul 14, 2024
1 parent ae0bbcb commit fff4413
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
17 changes: 6 additions & 11 deletions internal/transport/waku.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewNode(ctx context.Context, logger *zap.Logger) *Node {
return &Node{
waku: nil,
ctx: ctx,
logger: logger,
logger: logger.Named("waku"),
pubsubTopic: FleetName(config.Fleet()).DefaultPubsubTopic(),
peerConnection: nil,
roomCache: NewRoomCache(logger),
Expand All @@ -68,14 +68,13 @@ func (n *Node) Initialize() error {
}
}

peerConnection := make(chan node.PeerConnection)
n.peerConnection = make(chan node.PeerConnection)

options := []node.WakuNodeOption{
node.WithLogger(n.logger.Named("waku")),
//node.WithDNS4Domain(),
node.WithLogger(n.logger),
node.WithLogLevel(zap.DebugLevel),
node.WithHostAddress(hostAddr),
node.WithConnectionNotification(peerConnection),
node.WithConnectionNotification(n.peerConnection),
}

if config.WakuDiscV5() {
Expand All @@ -97,9 +96,7 @@ func (n *Node) Initialize() error {
)
}

fleet := FleetName(config.Fleet())

if fleet.IsSharded() {
if FleetName(config.Fleet()).IsSharded() {
options = append(options,
node.WithClusterID(DefaultClusterID),
)
Expand All @@ -113,8 +110,6 @@ func (n *Node) Initialize() error {
}

n.waku = wakuNode
n.peerConnection = peerConnection
n.logger = n.logger.Named("waku")
n.connectedPeers = make(map[peer.ID]struct{})

return nil
Expand Down Expand Up @@ -365,7 +360,7 @@ func (n *Node) watchConnectionStatus() {
} else {
delete(n.connectedPeers, status.PeerID)
}
//count := n.waku.PeerCount()
// using manual calculation instead of n.waku.PeerCount() for simpler testing
count := len(n.connectedPeers)
n.notifyConnectionStatus(ConnectionStatus{
IsOnline: count > 0,
Expand Down
14 changes: 14 additions & 0 deletions internal/transport/waku_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ func (s *WakuSuite) TestWatchConnectionStatus() {

sub := s.node.SubscribeToConnectionStatus()

finished := make(chan struct{})

go func() {
s.node.watchConnectionStatus()
close(finished)
}()

sent := node.PeerConnection{
PeerID: peer.ID(gofakeit.UUID()),
Connected: true,
Expand All @@ -113,4 +120,11 @@ func (s *WakuSuite) TestWatchConnectionStatus() {
}

close(s.node.peerConnection)

select {
case <-finished:
break
case <-time.After(500 * time.Millisecond):
s.Require().Fail("timeout waiting for connection status watch finish")
}
}

0 comments on commit fff4413

Please sign in to comment.