package autonatimport (mamanet)type dialPolicy struct { allowSelfDials bool host host.Host}// skipDial indicates that a multiaddress isn't worth attempted dialing.// The same logic is used when the autonat client is considering if// a remote peer is worth using as a server, and when the server is// considering if a requested client is worth dialing back.func ( *dialPolicy) ( ma.Multiaddr) bool {// skip relay addresses , := .ValueForProtocol(ma.P_CIRCUIT)if == nil {returntrue }if .allowSelfDials {returnfalse }// skip private network (unroutable) addressesif !manet.IsPublicAddr() {returntrue } , := manet.ToIP()if != nil {returntrue }// Skip dialing addresses we believe are the local node'sfor , := range .host.Addrs() { , := manet.ToIP()if != nil {continue }if .Equal() {returntrue } }returnfalse}// skipPeer indicates that the collection of multiaddresses representing a peer// isn't worth attempted dialing. If one of the addresses matches an address// we believe is ours, we exclude the peer, even if there are other valid// public addresses in the list.func ( *dialPolicy) ( []ma.Multiaddr) bool { := .host.Addrs() := make([]net.IP, 0)for , := range {if , := .ValueForProtocol(ma.P_CIRCUIT); != nil && manet.IsPublicAddr() { , := manet.ToIP()if != nil {continue } = append(, ) } }// if a public IP of the peer is one of ours: skip the peer. := falsefor , := range {if , := .ValueForProtocol(ma.P_CIRCUIT); != nil && manet.IsPublicAddr() { , := manet.ToIP()if != nil {continue }for , := range {if .Equal() {returntrue } } = true } }if .allowSelfDials {returnfalse }return !}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.