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 }