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")
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if !verifyId {
|
nodeId := h.IncomingMessage().(*SignedMessage).NodeId()
|
||||||
peer.SetId(h)
|
|
||||||
} else {
|
if !verifyId {
|
||||||
if !peer.ID.Equals(pId) {
|
peer.SetId(nodeId)
|
||||||
return errInvalidChallenge
|
} else {
|
||||||
}
|
if !peer.Id().Equals(nodeId) {
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
err := node.Services().P2P().AddPeer(peer)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if supportedFeatures != 3 {
|
peer.SetConnectionURIs(h.connectionUris)
|
||||||
return errors.New("Remote node does not support required features")
|
|
||||||
}
|
|
||||||
|
|
||||||
node.Services.P2P.Peers[peer.ID.String()] = peer
|
peerId, err := peer.Id().ToString()
|
||||||
node.Services.P2P.ReconnectDelay[peer.ID.String()] = 1
|
|
||||||
|
|
||||||
connectionUrisCount := data.UnpackInt()
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
peer.ConnectionUris = make([]*url.URL, 0)
|
node.Logger().Info(fmt.Sprintf("[+] %s (%s)", peerId, peer.RenderLocationURI()))
|
||||||
for i := 0; i < connectionUrisCount; i++ {
|
|
||||||
uriStr := data.UnpackString()
|
|
||||||
uri, err := url.Parse(uriStr)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
peer.ConnectionUris = append(peer.ConnectionUris, uri)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log information - Assuming a logging method exists
|
err = node.Services().P2P().SendPublicPeersToPeer(peer, []net.Peer{peer})
|
||||||
node.Logger.Info(fmt.Sprintf("[+] %s (%s)", peer.ID.String(), peer.RenderLocationUri().String()))
|
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