@@ -131,7 +131,6 @@ func (s *Service) createNotificationsMessageHandler(info *notificationsProtocol,
131131 err := handshakeValidator (peer , hs )
132132 if err != nil {
133133 logger .Trace ("failed to validate handshake" , "protocol" , info .protocolID , "peer" , peer , "error" , err )
134- _ = stream .Conn ().Close ()
135134 return errCannotValidateHandshake
136135 }
137136
@@ -141,17 +140,17 @@ func (s *Service) createNotificationsMessageHandler(info *notificationsProtocol,
141140 // once validated, send back a handshake
142141 resp , err := info .getHandshake ()
143142 if err != nil {
144- logger .Debug ("failed to get handshake" , "protocol" , info .protocolID , "error" , err )
143+ logger .Warn ("failed to get handshake" , "protocol" , info .protocolID , "error" , err )
145144 return err
146145 }
147146
148- err = s .host .send ( peer , info . protocolID , resp )
147+ err = s .host .writeToStream ( stream , resp )
149148 if err != nil {
150149 logger .Trace ("failed to send handshake" , "protocol" , info .protocolID , "peer" , peer , "error" , err )
151- _ = stream .Conn ().Close ()
152150 return err
153151 }
154152 logger .Trace ("receiver: sent handshake" , "protocol" , info .protocolID , "peer" , peer )
153+ return nil
155154 }
156155
157156 // if we are the initiator and haven't received the handshake already, validate it
@@ -161,7 +160,6 @@ func (s *Service) createNotificationsMessageHandler(info *notificationsProtocol,
161160 if err != nil {
162161 logger .Trace ("failed to validate handshake" , "protocol" , info .protocolID , "peer" , peer , "error" , err )
163162 hsData .validated = false
164- _ = stream .Conn ().Close ()
165163 return errCannotValidateHandshake
166164 }
167165
@@ -175,7 +173,7 @@ func (s *Service) createNotificationsMessageHandler(info *notificationsProtocol,
175173 // if we are the initiator, send the message
176174 if hsData , has := info .getHandshakeData (peer ); has && hsData .validated && hsData .received && hsData .outboundMsg != nil {
177175 logger .Trace ("sender: sending message" , "protocol" , info .protocolID )
178- err := s .host .send ( peer , info . protocolID , hsData .outboundMsg )
176+ err := s .host .writeToStream ( stream , hsData .outboundMsg )
179177 if err != nil {
180178 logger .Debug ("failed to send message" , "protocol" , info .protocolID , "peer" , peer , "error" , err )
181179 return err
@@ -197,11 +195,14 @@ func (s *Service) createNotificationsMessageHandler(info *notificationsProtocol,
197195 }
198196
199197 // TODO: improve this by keeping track of who you've received/sent messages from
200- if ! s .noGossip {
201- seen := s .gossip .hasSeen (msg )
202- if ! seen {
203- s .broadcastExcluding (info , peer , msg )
204- }
198+ if s .noGossip {
199+ return nil
200+ }
201+
202+ seen := s .gossip .hasSeen (msg )
203+ if ! seen {
204+ // TODO: update this to write to stream w/ handshake established
205+ s .broadcastExcluding (info , peer , msg )
205206 }
206207
207208 return nil
@@ -261,7 +262,7 @@ func (s *Service) broadcastExcluding(info *notificationsProtocol, excluding peer
261262 }
262263
263264 if err != nil {
264- logger .Error ("failed to send message to peer" , "peer" , peer , "error" , err )
265+ logger .Debug ("failed to send message to peer" , "peer" , peer , "error" , err )
265266 }
266267 }
267268}
0 commit comments