refactor: use interfaces
This commit is contained in:
parent
4678d406fc
commit
51d76a2d95
|
@ -2,8 +2,8 @@ package protocol
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/interfaces"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/net"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/node"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
)
|
||||
|
@ -55,7 +55,7 @@ func (m HandshakeOpen) EncodeMsgpack(enc *msgpack.Encoder) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *HandshakeOpen) HandleMessage(node *node.NodeImpl, peer *net.Peer, verifyId bool) error {
|
||||
func (m *HandshakeOpen) HandleMessage(node interfaces.Node, peer *net.Peer, verifyId bool) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ package protocol
|
|||
|
||||
import (
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/interfaces"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/net"
|
||||
libs5_go "git.lumeweb.com/LumeWeb/libs5-go/node"
|
||||
"github.com/emirpasic/gods/sets/hashset"
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
"go.uber.org/zap"
|
||||
|
@ -47,7 +47,7 @@ func (h *HashQuery) DecodeMessage(dec *msgpack.Decoder) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
func (h *HashQuery) HandleMessage(node *libs5_go.NodeImpl, peer *net.Peer, verifyId bool) error {
|
||||
func (h *HashQuery) HandleMessage(node interfaces.Node, peer *net.Peer, verifyId bool) error {
|
||||
mapLocations, err := node.GetCachedStorageLocations(h.hash, h.kinds)
|
||||
if err != nil {
|
||||
log.Printf("Error getting cached storage locations: %v", err)
|
||||
|
@ -71,14 +71,14 @@ func (h *HashQuery) HandleMessage(node *libs5_go.NodeImpl, peer *net.Peer, verif
|
|||
return err
|
||||
}
|
||||
|
||||
sortedNodeId, err := score[0].ToString()
|
||||
sortedNodeId, err := (*score[0]).ToString()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
entry, exists := mapLocations[sortedNodeId]
|
||||
if exists {
|
||||
err := (*peer).SendMessage(entry.ProviderMessage)
|
||||
err := (*peer).SendMessage(entry.ProviderMessage())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ var (
|
|||
)
|
||||
|
||||
type IncomingMessage interface {
|
||||
HandleMessage(node *interfaces.Node, peer *net.Peer, verifyId bool) error
|
||||
HandleMessage(node interfaces.Node, peer *net.Peer, verifyId bool) error
|
||||
SetIncomingMessage(msg IncomingMessage)
|
||||
msgpack.CustomDecoder
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ func (i *IncomingMessageImpl) ToMessage() (message []byte, err error) {
|
|||
return msgpack.Marshal(i)
|
||||
}
|
||||
|
||||
func (i *IncomingMessageImpl) HandleMessage(node *interfaces.Node, peer *net.Peer, verifyId bool) error {
|
||||
func (i *IncomingMessageImpl) HandleMessage(node interfaces.Node, peer *net.Peer, verifyId bool) error {
|
||||
panic("child class should implement this method")
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ package signed
|
|||
|
||||
import (
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/interfaces"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/net"
|
||||
libs5_go "git.lumeweb.com/LumeWeb/libs5-go/node"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/protocol"
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
"net/url"
|
||||
|
@ -60,7 +60,7 @@ func (a *AnnouncePeers) DecodeMessage(dec *msgpack.Decoder) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (a AnnouncePeers) HandleMessage(node *libs5_go.NodeImpl, peer *net.Peer, verifyId bool) error {
|
||||
func (a AnnouncePeers) HandleMessage(node interfaces.Node, peer *net.Peer, verifyId bool) error {
|
||||
if len(a.connectionUris) > 0 {
|
||||
firstUrl := a.connectionUris[0]
|
||||
uri := new(url.URL)
|
||||
|
|
|
@ -3,8 +3,8 @@ package signed
|
|||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/interfaces"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/net"
|
||||
libs5_go "git.lumeweb.com/LumeWeb/libs5-go/node"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/protocol"
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
)
|
||||
|
@ -20,8 +20,8 @@ func NewHandshakeDone() *HandshakeDone {
|
|||
return &HandshakeDone{HandshakeOpen: *protocol.NewHandshakeOpen(nil, ""), supportedFeatures: -1}
|
||||
}
|
||||
|
||||
func (h HandshakeDone) HandleMessage(node *libs5_go.NodeImpl, peer *net.Peer, verifyId bool) error {
|
||||
if !(*node).IsStarted() {
|
||||
func (h HandshakeDone) HandleMessage(node interfaces.Node, peer *net.Peer, verifyId bool) error {
|
||||
if !node.IsStarted() {
|
||||
err := (*peer).End()
|
||||
if err != nil {
|
||||
return nil
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"crypto/ed25519"
|
||||
"errors"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/interfaces"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/net"
|
||||
libs5_go "git.lumeweb.com/LumeWeb/libs5-go/node"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/protocol/signed"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
|
@ -54,7 +54,7 @@ func NewSignedMessage() *SignedMessage {
|
|||
return &SignedMessage{}
|
||||
}
|
||||
|
||||
func (s *SignedMessage) HandleMessage(node *libs5_go.NodeImpl, peer *net.Peer, verifyId bool) error {
|
||||
func (s *SignedMessage) HandleMessage(node interfaces.Node, peer *net.Peer, verifyId bool) error {
|
||||
var payload signedMessagePayoad
|
||||
|
||||
err := msgpack.Unmarshal(s.message, &payload)
|
||||
|
|
|
@ -4,8 +4,9 @@ import (
|
|||
"crypto/ed25519"
|
||||
"fmt"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/interfaces"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/net"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/node"
|
||||
nodep "git.lumeweb.com/LumeWeb/libs5-go/node"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/utils"
|
||||
"github.com/emirpasic/gods/sets/hashset"
|
||||
|
@ -39,7 +40,7 @@ func (s *StorageLocation) DecodeMessage(dec *msgpack.Decoder) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
func (s *StorageLocation) HandleMessage(node *node.NodeImpl, peer *net.Peer, verifyId bool) error {
|
||||
func (s *StorageLocation) HandleMessage(node interfaces.Node, peer *net.Peer, verifyId bool) error {
|
||||
hash := encoding.NewMultihash(s.raw[1:34]) // Replace NewMultihash with appropriate function
|
||||
fmt.Println("Hash:", hash)
|
||||
|
||||
|
@ -73,7 +74,7 @@ func (s *StorageLocation) HandleMessage(node *node.NodeImpl, peer *net.Peer, ver
|
|||
nodeId := encoding.NewNodeId(publicKey)
|
||||
|
||||
// Assuming `node` is an instance of your NodeImpl structure
|
||||
err := node.AddStorageLocation(hash, nodeId, node.NewStorageLocation(int(typeOfData), parts, int64(expiry)), s.raw, node.Config()) // Implement AddStorageLocation
|
||||
err := node.AddStorageLocation(hash, nodeId, nodep.NewStorageLocation(int(typeOfData), parts, int64(expiry)), s.raw, node.Config()) // Implement AddStorageLocation
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to add storage location: %s", err)
|
||||
|
|
Loading…
Reference in New Issue