Netstore with a mock peerPool. Initial structure.

This commit is contained in:
Daniel A. Nagy 2015-02-05 14:57:37 +01:00
parent 398deb7766
commit 9d7a3e2f8a

View file

@ -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
}