@@ -325,11 +325,40 @@ func (ac *client) handleDialBack(s network.Stream) {
325325 }
326326}
327327
328+ var tlsWSAddr = ma .StringCast ("/tls/ws" )
329+
328330// normalizeMultiaddr returns a multiaddr suitable for equality checks.
329- // it removes trailing certhashes.
331+ // it removes trailing certhashes and p2p components, removes sni components,
332+ // and translates /wss to /tls/ws.
333+ // Remove sni components because there's no way for us to verify whether the
334+ // correct sni was dialled by the remote host as the LocalAddr on the websocket conn
335+ // doesn't have sni information.
336+ // Note: This is used for comparing two addresses where both the addresses are
337+ // controlled by the host not by a remote node.
330338func normalizeMultiaddr (addr ma.Multiaddr ) ma.Multiaddr {
331339 addr = removeTrailing (addr , ma .P_P2P )
332340 addr = removeTrailing (addr , ma .P_CERTHASH )
341+
342+ for i , c := range addr {
343+ if c .Code () == ma .P_WSS {
344+ na := make (ma.Multiaddr , 0 , len (addr )+ 1 )
345+ na = append (na , addr [:i ]... )
346+ na = append (na , tlsWSAddr ... )
347+ na = append (na , addr [i + 1 :]... )
348+ addr = na
349+ break // only do this once; there shouldn't be two /wss components anyway
350+ }
351+ }
352+
353+ for i , c := range addr {
354+ if c .Code () == ma .P_SNI {
355+ na := make (ma.Multiaddr , 0 , len (addr )- 1 )
356+ na = append (na , addr [:i ]... )
357+ na = append (na , addr [i + 1 :]... )
358+ addr = na
359+ break // only do this once; there shouldn't be two /sni components anyway
360+ }
361+ }
333362 return addr
334363}
335364
0 commit comments