feat: implement HandshakeDone HandleMessage
This commit is contained in:
parent
deee8b0e0f
commit
8a47faecac
|
@ -3,6 +3,7 @@ package signed
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"git.lumeweb.com/LumeWeb/libs5-go/interfaces"
|
"git.lumeweb.com/LumeWeb/libs5-go/interfaces"
|
||||||
"git.lumeweb.com/LumeWeb/libs5-go/net"
|
"git.lumeweb.com/LumeWeb/libs5-go/net"
|
||||||
"git.lumeweb.com/LumeWeb/libs5-go/protocol/base"
|
"git.lumeweb.com/LumeWeb/libs5-go/protocol/base"
|
||||||
|
@ -81,45 +82,42 @@ func (h HandshakeDone) HandleMessage(node interfaces.Node, peer net.Peer, verify
|
||||||
if !bytes.Equal(peer.Challenge(), h.challenge) {
|
if !bytes.Equal(peer.Challenge(), h.challenge) {
|
||||||
return errors.New("Invalid challenge")
|
return errors.New("Invalid challenge")
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
|
nodeId := h.IncomingMessage().(*SignedMessage).NodeId()
|
||||||
|
|
||||||
if !verifyId {
|
if !verifyId {
|
||||||
peer.SetId(h)
|
peer.SetId(nodeId)
|
||||||
} else {
|
} else {
|
||||||
if !peer.ID.Equals(pId) {
|
if !peer.Id().Equals(nodeId) {
|
||||||
return errInvalidChallenge
|
return fmt.Errorf("Invalid transports id on initial list")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
peer.isConnected = true
|
peer.SetConnected(true)
|
||||||
|
|
||||||
supportedFeatures := data.UnpackInt()
|
if h.supportedFeatures != types.SupportedFeatures {
|
||||||
|
return fmt.Errorf("Remote node does not support required features")
|
||||||
if supportedFeatures != 3 {
|
|
||||||
return errors.New("Remote node does not support required features")
|
|
||||||
}
|
}
|
||||||
|
err := node.Services().P2P().AddPeer(peer)
|
||||||
node.Services.P2P.Peers[peer.ID.String()] = peer
|
|
||||||
node.Services.P2P.ReconnectDelay[peer.ID.String()] = 1
|
|
||||||
|
|
||||||
connectionUrisCount := data.UnpackInt()
|
|
||||||
|
|
||||||
peer.ConnectionUris = make([]*url.URL, 0)
|
|
||||||
for i := 0; i < connectionUrisCount; i++ {
|
|
||||||
uriStr := data.UnpackString()
|
|
||||||
uri, err := url.Parse(uriStr)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
peer.ConnectionUris = append(peer.ConnectionUris, uri)
|
|
||||||
|
peer.SetConnectionURIs(h.connectionUris)
|
||||||
|
|
||||||
|
peerId, err := peer.Id().ToString()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log information - Assuming a logging method exists
|
node.Logger().Info(fmt.Sprintf("[+] %s (%s)", peerId, peer.RenderLocationURI()))
|
||||||
node.Logger.Info(fmt.Sprintf("[+] %s (%s)", peer.ID.String(), peer.RenderLocationUri().String()))
|
|
||||||
|
err = node.Services().P2P().SendPublicPeersToPeer(peer, []net.Peer{peer})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Send peer lists and emit 'peerConnected' event
|
|
||||||
// Assuming appropriate methods exist in node.Services.P2P
|
|
||||||
node.Services.P2P.SendPublicPeersToPeer(peer)
|
|
||||||
*/
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue