diff --git a/Commands.go b/Commands.go index 7da7848..93fa618 100644 --- a/Commands.go +++ b/Commands.go @@ -36,6 +36,8 @@ func (peer *PeerInfo) cmdAnouncement(msg *MessageAnnouncement) { // FIND_SELF: Requesting peers close to the sender? if msg.Actions&(1< 0 { + Filters.IncomingRequest(peer, ActionFindSelf, peer.NodeID, nil) + selfD := Hash2Peer{ID: KeyHash{peer.NodeID}} // do not respond the caller's own peer (add to ignore list) @@ -55,6 +57,8 @@ func (peer *PeerInfo) cmdAnouncement(msg *MessageAnnouncement) { // FIND_PEER: Find a different peer? if msg.Actions&(1< 0 && len(msg.FindPeerKeys) > 0 { for _, findPeer := range msg.FindPeerKeys { + Filters.IncomingRequest(peer, ActionFindPeer, findPeer.Hash, nil) + details := Hash2Peer{ID: findPeer} // Same as before, put self as ignoredNodes. @@ -75,6 +79,8 @@ func (peer *PeerInfo) cmdAnouncement(msg *MessageAnnouncement) { // Find a value? if msg.Actions&(1< 0 { for _, findHash := range msg.FindDataKeys { + Filters.IncomingRequest(peer, ActionFindValue, findHash.Hash, nil) + stored, data := announcementGetData(findHash.Hash) if stored && len(data) > 0 { filesEmbed = append(filesEmbed, EmbeddedFileData{ID: findHash, Data: data}) @@ -89,6 +95,10 @@ func (peer *PeerInfo) cmdAnouncement(msg *MessageAnnouncement) { // Information about files stored by the sender? if msg.Actions&(1< 0 && len(msg.InfoStoreFiles) > 0 { + for n := range msg.InfoStoreFiles { + Filters.IncomingRequest(peer, ActionInfoStore, msg.InfoStoreFiles[n].ID.Hash, &msg.InfoStoreFiles[n]) + } + peer.announcementStore(msg.InfoStoreFiles) } diff --git a/Filter.go b/Filter.go index dd49d84..a87551b 100644 --- a/Filter.go +++ b/Filter.go @@ -30,6 +30,9 @@ var Filters struct { // DHTSearchStatus is called with updates of searches in the DHT. It allows to see the live progress of searches. DHTSearchStatus func(client *dht.SearchClient, function, format string, v ...interface{}) + + // IncomingRequest receives all incoming information requests. The action field is set accordingly. + IncomingRequest func(peer *PeerInfo, Action int, Key []byte, Info interface{}) } func initFilters() { @@ -45,10 +48,12 @@ func initFilters() { if Filters.DHTSearchStatus == nil { Filters.DHTSearchStatus = func(client *dht.SearchClient, function, format string, v ...interface{}) {} } - if Filters.LogError == nil { Filters.LogError = DefaultLogError } + if Filters.IncomingRequest == nil { + Filters.IncomingRequest = func(peer *PeerInfo, Action int, Key []byte, Info interface{}) {} + } } // DefaultLogError is the default error logging function diff --git a/README.md b/README.md index 865f32a..e289d02 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ The core library which is needed for any Peernet application. It provides connectivity to the network and all basic functions. For details about Peernet see https://peernet.org/. For the current technical roadmap and upcoming releases see the [Talk forum](https://talk.peernet.org/discussion/10/technical-roadmap). -Current version: Alpha 2 +Current version: Alpha 3 Current development status: Initial connectivity works. DHT functionality is in development.