Commit e4ffe287 authored by Janoš Guljaš's avatar Janoš Guljaš Committed by GitHub

add dedicated peerstore for every libp2p host (#18)

parent b5312204
......@@ -11,6 +11,7 @@ require (
github.com/libp2p/go-libp2p v0.5.1
github.com/libp2p/go-libp2p-autonat-svc v0.1.0
github.com/libp2p/go-libp2p-core v0.3.0
github.com/libp2p/go-libp2p-peerstore v0.1.4
github.com/libp2p/go-libp2p-quic-transport v0.2.2
github.com/libp2p/go-libp2p-secio v0.2.1
github.com/libp2p/go-libp2p-tls v0.1.3
......
......@@ -11,8 +11,6 @@ import (
"fmt"
"net"
"github.com/libp2p/go-libp2p-core/helpers"
"github.com/ethersphere/bee/pkg/addressbook"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p"
......@@ -22,10 +20,13 @@ import (
"github.com/libp2p/go-libp2p"
autonat "github.com/libp2p/go-libp2p-autonat-svc"
crypto "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/helpers"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"
libp2ppeer "github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/peerstore"
protocol "github.com/libp2p/go-libp2p-core/protocol"
"github.com/libp2p/go-libp2p-peerstore/pstoremem"
libp2pquic "github.com/libp2p/go-libp2p-quic-transport"
secio "github.com/libp2p/go-libp2p-secio"
libp2ptls "github.com/libp2p/go-libp2p-tls"
......@@ -37,6 +38,7 @@ var _ p2p.Service = (*Service)(nil)
type Service struct {
host host.Host
libp2pPeerstore peerstore.Peerstore
metrics metrics
networkID int32
handshakeService *handshake.Service
......@@ -100,6 +102,8 @@ func New(ctx context.Context, o Options) (*Service, error) {
}
}
libp2pPeerstore := pstoremem.NewPeerstore()
opts := []libp2p.Option{
// Multiple listen addresses
libp2p.ListenAddrStrings(listenAddrs...),
......@@ -111,6 +115,8 @@ func New(ctx context.Context, o Options) (*Service, error) {
libp2p.DefaultTransports,
// Attempt to open ports using uPNP for NATed hosts.
libp2p.NATPortMap(),
// Use dedicated peerstore instead the global DefaultPeerstore
libp2p.Peerstore(libp2pPeerstore),
}
if o.PrivateKey != nil {
......@@ -148,6 +154,7 @@ func New(ctx context.Context, o Options) (*Service, error) {
peerRegistry := newPeerRegistry()
s := &Service{
host: h,
libp2pPeerstore: libp2pPeerstore,
metrics: newMetrics(),
networkID: o.NetworkID,
handshakeService: handshake.New(peerRegistry, o.Overlay, o.NetworkID, o.Logger),
......@@ -344,5 +351,8 @@ func (s *Service) newStreamForPeerID(ctx context.Context, peerID libp2ppeer.ID,
}
func (s *Service) Close() error {
if err := s.libp2pPeerstore.Close(); err != nil {
return err
}
return s.host.Close()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment