Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions dot/network/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,12 @@ func createDecoder(info *notificationsProtocol, handshakeDecoder HandshakeDecode
}

// createNotificationsMessageHandler returns a function that is called by the handler of *inbound* streams.
func (s *Service) createNotificationsMessageHandler(info *notificationsProtocol,
func (s *Service) createNotificationsMessageHandler(
info *notificationsProtocol,
messageHandler NotificationsMessageHandler,
batchHandler NotificationsMessageBatchHandler) messageHandler {
batchHandler NotificationsMessageBatchHandler,
) messageHandler {

Comment thread
kishansagathiya marked this conversation as resolved.
Outdated
return func(stream libp2pnetwork.Stream, m Message) error {
if m == nil || info == nil || info.handshakeValidator == nil || messageHandler == nil {
Comment thread
kishansagathiya marked this conversation as resolved.
Outdated
return nil
Expand Down Expand Up @@ -201,6 +204,7 @@ func (s *Service) createNotificationsMessageHandler(info *notificationsProtocol,
info.inboundHandshakeData.Store(peer, hsData)

// once validated, send back a handshake
// TODO: getHandshake creates a new handshake struct. Rename?
Comment thread
kishansagathiya marked this conversation as resolved.
Outdated
resp, err := info.getHandshake()
if err != nil {
logger.Warnf("failed to get handshake using protocol %s: %s", info.protocolID, err)
Expand All @@ -214,6 +218,10 @@ func (s *Service) createNotificationsMessageHandler(info *notificationsProtocol,
}

logger.Tracef("receiver: sent handshake to peer %s using protocol %s", peer, info.protocolID)

if err := stream.CloseWrite(); err != nil {
logger.Tracef("failed to close stream for writing: %s", err)
}
}

return nil
Expand Down Expand Up @@ -380,6 +388,10 @@ func (s *Service) sendHandshake(peer peer.ID, hs Handshake, info *notificationsP
hsData.received = true
}

if err := stream.CloseRead(); err != nil {
logger.Tracef("failed to close stream for reading: %s", err)
}

if err = info.handshakeValidator(peer, resp); err != nil {
logger.Tracef("failed to validate handshake from peer %s using protocol %s: %s", peer, info.protocolID, err)
hsData.validated = false
Expand Down