mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-20 11:46:44 +00:00
Netstore with a mock peerPool. Initial structure.
This commit is contained in:
parent
398deb7766
commit
9d7a3e2f8a
1 changed files with 34 additions and 4 deletions
|
|
@ -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.
|
It does forwarding for incoming requests and handles expiry/timeout.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
type peerPool interface {
|
import (
|
||||||
GetPeers(target Key, peers []peer)
|
"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
|
// it implements the ChunkStore interface
|
||||||
|
|
@ -15,8 +36,17 @@ type netStore struct {
|
||||||
// cademlia
|
// 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue