Compare commits

...

2 Commits

3 changed files with 14 additions and 0 deletions

View File

@ -47,6 +47,7 @@ type Peer interface {
SetHandshakeDone(status bool)
GetIPString() string
GetIP() net.Addr
SetIP(ip net.Addr)
Abuser() bool
}
@ -93,6 +94,10 @@ func (b *BasePeer) GetIP() net.Addr {
panic("must implement in child class")
}
func (b *BasePeer) SetIP(ip net.Addr) {
panic("must implement in child class")
}
func (b *BasePeer) Challenge() []byte {
return b.challenge
}

View File

@ -19,6 +19,7 @@ type WebSocketPeer struct {
BasePeer
socket *websocket.Conn
abuser bool
ip net.Addr
}
func (p *WebSocketPeer) Connect(uri *url.URL) (interface{}, error) {
@ -139,6 +140,10 @@ func (p *WebSocketPeer) GetChallenge() []byte {
}
func (p *WebSocketPeer) GetIP() net.Addr {
if p.ip != nil {
return p.ip
}
ctx, cancel := context.WithCancel(context.Background())
netConn := websocket.NetConn(ctx, p.socket, websocket.MessageBinary)

View File

@ -125,6 +125,10 @@ func (h *HTTPServiceDefault) p2pHandler(ctx jape.Context) {
return
}
if ip != nil {
peer.SetIP(ip)
}
h.Services().P2P().ConnectionTracker().Add(1)
go func() {