mirror of
https://github.com/sigcn/pg.git
synced 2025-10-04 04:46:24 +08:00
p2p: skip nodes with node.nr label when selecting relay peer
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package disco
|
package disco
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
type PeerID string
|
type PeerID string
|
||||||
|
|
||||||
func (id PeerID) String() string {
|
func (id PeerID) String() string {
|
||||||
@@ -17,3 +19,21 @@ func (id PeerID) Len() byte {
|
|||||||
func (id PeerID) Bytes() []byte {
|
func (id PeerID) Bytes() []byte {
|
||||||
return []byte(id)
|
return []byte(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Labels []string
|
||||||
|
|
||||||
|
func (ls Labels) Get(key string) (string, bool) {
|
||||||
|
for _, l := range ls {
|
||||||
|
kv := strings.Split(l, "=")
|
||||||
|
if len(kv) == 2 {
|
||||||
|
if kv[0] == key {
|
||||||
|
return kv[1], true
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if kv[0] == key {
|
||||||
|
return "", true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
@@ -270,8 +270,12 @@ func (c *PacketConn) relayPeer(peerID disco.PeerID) disco.PeerID {
|
|||||||
if meta == nil {
|
if meta == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if _, ok := disco.Labels(meta["label"]).Get("node.nr"); ok {
|
||||||
|
// can not as relay peer when `node.nr` label is present
|
||||||
|
continue
|
||||||
|
}
|
||||||
peerNAT := disco.NATType(meta.Get("nat"))
|
peerNAT := disco.NATType(meta.Get("nat"))
|
||||||
if peerNAT == disco.Easy || peerNAT == disco.IP4 {
|
if peerNAT == disco.Easy || peerNAT == disco.IP4 || peerNAT == disco.IP46 {
|
||||||
return p.PeerID
|
return p.PeerID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user