From 9d7a3e2f8abc9014aca441a8a4fda4ace22718c0 Mon Sep 17 00:00:00 2001 From: "Daniel A. Nagy" Date: Thu, 5 Feb 2015 14:57:37 +0100 Subject: [PATCH] Netstore with a mock peerPool. Initial structure. --- bzz/netstore.go | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/bzz/netstore.go b/bzz/netstore.go index be59443d7e..9dec6e673f 100644 --- a/bzz/netstore.go +++ b/bzz/netstore.go @@ -5,8 +5,29 @@ DHT implements the chunk store that directly communicates with the bzz protocol It does forwarding for incoming requests and handles expiry/timeout. */ -type peerPool interface { - GetPeers(target Key, peers []peer) +import ( + "math/rand" + "time" +) + +// This is a mock implementation with a fixed peer pool with no distinction between peers +type peerPool struct { + pool map[string]peer +} + +func (self *peerPool) addPeer(p peer) { + self.pool[p.peer.identity.Pubkey()] = p +} + +func (self *peerPool) removePeer(p peer) { + delete(self.pool, p.peer.identity.Pubkey) +} + +func (self *peerPool) GetPeers(target Key) (peers []peer) { + for key, value := range self.pool { + peers = append(peers, value) + } + return } // it implements the ChunkStore interface @@ -15,8 +36,17 @@ type netStore struct { // cademlia } -func (self *DPA) Put(chunk *Chunk) { - +func (self *netStore) Put(chunk *Chunk) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + req := storeRequestMsgData{ + Key: chunk.Key, + Data: chunk.Data, + Id: r.Int63(), + Size: chunk.Size, + } + for _, peer := range self.peerPool.GetPeers(chunk.Key) { + go peer.store(req) + } return }