|
|
|
@ -3,16 +3,18 @@ package security |
|
|
|
|
import ( |
|
|
|
|
"fmt" |
|
|
|
|
"sync" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/internal/utils" |
|
|
|
|
"github.com/harmony-one/harmony/internal/utils/blockedpeers" |
|
|
|
|
libp2p_network "github.com/libp2p/go-libp2p/core/network" |
|
|
|
|
libp2pnetwork "github.com/libp2p/go-libp2p/core/network" |
|
|
|
|
ma "github.com/multiformats/go-multiaddr" |
|
|
|
|
"github.com/pkg/errors" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type Security interface { |
|
|
|
|
OnConnectCheck(net libp2p_network.Network, conn libp2p_network.Conn) error |
|
|
|
|
OnDisconnectCheck(conn libp2p_network.Conn) error |
|
|
|
|
OnConnectCheck(net libp2pnetwork.Network, conn libp2pnetwork.Conn) error |
|
|
|
|
OnDisconnectCheck(conn libp2pnetwork.Conn) error |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type peerMap struct { |
|
|
|
@ -85,7 +87,7 @@ func (m *Manager) RangePeers(f func(key string, value []string) bool) { |
|
|
|
|
m.peers.Range(f) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *Manager) OnConnectCheck(net libp2p_network.Network, conn libp2p_network.Conn) error { |
|
|
|
|
func (m *Manager) OnConnectCheck(net libp2pnetwork.Network, conn libp2pnetwork.Conn) error { |
|
|
|
|
m.mutex.Lock() |
|
|
|
|
defer m.mutex.Unlock() |
|
|
|
|
|
|
|
|
@ -131,7 +133,7 @@ func (m *Manager) OnConnectCheck(net libp2p_network.Network, conn libp2p_network |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *Manager) OnDisconnectCheck(conn libp2p_network.Conn) error { |
|
|
|
|
func (m *Manager) OnDisconnectCheck(conn libp2pnetwork.Conn) error { |
|
|
|
|
m.mutex.Lock() |
|
|
|
|
defer m.mutex.Unlock() |
|
|
|
|
|
|
|
|
@ -169,7 +171,7 @@ func find(slice []string, val string) (int, bool) { |
|
|
|
|
return -1, false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getRemoteIP(conn libp2p_network.Conn) (string, error) { |
|
|
|
|
func getRemoteIP(conn libp2pnetwork.Conn) (string, error) { |
|
|
|
|
for _, protocol := range conn.RemoteMultiaddr().Protocols() { |
|
|
|
|
switch protocol.Code { |
|
|
|
|
case ma.P_IP4: |
|
|
|
|