@@ -2,7 +2,7 @@ package basichost
2
2
3
3
import (
4
4
"context"
5
- "fmt "
5
+ "errors "
6
6
"net"
7
7
"slices"
8
8
"sort"
@@ -32,15 +32,14 @@ type thinWaist struct {
32
32
Addr , TW , Rest ma.Multiaddr
33
33
}
34
34
35
+ var errTW = errors .New ("not a thinwaist address" )
36
+
35
37
func thinWaistForm (a ma.Multiaddr ) (thinWaist , error ) {
36
38
if len (a ) < 2 {
37
- return thinWaist {}, fmt . Errorf ( "not a thinwaist address: %s" , a )
39
+ return thinWaist {}, errTW
38
40
}
39
- // we don't care about link local ipv6 addresses here
40
- hasIP := a [0 ].Code () == ma .P_IP4 || a [0 ].Code () == ma .P_IP6
41
- hasProtocol := a [1 ].Code () == ma .P_TCP || a [1 ].Code () == ma .P_UDP
42
- if ! hasIP || ! hasProtocol {
43
- return thinWaist {}, fmt .Errorf ("not a thinwaist address: %s" , a )
41
+ if c0 , c1 := a [0 ].Code (), a [1 ].Code (); (c0 != ma .P_IP4 && c0 != ma .P_IP6 ) || (c1 != ma .P_TCP && c1 != ma .P_UDP ) {
42
+ return thinWaist {}, errTW
44
43
}
45
44
return thinWaist {Addr : a , TW : a [:2 ], Rest : a [2 :]}, nil
46
45
}
@@ -503,14 +502,14 @@ func (o *ObservedAddrsManager) Close() error {
503
502
return nil
504
503
}
505
504
506
- // hasConsistentTransport returns true if the address `a ` shares the same
507
- // protocols with `b `
508
- func hasConsistentTransport (a , b ma.Multiaddr ) bool {
509
- if len (a ) != len (b ) {
505
+ // hasConsistentTransport returns true if the thin waist address `aTW ` shares the same
506
+ // protocols with `bTW `
507
+ func hasConsistentTransport (aTW , bTW ma.Multiaddr ) bool {
508
+ if len (aTW ) != len (bTW ) {
510
509
return false
511
510
}
512
- for i , ac := range a {
513
- if b [i ].Code () != ac .Code () {
511
+ for i , a := range aTW {
512
+ if bTW [i ].Code () != a .Code () {
514
513
return false
515
514
}
516
515
}
0 commit comments