forked from libp2p/go-libp2p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.go
27 lines (24 loc) · 1 KB
/
filter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package holepunch
import (
ma "github.com/multiformats/go-multiaddr"
"github.com/seqsy/go-libp2p/core/peer"
)
// WithAddrFilter is a Service option that enables multiaddress filtering.
// It allows to only send a subset of observed addresses to the remote
// peer. E.g., only announce TCP or QUIC multi addresses instead of both.
// It also allows to only consider a subset of received multi addresses
// that remote peers announced to us.
// Theoretically, this API also allows to add multi addresses in both cases.
func WithAddrFilter(f AddrFilter) Option {
return func(hps *Service) error {
hps.filter = f
return nil
}
}
// AddrFilter defines the interface for the multi address filtering.
type AddrFilter interface {
// FilterLocal filters the multi addresses that are sent to the remote peer.
FilterLocal(remoteID peer.ID, maddrs []ma.Multiaddr) []ma.Multiaddr
// FilterRemote filters the multi addresses received from the remote peer.
FilterRemote(remoteID peer.ID, maddrs []ma.Multiaddr) []ma.Multiaddr
}