mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-22 02:47:48 +08:00
25 lines
741 B
Go
25 lines
741 B
Go
package libp2p
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/libp2p/go-libp2p"
|
|
"github.com/libp2p/go-libp2p/core/host"
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
|
"github.com/libp2p/go-libp2p/core/peerstore"
|
|
)
|
|
|
|
type HostOption func(id peer.ID, ps peerstore.Peerstore, options ...libp2p.Option) (host.Host, error)
|
|
|
|
var DefaultHostOption HostOption = constructPeerHost
|
|
|
|
// isolates the complex initialization steps
|
|
func constructPeerHost(id peer.ID, ps peerstore.Peerstore, options ...libp2p.Option) (host.Host, error) {
|
|
pkey := ps.PrivKey(id)
|
|
if pkey == nil {
|
|
return nil, fmt.Errorf("missing private key for node ID: %s", id)
|
|
}
|
|
options = append([]libp2p.Option{libp2p.Identity(pkey), libp2p.Peerstore(ps)}, options...)
|
|
return libp2p.New(options...)
|
|
}
|