From f34163e3a3b4b973741717cef30ae1a784cc68a7 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sat, 4 Nov 2017 12:06:13 -0700 Subject: [PATCH 1/6] first hack at a nice libp2p constructor --- libp2p.go | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 libp2p.go diff --git a/libp2p.go b/libp2p.go new file mode 100644 index 0000000000..7905461805 --- /dev/null +++ b/libp2p.go @@ -0,0 +1,90 @@ +package libp2p + +import ( + "context" + "crypto/rand" + + crypto "github.com/libp2p/go-libp2p-crypto" + host "github.com/libp2p/go-libp2p-host" + pnet "github.com/libp2p/go-libp2p-interface-pnet" + metrics "github.com/libp2p/go-libp2p-metrics" + peer "github.com/libp2p/go-libp2p-peer" + pstore "github.com/libp2p/go-libp2p-peerstore" + swarm "github.com/libp2p/go-libp2p-swarm" + transport "github.com/libp2p/go-libp2p-transport" + bhost "github.com/libp2p/go-libp2p/p2p/host/basic" + mux "github.com/libp2p/go-stream-muxer" + ma "github.com/multiformats/go-multiaddr" + mplex "github.com/whyrusleeping/go-smux-multiplex" + msmux "github.com/whyrusleeping/go-smux-multistream" + yamux "github.com/whyrusleeping/go-smux-yamux" +) + +type Config struct { + Transports []transport.Transport + Muxer mux.Transport + ListenAddrs []ma.Multiaddr + PeerKey crypto.PrivKey + Peerstore pstore.Peerstore + Protector pnet.Protector + Reporter metrics.Reporter +} + +func Construct(ctx context.Context, cfg *Config) (host.Host, error) { + if cfg == nil { + cfg = DefaultConfig() + } + + if cfg.PeerKey == nil { + priv, _, err := crypto.GenerateKeyPairWithReader(crypto.RSA, 2048, rand.Reader) + if err != nil { + return nil, err + } + cfg.PeerKey = priv + } + + // Obtain Peer ID from public key + pid, err := peer.IDFromPublicKey(cfg.PeerKey.GetPublic()) + if err != nil { + return nil, err + } + + ps := cfg.Peerstore + if ps == nil { + ps = pstore.NewPeerstore() + } + + ps.AddPrivKey(pid, cfg.PeerKey) + ps.AddPubKey(pid, cfg.PeerKey.GetPublic()) + + swrm, err := swarm.NewSwarmWithProtector(ctx, cfg.ListenAddrs, pid, ps, cfg.Protector, cfg.Muxer, cfg.Reporter) + if err != nil { + return nil, err + } + + netw := (*swarm.Network)(swrm) + + return bhost.New(netw), nil +} + +func DefaultMuxer() mux.Transport { + // Set up stream multiplexer + tpt := msmux.NewBlankTransport() + tpt.AddTransport("/yamux/1.0.0", yamux.DefaultTransport) + tpt.AddTransport("/mplex/6.3.0", mplex.DefaultTransport) + return tpt +} + +func DefaultConfig() *Config { + // Create a multiaddress + addr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/0") + if err != nil { + panic(err) + } + + return &Config{ + ListenAddrs: []ma.Multiaddr{addr}, + Peerstore: pstore.NewPeerstore(), + Muxer: DefaultMuxer(), + } +} From c937b88e457405876aabe1f538d8ef5151373c7b Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sun, 5 Nov 2017 07:28:59 -0800 Subject: [PATCH 2/6] review feedback --- libp2p.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libp2p.go b/libp2p.go index 7905461805..831a9c8ac2 100644 --- a/libp2p.go +++ b/libp2p.go @@ -20,6 +20,7 @@ import ( yamux "github.com/whyrusleeping/go-smux-yamux" ) +// Config describes a set of settings for a libp2p node type Config struct { Transports []transport.Transport Muxer mux.Transport @@ -30,11 +31,18 @@ type Config struct { Reporter metrics.Reporter } -func Construct(ctx context.Context, cfg *Config) (host.Host, error) { +func New(ctx context.Context) (host.Host, error) { + return NewWithCfg(ctx, DefaultConfig()) +} + +// Construct instantiates a libp2p host using information from the given +// config. `nil` may be passed to use default options. +func NewWithCfg(ctx context.Context, cfg *Config) (host.Host, error) { if cfg == nil { cfg = DefaultConfig() } + // If no key was given, generate a random 2048 bit RSA key if cfg.PeerKey == nil { priv, _, err := crypto.GenerateKeyPairWithReader(crypto.RSA, 2048, rand.Reader) if err != nil { @@ -49,6 +57,7 @@ func Construct(ctx context.Context, cfg *Config) (host.Host, error) { return nil, err } + // Create a new blank peerstore if none was passed in ps := cfg.Peerstore if ps == nil { ps = pstore.NewPeerstore() @@ -70,14 +79,17 @@ func Construct(ctx context.Context, cfg *Config) (host.Host, error) { func DefaultMuxer() mux.Transport { // Set up stream multiplexer tpt := msmux.NewBlankTransport() + + // By default, support yamux and multiplex tpt.AddTransport("/yamux/1.0.0", yamux.DefaultTransport) tpt.AddTransport("/mplex/6.3.0", mplex.DefaultTransport) + return tpt } func DefaultConfig() *Config { - // Create a multiaddress - addr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/0") + // Create a multiaddress that listens on a random port on all interfaces + addr, err := ma.NewMultiaddr("/ip4/0.0.0.0/tcp/0") if err != nil { panic(err) } From d04268054f706547e6d11a7283782a54e17f9799 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Thu, 14 Dec 2017 13:10:09 -0800 Subject: [PATCH 3/6] use new constructor for examples --- examples/echo/main.go | 22 ++++--------------- examples/libp2p-host/host.go | 41 ++++++++++++++++++------------------ libp2p.go | 22 +++++++++++-------- 3 files changed, 38 insertions(+), 47 deletions(-) diff --git a/examples/echo/main.go b/examples/echo/main.go index cc37453da3..d0e704f932 100644 --- a/examples/echo/main.go +++ b/examples/echo/main.go @@ -12,6 +12,7 @@ import ( mrand "math/rand" golog "github.com/ipfs/go-log" + libp2p "github.com/libp2p/go-libp2p" crypto "github.com/libp2p/go-libp2p-crypto" host "github.com/libp2p/go-libp2p-host" net "github.com/libp2p/go-libp2p-net" @@ -69,28 +70,13 @@ func makeBasicHost(listenPort int, secio bool, randseed int64) (host.Host, error ps.AddPubKey(pid, pub) } - // Set up stream multiplexer - tpt := msmux.NewBlankTransport() - tpt.AddTransport("/yamux/1.0.0", yamux.DefaultTransport) - - // Create swarm (implements libP2P Network) - swrm, err := swarm.NewSwarmWithProtector( - context.Background(), - []ma.Multiaddr{addr}, - pid, - ps, - nil, - tpt, - nil, - ) + basicHost, err := libp2p.NewWithCfg(ctx, &libp2p.Config{ + ListenAddrs: []ma.Multiaddr{addr}, + }) if err != nil { return nil, err } - netw := (*swarm.Network)(swrm) - - basicHost := bhost.New(netw) - // Build host multiaddress hostAddr, _ := ma.NewMultiaddr(fmt.Sprintf("/ipfs/%s", basicHost.ID().Pretty())) diff --git a/examples/libp2p-host/host.go b/examples/libp2p-host/host.go index 9c028206ec..b0b53d8bbf 100644 --- a/examples/libp2p-host/host.go +++ b/examples/libp2p-host/host.go @@ -5,47 +5,48 @@ import ( "crypto/rand" "fmt" + libp2p "github.com/libp2p/go-libp2p" crypto "github.com/libp2p/go-libp2p-crypto" - peer "github.com/libp2p/go-libp2p-peer" - pstore "github.com/libp2p/go-libp2p-peerstore" - swarm "github.com/libp2p/go-libp2p-swarm" - bhost "github.com/libp2p/go-libp2p/p2p/host/basic" ma "github.com/multiformats/go-multiaddr" ) func main() { - // Generate an identity keypair using go's cryptographic randomness source - priv, pub, err := crypto.GenerateEd25519Key(rand.Reader) + // The context governs the lifetime of the libp2p node + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + // To construct a simple host with all the default settings, just use `New` + h, err := libp2p.New(ctx) if err != nil { panic(err) } - // A peers ID is the hash of its public key - pid, err := peer.IDFromPublicKey(pub) + fmt.Printf("Hello World, my hosts ID is %s\n", h.ID()) + + // If you want more control over the configuration, you can fill out fields + // in the libp2p config, and use `NewWithCfg` + cfg := new(libp2p.Config) + + // Set your own keypair + priv, _, err := crypto.GenerateEd25519Key(rand.Reader) if err != nil { panic(err) } + cfg.PeerKey = priv - // We've created the identity, now we need to store it. - // A peerstore holds information about peers, including your own - ps := pstore.NewPeerstore() - ps.AddPrivKey(pid, priv) - ps.AddPubKey(pid, pub) - + // Set your own listen address maddr, err := ma.NewMultiaddr("/ip4/0.0.0.0/tcp/9000") if err != nil { panic(err) } - // Make a context to govern the lifespan of the swarm - ctx := context.Background() + // The config takes an array of addresses, specify as many as you want. + cfg.ListenAddrs = []ma.Multiaddr{maddr} - // Put all this together - netw, err := swarm.NewNetwork(ctx, []ma.Multiaddr{maddr}, pid, ps, nil) + h2, err := libp2p.NewWithCfg(ctx, cfg) if err != nil { panic(err) } - myhost := bhost.New(netw) - fmt.Printf("Hello World, my hosts ID is %s\n", myhost.ID()) + fmt.Printf("Hello World, my second hosts ID is %s\n", h2.ID()) } diff --git a/libp2p.go b/libp2p.go index 831a9c8ac2..da508732f3 100644 --- a/libp2p.go +++ b/libp2p.go @@ -22,13 +22,14 @@ import ( // Config describes a set of settings for a libp2p node type Config struct { - Transports []transport.Transport - Muxer mux.Transport - ListenAddrs []ma.Multiaddr - PeerKey crypto.PrivKey - Peerstore pstore.Peerstore - Protector pnet.Protector - Reporter metrics.Reporter + Transports []transport.Transport + Muxer mux.Transport + ListenAddrs []ma.Multiaddr + PeerKey crypto.PrivKey + Peerstore pstore.Peerstore + Protector pnet.Protector + Reporter metrics.Reporter + DisableSecio bool } func New(ctx context.Context) (host.Host, error) { @@ -63,8 +64,11 @@ func NewWithCfg(ctx context.Context, cfg *Config) (host.Host, error) { ps = pstore.NewPeerstore() } - ps.AddPrivKey(pid, cfg.PeerKey) - ps.AddPubKey(pid, cfg.PeerKey.GetPublic()) + // If secio is disabled, don't add our private key to the peerstore + if !cfg.DisableSecio { + ps.AddPrivKey(pid, cfg.PeerKey) + ps.AddPubKey(pid, cfg.PeerKey.GetPublic()) + } swrm, err := swarm.NewSwarmWithProtector(ctx, cfg.ListenAddrs, pid, ps, cfg.Protector, cfg.Muxer, cfg.Reporter) if err != nil { From 8d84ecd01bc0d58dab41108c00b9418819ca61c8 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Thu, 14 Dec 2017 15:40:24 -0800 Subject: [PATCH 4/6] functional parameters --- examples/echo/main.go | 35 ++++----------- examples/libp2p-host/host.go | 23 ++++------ libp2p.go | 85 +++++++++++++++++++++++++++++++++--- 3 files changed, 97 insertions(+), 46 deletions(-) diff --git a/examples/echo/main.go b/examples/echo/main.go index d0e704f932..9da76b50c4 100644 --- a/examples/echo/main.go +++ b/examples/echo/main.go @@ -18,12 +18,8 @@ import ( net "github.com/libp2p/go-libp2p-net" peer "github.com/libp2p/go-libp2p-peer" pstore "github.com/libp2p/go-libp2p-peerstore" - swarm "github.com/libp2p/go-libp2p-swarm" - bhost "github.com/libp2p/go-libp2p/p2p/host/basic" ma "github.com/multiformats/go-multiaddr" gologging "github.com/whyrusleeping/go-logging" - msmux "github.com/whyrusleeping/go-smux-multistream" - yamux "github.com/whyrusleeping/go-smux-yamux" ) // makeBasicHost creates a LibP2P host with a random peer ID listening on the @@ -42,37 +38,21 @@ func makeBasicHost(listenPort int, secio bool, randseed int64) (host.Host, error // Generate a key pair for this host. We will use it at least // to obtain a valid host ID. - priv, pub, err := crypto.GenerateKeyPairWithReader(crypto.RSA, 2048, r) + priv, _, err := crypto.GenerateKeyPairWithReader(crypto.RSA, 2048, r) if err != nil { return nil, err } - // Obtain Peer ID from public key - pid, err := peer.IDFromPublicKey(pub) - if err != nil { - return nil, err - } - - // Create a multiaddress - addr, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", listenPort)) - - if err != nil { - return nil, err + opts := []libp2p.Option{ + libp2p.ListenAddrStrings(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", listenPort)), + libp2p.WithPeerKey(priv), } - // Create a peerstore - ps := pstore.NewPeerstore() - - // If using secio, we add the keys to the peerstore - // for this peer ID. - if secio { - ps.AddPrivKey(pid, priv) - ps.AddPubKey(pid, pub) + if !secio { + opts = append(opts, libp2p.NoSecio) } - basicHost, err := libp2p.NewWithCfg(ctx, &libp2p.Config{ - ListenAddrs: []ma.Multiaddr{addr}, - }) + basicHost, err := libp2p.New(context.Background(), opts...) if err != nil { return nil, err } @@ -82,6 +62,7 @@ func makeBasicHost(listenPort int, secio bool, randseed int64) (host.Host, error // Now we can build a full multiaddress to reach this host // by encapsulating both addresses: + addr := basicHost.Addrs()[0] fullAddr := addr.Encapsulate(hostAddr) log.Printf("I am %s\n", fullAddr) if secio { diff --git a/examples/libp2p-host/host.go b/examples/libp2p-host/host.go index b0b53d8bbf..f24784d143 100644 --- a/examples/libp2p-host/host.go +++ b/examples/libp2p-host/host.go @@ -7,7 +7,6 @@ import ( libp2p "github.com/libp2p/go-libp2p" crypto "github.com/libp2p/go-libp2p-crypto" - ma "github.com/multiformats/go-multiaddr" ) func main() { @@ -23,27 +22,23 @@ func main() { fmt.Printf("Hello World, my hosts ID is %s\n", h.ID()) - // If you want more control over the configuration, you can fill out fields - // in the libp2p config, and use `NewWithCfg` - cfg := new(libp2p.Config) + // If you want more control over the configuration, you can specify some + // options to the constructor // Set your own keypair priv, _, err := crypto.GenerateEd25519Key(rand.Reader) if err != nil { panic(err) } - cfg.PeerKey = priv - // Set your own listen address - maddr, err := ma.NewMultiaddr("/ip4/0.0.0.0/tcp/9000") - if err != nil { - panic(err) - } - - // The config takes an array of addresses, specify as many as you want. - cfg.ListenAddrs = []ma.Multiaddr{maddr} + h2, err := libp2p.New(ctx, + // Use your own created keypair + libp2p.WithPeerKey(priv), - h2, err := libp2p.NewWithCfg(ctx, cfg) + // Set your own listen address + // The config takes an array of addresses, specify as many as you want. + libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/9000"), + ) if err != nil { panic(err) } diff --git a/libp2p.go b/libp2p.go index da508732f3..b2c4d6cc28 100644 --- a/libp2p.go +++ b/libp2p.go @@ -32,13 +32,88 @@ type Config struct { DisableSecio bool } -func New(ctx context.Context) (host.Host, error) { - return NewWithCfg(ctx, DefaultConfig()) +type Option func(cfg *Config) error + +func Transports(tpts []transport.Transport) Option { + return func(cfg *Config) error { + cfg.Transports = tpts + return nil + } +} + +func ListenAddrStrings(s ...string) Option { + return func(cfg *Config) error { + for _, addrstr := range s { + a, err := ma.NewMultiaddr(addrstr) + if err != nil { + return err + } + cfg.ListenAddrs = append(cfg.ListenAddrs, a) + } + return nil + } +} + +func ListenAddrs(addrs []ma.Multiaddr) Option { + return func(cfg *Config) error { + cfg.ListenAddrs = append(cfg.ListenAddrs, addrs...) + return nil + } +} + +func NoSecio(cfg *Config) error { + cfg.DisableSecio = true + return nil +} + +func WithMuxer(m mux.Transport) Option { + return func(cfg *Config) error { + cfg.Muxer = m + return nil + } +} + +func WithPeerstore(ps pstore.Peerstore) Option { + return func(cfg *Config) error { + cfg.Peerstore = ps + return nil + } +} + +func WithNetProtector(prot pnet.Protector) Option { + return func(cfg *Config) error { + cfg.Protector = prot + return nil + } +} + +func WithBandwidthReporter(rep metrics.Reporter) Option { + return func(cfg *Config) error { + cfg.Reporter = rep + return nil + } +} + +func New(ctx context.Context, opts ...Option) (host.Host, error) { + cfg := DefaultConfig() + + for _, opt := range opts { + if err := opt(cfg); err != nil { + return nil, err + } + } + + return newWithCfg(ctx, cfg) +} + +func WithPeerKey(sk crypto.PrivKey) Option { + return func(cfg *Config) error { + cfg.PeerKey = sk + return nil + } } -// Construct instantiates a libp2p host using information from the given -// config. `nil` may be passed to use default options. -func NewWithCfg(ctx context.Context, cfg *Config) (host.Host, error) { +func newWithCfg(ctx context.Context, cfg *Config) (host.Host, error) { if cfg == nil { cfg = DefaultConfig() } From bbbc040b60e15e9e2b7dc8686085b5d0eb85af69 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Fri, 15 Dec 2017 16:02:30 -0800 Subject: [PATCH 5/6] incorporate lgierths opinions --- examples/echo/main.go | 4 +- examples/libp2p-host/host.go | 2 +- libp2p.go | 104 ++++++++++++++++++++++++----------- 3 files changed, 75 insertions(+), 35 deletions(-) diff --git a/examples/echo/main.go b/examples/echo/main.go index 9da76b50c4..412df18fc1 100644 --- a/examples/echo/main.go +++ b/examples/echo/main.go @@ -45,11 +45,11 @@ func makeBasicHost(listenPort int, secio bool, randseed int64) (host.Host, error opts := []libp2p.Option{ libp2p.ListenAddrStrings(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", listenPort)), - libp2p.WithPeerKey(priv), + libp2p.Identity(priv), } if !secio { - opts = append(opts, libp2p.NoSecio) + opts = append(opts, libp2p.NoEncryption()) } basicHost, err := libp2p.New(context.Background(), opts...) diff --git a/examples/libp2p-host/host.go b/examples/libp2p-host/host.go index f24784d143..793cdf4fd8 100644 --- a/examples/libp2p-host/host.go +++ b/examples/libp2p-host/host.go @@ -33,7 +33,7 @@ func main() { h2, err := libp2p.New(ctx, // Use your own created keypair - libp2p.WithPeerKey(priv), + libp2p.Identity(priv), // Set your own listen address // The config takes an array of addresses, specify as many as you want. diff --git a/libp2p.go b/libp2p.go index b2c4d6cc28..837f9fddf0 100644 --- a/libp2p.go +++ b/libp2p.go @@ -3,6 +3,7 @@ package libp2p import ( "context" "crypto/rand" + "fmt" crypto "github.com/libp2p/go-libp2p-crypto" host "github.com/libp2p/go-libp2p-host" @@ -34,9 +35,9 @@ type Config struct { type Option func(cfg *Config) error -func Transports(tpts []transport.Transport) Option { +func Transports(tpts ...transport.Transport) Option { return func(cfg *Config) error { - cfg.Transports = tpts + cfg.Transports = append(cfg.Transports, tpts...) return nil } } @@ -54,70 +55,110 @@ func ListenAddrStrings(s ...string) Option { } } -func ListenAddrs(addrs []ma.Multiaddr) Option { +func ListenAddrs(addrs ...ma.Multiaddr) Option { return func(cfg *Config) error { cfg.ListenAddrs = append(cfg.ListenAddrs, addrs...) return nil } } -func NoSecio(cfg *Config) error { - cfg.DisableSecio = true - return nil +type transportEncOpt int + +const ( + EncPlaintext = transportEncOpt(0) + EncSecio = transportEncOpt(1) +) + +func TransportEncryption(tenc ...transportEncOpt) Option { + return func(cfg *Config) error { + if len(tenc) != 1 { + return fmt.Errorf("can only specify a single transport encryption option right now") + } + + // TODO: actually make this pluggable, otherwise tls will get tricky + switch tenc[0] { + case EncPlaintext: + cfg.DisableSecio = true + case EncSecio: + // noop + default: + return fmt.Errorf("unrecognized transport encryption option: %d", tenc[0]) + } + return nil + } } -func WithMuxer(m mux.Transport) Option { +func NoEncryption() Option { + return TransportEncryption(EncPlaintext) +} + +func Muxer(m mux.Transport) Option { return func(cfg *Config) error { + if cfg.Muxer != nil { + return fmt.Errorf("cannot specify multiple muxer options") + } + cfg.Muxer = m return nil } } -func WithPeerstore(ps pstore.Peerstore) Option { +func Peerstore(ps pstore.Peerstore) Option { return func(cfg *Config) error { + if cfg.Peerstore != nil { + return fmt.Errorf("cannot specify multiple peerstore options") + } + cfg.Peerstore = ps return nil } } -func WithNetProtector(prot pnet.Protector) Option { +func PrivateNetwork(prot pnet.Protector) Option { return func(cfg *Config) error { + if cfg.Protector != nil { + return fmt.Errorf("cannot specify multiple private network options") + } + cfg.Protector = prot return nil } } -func WithBandwidthReporter(rep metrics.Reporter) Option { +func BandwidthReporter(rep metrics.Reporter) Option { return func(cfg *Config) error { + if cfg.Reporter != nil { + return fmt.Errorf("cannot specify multiple bandwidth reporter options") + } + cfg.Reporter = rep return nil } } -func New(ctx context.Context, opts ...Option) (host.Host, error) { - cfg := DefaultConfig() - - for _, opt := range opts { - if err := opt(cfg); err != nil { - return nil, err +func Identity(sk crypto.PrivKey) Option { + return func(cfg *Config) error { + if cfg.PeerKey != nil { + return fmt.Errorf("cannot specify multiple identities") } - } - - return newWithCfg(ctx, cfg) -} -func WithPeerKey(sk crypto.PrivKey) Option { - return func(cfg *Config) error { cfg.PeerKey = sk return nil } } -func newWithCfg(ctx context.Context, cfg *Config) (host.Host, error) { - if cfg == nil { - cfg = DefaultConfig() +func New(ctx context.Context, opts ...Option) (host.Host, error) { + var cfg Config + for _, opt := range opts { + if err := opt(&cfg); err != nil { + return nil, err + } } + return newWithCfg(ctx, &cfg) +} + +func newWithCfg(ctx context.Context, cfg *Config) (host.Host, error) { // If no key was given, generate a random 2048 bit RSA key if cfg.PeerKey == nil { priv, _, err := crypto.GenerateKeyPairWithReader(crypto.RSA, 2048, rand.Reader) @@ -166,16 +207,15 @@ func DefaultMuxer() mux.Transport { return tpt } -func DefaultConfig() *Config { +func Defaults(cfg *Config) error { // Create a multiaddress that listens on a random port on all interfaces addr, err := ma.NewMultiaddr("/ip4/0.0.0.0/tcp/0") if err != nil { - panic(err) + return err } - return &Config{ - ListenAddrs: []ma.Multiaddr{addr}, - Peerstore: pstore.NewPeerstore(), - Muxer: DefaultMuxer(), - } + cfg.ListenAddrs = []ma.Multiaddr{addr} + cfg.Peerstore = pstore.NewPeerstore() + cfg.Muxer = DefaultMuxer() + return nil } From 5824305949550820fda8528b731a7c48ad47cf94 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sat, 6 Jan 2018 16:19:49 -0800 Subject: [PATCH 6/6] import go-smux-multiplex --- package.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/package.json b/package.json index 3f49be09af..26a4346730 100644 --- a/package.json +++ b/package.json @@ -280,6 +280,12 @@ "hash": "QmSAJm4QdTJ3EGF2cvgNcQyXTEbxqWSW1x4kCVV1aJQUQr", "name": "go-libp2p-interface-connmgr", "version": "0.0.4" + }, + { + "author": "whyrusleeping", + "hash": "QmREBy6TSjLQMtYFhjf97cypsUTzBagcwamWocKHFCTb1e", + "name": "go-smux-multiplex", + "version": "3.0.4" } ], "gxVersion": "0.4.0",