diff --git a/node.go b/node/node.go similarity index 93% rename from node.go rename to node/node.go index 3d5b2fd..335acc9 100644 --- a/node.go +++ b/node/node.go @@ -1,6 +1,7 @@ -package libs5_go +package node import ( + "git.lumeweb.com/LumeWeb/libs5-go" "git.lumeweb.com/LumeWeb/libs5-go/encoding" "git.lumeweb.com/LumeWeb/libs5-go/service" "git.lumeweb.com/LumeWeb/libs5-go/structs" @@ -26,7 +27,7 @@ func (s *Services) P2P() *service.P2P { const cacheBucketName = "object-cache" type Node struct { - nodeConfig *NodeConfig + nodeConfig *libs5_go.NodeConfig metadataCache *structs.Map started bool hashQueryRoutingTable *structs.Map @@ -38,7 +39,7 @@ func (n *Node) Services() *Services { return &n.services } -func NewNode(config *NodeConfig) *Node { +func NewNode(config *libs5_go.NodeConfig) *Node { return &Node{ nodeConfig: config, metadataCache: structs.NewMap(), @@ -54,7 +55,7 @@ func (n *Node) IsStarted() bool { return n.started } -func (n *Node) Config() *NodeConfig { +func (n *Node) Config() *libs5_go.NodeConfig { return n.nodeConfig } @@ -151,8 +152,8 @@ func (n *Node) GetCachedStorageLocations(hash *encoding.Multihash, types []int) } return locations, nil } -func (n *Node) readStorageLocationsFromDB(hash *encoding.Multihash) (storageLocationMap, error) { - locationMap := newStorageLocationMap() +func (n *Node) readStorageLocationsFromDB(hash *encoding.Multihash) (libs5_go.storageLocationMap, error) { + locationMap := libs5_go.newStorageLocationMap() bytes := n.cacheBucket.Get(hash.FullBytes()) if bytes == nil { @@ -166,7 +167,7 @@ func (n *Node) readStorageLocationsFromDB(hash *encoding.Multihash) (storageLoca return locationMap, nil } -func (n *Node) AddStorageLocation(hash *encoding.Multihash, nodeId *encoding.NodeId, location *StorageLocation, message []byte, config *NodeConfig) error { +func (n *Node) AddStorageLocation(hash *encoding.Multihash, nodeId *encoding.NodeId, location *StorageLocation, message []byte, config *libs5_go.NodeConfig) error { // Read existing storage locations locationDb, err := n.readStorageLocationsFromDB(hash) if err != nil { @@ -181,8 +182,8 @@ func (n *Node) AddStorageLocation(hash *encoding.Multihash, nodeId *encoding.Nod // Get or create the inner map for the specific type innerMap, exists := locationDb[location.Type] if !exists { - innerMap = make(nodeStorage, 1) - innerMap[nodeIdStr] = make(nodeDetailsStorage, 1) + innerMap = make(libs5_go.nodeStorage, 1) + innerMap[nodeIdStr] = make(libs5_go.nodeDetailsStorage, 1) } // Create location map with new data diff --git a/storage.go b/node/storage.go similarity index 99% rename from storage.go rename to node/storage.go index 598d88f..1fe7452 100644 --- a/storage.go +++ b/node/storage.go @@ -1,4 +1,4 @@ -package libs5_go +package node import ( "fmt" diff --git a/protocol/handshake_open.go b/protocol/handshake_open.go index 44c58f0..9e6c2d5 100644 --- a/protocol/handshake_open.go +++ b/protocol/handshake_open.go @@ -2,8 +2,8 @@ package protocol import ( "errors" - "git.lumeweb.com/LumeWeb/libs5-go" "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 *libs5_go.Node, peer *net.Peer, verifyId bool) error { +func (m *HandshakeOpen) HandleMessage(node *node.Node, peer *net.Peer, verifyId bool) error { return nil } diff --git a/protocol/hash_query.go b/protocol/hash_query.go index c3aa80c..57d45e0 100644 --- a/protocol/hash_query.go +++ b/protocol/hash_query.go @@ -1,9 +1,9 @@ package protocol import ( - libs5_go "git.lumeweb.com/LumeWeb/libs5-go" "git.lumeweb.com/LumeWeb/libs5-go/encoding" "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" diff --git a/protocol/incoming_message.go b/protocol/incoming_message.go index b0b8bba..b1ebc26 100644 --- a/protocol/incoming_message.go +++ b/protocol/incoming_message.go @@ -2,8 +2,8 @@ package protocol import ( "fmt" - "git.lumeweb.com/LumeWeb/libs5-go" "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" "net/url" @@ -14,7 +14,7 @@ var ( ) type IncomingMessage interface { - HandleMessage(node *libs5_go.Node, peer *net.Peer, verifyId bool) error + HandleMessage(node *node.Node, peer *net.Peer, verifyId bool) error SetIncomingMessage(msg IncomingMessage) msgpack.CustomDecoder } @@ -54,7 +54,7 @@ func (i *IncomingMessageImpl) ToMessage() (message []byte, err error) { return msgpack.Marshal(i) } -func (i *IncomingMessageImpl) HandleMessage(node *libs5_go.Node, peer *net.Peer, verifyId bool) error { +func (i *IncomingMessageImpl) HandleMessage(node *node.Node, peer *net.Peer, verifyId bool) error { panic("child class should implement this method") } @@ -89,7 +89,7 @@ func NewIncomingMessageTyped(kind types.ProtocolMethod, data msgpack.RawMessage) return &IncomingMessageTypedImpl{*known} } -type IncomingMessageHandler func(node *libs5_go.Node, peer *net.Peer, u *url.URL, verifyId bool) error +type IncomingMessageHandler func(node *node.Node, peer *net.Peer, u *url.URL, verifyId bool) error func (i *IncomingMessageImpl) DecodeMsgpack(dec *msgpack.Decoder) error { if i.known { diff --git a/protocol/signed/accounce_peers.go b/protocol/signed/accounce_peers.go index 6830687..ad4b43d 100644 --- a/protocol/signed/accounce_peers.go +++ b/protocol/signed/accounce_peers.go @@ -1,9 +1,9 @@ package signed import ( - libs5_go "git.lumeweb.com/LumeWeb/libs5-go" "git.lumeweb.com/LumeWeb/libs5-go/encoding" "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" diff --git a/protocol/signed/handshake_done.go b/protocol/signed/handshake_done.go index da0f897..f2bc4a0 100644 --- a/protocol/signed/handshake_done.go +++ b/protocol/signed/handshake_done.go @@ -3,8 +3,8 @@ package signed import ( "bytes" "errors" - libs5_go "git.lumeweb.com/LumeWeb/libs5-go" "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" ) diff --git a/protocol/signed_message.go b/protocol/signed_message.go index 4140688..77c12eb 100644 --- a/protocol/signed_message.go +++ b/protocol/signed_message.go @@ -3,9 +3,9 @@ package protocol import ( "crypto/ed25519" "errors" - libs5_go "git.lumeweb.com/LumeWeb/libs5-go" "git.lumeweb.com/LumeWeb/libs5-go/encoding" "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" diff --git a/protocol/storage_location.go b/protocol/storage_location.go index 1c4bd87..07117de 100644 --- a/protocol/storage_location.go +++ b/protocol/storage_location.go @@ -3,9 +3,9 @@ package protocol import ( "crypto/ed25519" "fmt" - libs5_go "git.lumeweb.com/LumeWeb/libs5-go" "git.lumeweb.com/LumeWeb/libs5-go/encoding" "git.lumeweb.com/LumeWeb/libs5-go/net" + "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 +39,7 @@ func (s *StorageLocation) DecodeMessage(dec *msgpack.Decoder) error { return nil } -func (s *StorageLocation) HandleMessage(node *libs5_go.Node, peer *net.Peer, verifyId bool) error { +func (s *StorageLocation) HandleMessage(node *node.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 +73,7 @@ func (s *StorageLocation) HandleMessage(node *libs5_go.Node, peer *net.Peer, ver nodeId := encoding.NewNodeId(publicKey) // Assuming `node` is an instance of your Node structure - err := node.AddStorageLocation(hash, nodeId, libs5_go.NewStorageLocation(int(typeOfData), parts, int64(expiry)), s.raw, node.Config()) // Implement AddStorageLocation + err := node.AddStorageLocation(hash, nodeId, node.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) diff --git a/service/p2p.go b/service/p2p.go index d80c2b3..f683965 100644 --- a/service/p2p.go +++ b/service/p2p.go @@ -2,10 +2,10 @@ package service import ( "errors" - libs5_go "git.lumeweb.com/LumeWeb/libs5-go" "git.lumeweb.com/LumeWeb/libs5-go/ed25519" "git.lumeweb.com/LumeWeb/libs5-go/encoding" "git.lumeweb.com/LumeWeb/libs5-go/net" + "git.lumeweb.com/LumeWeb/libs5-go/node" "git.lumeweb.com/LumeWeb/libs5-go/protocol" "git.lumeweb.com/LumeWeb/libs5-go/structs" "git.lumeweb.com/LumeWeb/libs5-go/utils" @@ -30,11 +30,11 @@ const nodeBucketName = "nodes" type P2P struct { logger *zap.Logger - nodeKeyPair ed25519.KeyPairEd25519 + nodeKeyPair *ed25519.KeyPairEd25519 localNodeID *encoding.NodeId networkID string nodesBucket *bolt.Bucket - node *libs5_go.Node + node *node.Node inited bool reconnectDelay *structs.Map peers *structs.Map @@ -76,7 +76,7 @@ func (n *nodeVotes) DecodeMsgpack(dec *msgpack.Decoder) error { return nil } -func NewP2P(node *libs5_go.Node) *P2P { +func NewP2P(node *node.Node) *P2P { service := &P2P{ logger: node.Logger(), nodeKeyPair: node.Config().KeyPair, @@ -90,7 +90,7 @@ func NewP2P(node *libs5_go.Node) *P2P { return service } -func (p *P2P) Node() *libs5_go.Node { +func (p *P2P) Node() *node.Node { return p.node } diff --git a/service/service.go b/service/service.go index f746929..d1146f4 100644 --- a/service/service.go +++ b/service/service.go @@ -1,9 +1,11 @@ package service -import libs5_go "git.lumeweb.com/LumeWeb/libs5-go" +import ( + "git.lumeweb.com/LumeWeb/libs5-go/node" +) type Service interface { - Node() *libs5_go.Node + Node() *node.Node Start() error Stop() error Init() error