Skip to content

Commit

Permalink
feat:handshake for meerevm p2p
Browse files Browse the repository at this point in the history
  • Loading branch information
lochjin committed Dec 2, 2024
1 parent f4fd228 commit 9365826
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
7 changes: 4 additions & 3 deletions p2p/synch/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (ps *PeerSync) immediatelyConnected(pe *peers.Peer) {
}

func (ps *PeerSync) Connection(pe *peers.Peer) {
ps.connectMeerEVM(pe)
if pe.ConnectionState().IsConnected() {
return
}
Expand Down Expand Up @@ -276,7 +277,7 @@ func (s *Sync) IsInboundPeerAtLimit() bool {
return len(s.Peers().DirInbound()) >= s.p2p.Config().MaxInbound
}

func (s *Sync) ConnectionGater(pid *peer.ID,addr ma.Multiaddr, dir network.Direction) bool {
func (s *Sync) ConnectionGater(pid *peer.ID, addr ma.Multiaddr, dir network.Direction) bool {

var pe *peers.Peer
if pid != nil {
Expand All @@ -285,8 +286,8 @@ func (s *Sync) ConnectionGater(pid *peer.ID,addr ma.Multiaddr, dir network.Direc
return true
}
pe = s.peers.Get(*pid)
}else if addr != nil {
pe =s.peers.GetByAddress(addr)
} else if addr != nil {
pe = s.peers.GetByAddress(addr)
}

if pe != nil {
Expand Down
36 changes: 36 additions & 0 deletions p2p/synch/meerevm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package synch

import (
"github.com/Qitmeer/qng/p2p/common"
"github.com/Qitmeer/qng/p2p/peers"
"github.com/ethereum/go-ethereum/p2p/enode"
)

func (ps *PeerSync) connectMeerEVM(pe *peers.Peer) {
ms := pe.GetMeerState()
if ms == nil {
return
}
meers := common.NewMeerState(ms)
meerP2P := ps.sy.p2p.BlockChain().MeerChain().Server()
if meerP2P.PeerCount() > 0 {
for _, p := range meerP2P.Peers() {
if p.ID() == meers.Id {
return
}
}
}
if len(meers.Enode) > 0 {
node, err := enode.Parse(enode.ValidSchemes, meers.Enode)
if err != nil {
log.Error("invalid enode: %v", err)
}
meerP2P.AddTrustedPeer(node)
} else if len(meers.ENR) > 0 {
node, err := enode.Parse(enode.ValidSchemes, meers.ENR)
if err != nil {
log.Error("invalid enr: %v", err)
}
meerP2P.AddTrustedPeer(node)
}
}

0 comments on commit 9365826

Please sign in to comment.