connection gater for libp2p host
This commit is contained in:
parent
6742a74260
commit
4b1d1b6540
@ -25,6 +25,7 @@ import (
|
||||
"github.com/libp2p/go-libp2p-peerstore/pstoremem"
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
record "github.com/libp2p/go-libp2p-record"
|
||||
"github.com/libp2p/go-libp2p/p2p/net/conngater"
|
||||
"github.com/multiformats/go-multiaddr"
|
||||
"go.uber.org/fx"
|
||||
"golang.org/x/xerrors"
|
||||
@ -98,6 +99,7 @@ var (
|
||||
ConnectionManagerKey = special{9} // Libp2p option
|
||||
AutoNATSvcKey = special{10} // Libp2p option
|
||||
BandwidthReporterKey = special{11} // Libp2p option
|
||||
ConnGaterKey = special{12} // libp2p option
|
||||
)
|
||||
|
||||
type invoke int
|
||||
@ -220,6 +222,9 @@ func libp2p() Option {
|
||||
|
||||
Override(PstoreAddSelfKeysKey, lp2p.PstoreAddSelfKeys),
|
||||
Override(StartListeningKey, lp2p.StartListening(config.DefaultFullNode().Libp2p.ListenAddresses)),
|
||||
|
||||
Override(new(*conngater.BasicConnectionGater), lp2p.ConnGater),
|
||||
Override(ConnGaterKey, lp2p.ConnGaterOption),
|
||||
)
|
||||
}
|
||||
|
||||
|
17
node/modules/lp2p/conngater.go
Normal file
17
node/modules/lp2p/conngater.go
Normal file
@ -0,0 +1,17 @@
|
||||
package lp2p
|
||||
|
||||
import (
|
||||
"github.com/libp2p/go-libp2p"
|
||||
"github.com/libp2p/go-libp2p/p2p/net/conngater"
|
||||
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
)
|
||||
|
||||
func ConnGater(ds dtypes.MetadataDS) (*conngater.BasicConnectionGater, error) {
|
||||
return conngater.NewBasicConnectionGater(ds)
|
||||
}
|
||||
|
||||
func ConnGaterOption(cg *conngater.BasicConnectionGater) (opts Libp2pOpts, err error) {
|
||||
opts.Opts = append(opts.Opts, libp2p.ConnectionGater(cg))
|
||||
return
|
||||
}
|
Loading…
Reference in New Issue
Block a user