Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update libp2p version #463

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.20.x]
go-version: [1.21.x]
platform: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: "1.20"
go-version: "1.21"
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
pre-commit:
strategy:
matrix:
go-version: [ 1.20.x ]
go-version: [ 1.21.x ]
platform: [ ubuntu-latest ]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/regression_basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
strategy:
matrix:
python-version: ["3.7"]
go-version: [1.20.x]
go-version: [1.21.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand All @@ -31,6 +31,7 @@ jobs:
git clone https://github.com/xuperchain/xuperchain.git
cd xuperchain
echo "replace github.com/xuperchain/xupercore => ../xupercore" >> go.mod
go mod tidy
make && make testnet && cd testnet/
sed -i' ' 's#level: debug#level: warn#g' node*/conf/log.yaml
sh control_all.sh start
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/regression_consensus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
strategy:
matrix:
python-version: ["3.7"]
go-version: [1.20.x]
go-version: [1.21.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand All @@ -31,6 +31,7 @@ jobs:
git clone https://github.com/xuperchain/xuperchain.git
cd xuperchain
echo "replace github.com/xuperchain/xupercore => ../xupercore" >> go.mod
go mod tidy
make && make testnet && cd testnet/
sed -i' ' 's#level: debug#level: warn#g' node*/conf/log.yaml
sh control_all.sh start
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/regression_parachain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
strategy:
matrix:
python-version: ["3.7"]
go-version: [1.20.x]
go-version: [1.21.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand All @@ -31,6 +31,7 @@ jobs:
git clone https://github.com/xuperchain/xuperchain.git
cd xuperchain
echo "replace github.com/xuperchain/xupercore => ../xupercore" >> go.mod
go mod tidy
make && make testnet && cd testnet/
sed -i' ' 's#level: debug#level: warn#g' node*/conf/log.yaml
sh control_all.sh start
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ logs/
# Go test binaries
*.test

kernel/mock/data/tmp/
kernel/mock/p2pv2/node1/data/blockchain/

# idea
.idea

Expand Down
2 changes: 1 addition & 1 deletion bcs/network/p2pv2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
pb "github.com/xuperchain/xupercore/protos"

"github.com/golang/protobuf/proto"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/core/peer"
prom "github.com/prometheus/client_golang/prometheus"
)

Expand Down
2 changes: 1 addition & 1 deletion bcs/network/p2pv2/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package p2pv2
import (
"math/rand"

"github.com/libp2p/go-libp2p-core/peer"
kbucket "github.com/libp2p/go-libp2p-kbucket"
"github.com/libp2p/go-libp2p/core/peer"
)

// PeerFilter the interface for filter peers
Expand Down
34 changes: 14 additions & 20 deletions bcs/network/p2pv2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ import (
"time"

"github.com/golang/protobuf/proto"
ipfsAddr "github.com/ipfs/go-ipfs-addr"
"github.com/libp2p/go-libp2p"
circuit "github.com/libp2p/go-libp2p-circuit"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/protocol"
"github.com/libp2p/go-libp2p-core/routing"
dht "github.com/libp2p/go-libp2p-kad-dht"
record "github.com/libp2p/go-libp2p-record"
secIO "github.com/libp2p/go-libp2p-secio"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol"
"github.com/libp2p/go-libp2p/core/routing"
noise "github.com/libp2p/go-libp2p/p2p/security/noise"
tls "github.com/libp2p/go-libp2p/p2p/security/tls"
"github.com/multiformats/go-multiaddr"
"github.com/patrickmn/go-cache"
prom "github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -118,7 +117,7 @@ func (p *P2PServerV2) Init(ctx *netCtx.NetCtx) error {
return ErrGenerateOpts
}

ho, err := libp2p.New(ctx, opts...)
ho, err := libp2p.New(opts...)
if err != nil {
p.log.Error("Create p2p host error", "error", err)
if strings.Contains(err.Error(), "bind: cannot assign requested address") {
Expand Down Expand Up @@ -191,7 +190,8 @@ func genHostOption(ctx *netCtx.NetCtx) ([]libp2p.Option, error) {

opts := []libp2p.Option{
libp2p.ListenAddrs(muAddr),
libp2p.EnableRelay(circuit.OptHop),
// libp2p.EnableRelay(circuit.OptHop),
libp2p.EnableRelay(),
}

if cfg.IsNat {
Expand All @@ -204,14 +204,14 @@ func genHostOption(ctx *netCtx.NetCtx) ([]libp2p.Option, error) {
return nil, err
}
opts = append(opts, libp2p.Identity(priv))
opts = append(opts, libp2p.Security(ID, NewTLS(cfg.KeyPath, cfg.ServiceName)))
opts = append(opts, libp2p.Security(tls.ID, tls.New))
} else {
priv, err := p2p.GetKeyPairFromPath(cfg.KeyPath)
if err != nil {
return nil, err
}
opts = append(opts, libp2p.Identity(priv))
opts = append(opts, libp2p.Security(secIO.ID, secIO.New))
opts = append(opts, libp2p.Security(noise.ID, noise.New))
}

return opts, nil
Expand Down Expand Up @@ -428,15 +428,9 @@ func (p *P2PServerV2) connectPeerByAddress(addresses []string) int {
func (p *P2PServerV2) getAddrInfos(addresses []string) []peer.AddrInfo {
addrInfos := make([]peer.AddrInfo, 0, len(addresses))
for _, addr := range addresses {
peerAddr, err := ipfsAddr.ParseString(addr)
addrInfo, err := peer.AddrInfoFromString(addr)
if err != nil {
p.log.Error("p2p: parse peer address error", "peerAddr", peerAddr, "error", err)
continue
}

addrInfo, err := peer.AddrInfoFromP2pAddr(peerAddr.Multiaddr())
if err != nil {
p.log.Error("p2p: get peer node info error", "peerAddr", peerAddr, "error", err)
p.log.Error("p2p: get peer node info error", "peerAddr", addr, "error", err)
continue
}

Expand Down
4 changes: 2 additions & 2 deletions bcs/network/p2pv2/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
pb "github.com/xuperchain/xupercore/protos"

ggio "github.com/gogo/protobuf/io"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
ma "github.com/multiformats/go-multiaddr"
)

Expand Down
2 changes: 1 addition & 1 deletion bcs/network/p2pv2/stream_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strings"
"sync"

"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/core/peer"

nctx "github.com/xuperchain/xupercore/kernel/network/context"
"github.com/xuperchain/xupercore/lib/logs"
Expand Down
8 changes: 4 additions & 4 deletions bcs/network/p2pv2/stream_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"errors"
"sync"

"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/protocol"
swarm "github.com/libp2p/go-libp2p-swarm"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol"
swarm "github.com/libp2p/go-libp2p/p2p/net/swarm"

xctx "github.com/xuperchain/xupercore/kernel/common/xcontext"
nctx "github.com/xuperchain/xupercore/kernel/network/context"
Expand Down
24 changes: 17 additions & 7 deletions bcs/network/p2pv2/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import (
"os"
"path/filepath"

"github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/sec"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol"
"github.com/libp2p/go-libp2p/core/sec"
)

// ID is the protocol ID (used when negotiating with multistream)
Expand Down Expand Up @@ -64,8 +66,12 @@ func NewTLS(path, serviceName string) func(key crypto.PrivKey) (*Transport, erro
}
}

func (t *Transport) ID() protocol.ID {
return ID
}

// SecureInbound runs the TLS handshake as a server.
func (t *Transport) SecureInbound(ctx context.Context, insecure net.Conn) (sec.SecureConn, error) {
func (t *Transport) SecureInbound(ctx context.Context, insecure net.Conn, p peer.ID) (sec.SecureConn, error) {
conn := tls.Server(insecure, t.config.Clone())
if err := conn.Handshake(); err != nil {
insecure.Close()
Expand Down Expand Up @@ -115,7 +121,6 @@ func (t *Transport) setupConn(tlsConn *tls.Conn, remotePubKey crypto.PubKey) (se
if err != nil {
return nil, err
}

return &conn{
Conn: tlsConn,
localPeer: t.localPeer,
Expand All @@ -132,8 +137,9 @@ type conn struct {
localPeer peer.ID
privKey crypto.PrivKey

remotePeer peer.ID
remotePubKey crypto.PubKey
remotePeer peer.ID
remotePubKey crypto.PubKey
connectionState network.ConnectionState
}

var _ sec.SecureConn = &conn{}
Expand All @@ -153,3 +159,7 @@ func (c *conn) RemotePeer() peer.ID {
func (c *conn) RemotePublicKey() crypto.PubKey {
return c.remotePubKey
}

func (c *conn) ConnState() network.ConnectionState {
return c.connectionState
}
2 changes: 1 addition & 1 deletion bcs/network/p2pv2/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package p2pv2
import (
"fmt"

"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/core/peer"
)

type blankValidator struct{}
Expand Down
Loading
Loading