Skip to content

Commit

Permalink
support yamux
Browse files Browse the repository at this point in the history
  • Loading branch information
Ji Qiren committed Aug 22, 2023
1 parent 28501e1 commit c8956c9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ linters:
- unconvert
- gofmt
- asciicheck
- depguard
- dogsled
- gocritic
- goimports
Expand Down Expand Up @@ -60,3 +59,4 @@ linters:
- goconst
- gocyclo
- structcheck
- depguard
2 changes: 1 addition & 1 deletion common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type P2PConfig struct {
BlackPID []string
BlackIP []string
AdminPort string
Secio bool
DisableMplex bool
}

// RPCConfig is the config for RPC Server.
Expand Down
12 changes: 9 additions & 3 deletions p2p/net_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
libnet "github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/p2p/muxer/mplex"
"github.com/libp2p/go-libp2p/p2p/muxer/yamux"
"github.com/libp2p/go-libp2p/p2p/security/noise"
tls "github.com/libp2p/go-libp2p/p2p/security/tls"

Expand Down Expand Up @@ -138,20 +139,25 @@ func (ns *NetService) startHost(pk crypto.PrivKey, listenAddr string) (host.Host
libp2p.Security(tls.ID, tls.New),
libp2p.Security(noise.ID, noise.New),
}
muxOptions := []libp2p.Option{
libp2p.Muxer(yamux.ID, yamux.DefaultTransport),
}
if !ns.config.DisableMplex {
muxOptions = append(muxOptions, libp2p.Muxer(protocolID, mplex.DefaultTransport))
}
opts := []libp2p.Option{
libp2p.Identity(pk),
libp2p.NATPortMap(),
libp2p.ListenAddrStrings(fmt.Sprintf("/ip4/%s/tcp/%d", tcpAddr.IP, tcpAddr.Port)),
libp2p.ChainOptions(
libp2p.Muxer(protocolID, mplex.DefaultTransport),
),
libp2p.ChainOptions(muxOptions...),
libp2p.ChainOptions(secOptions...),
}
h, err := libp2p.New(opts...)
if err != nil {
return nil, err
}
h.SetStreamHandler(protocolID, ns.streamHandler)
h.SetStreamHandler(yamux.ID, ns.streamHandler)
return h, nil
}

Expand Down

0 comments on commit c8956c9

Please sign in to comment.