New debug command 'debug watch incoming'

This commit is contained in:
Kleissner
2021-07-29 04:14:49 +02:00
parent 837e4a6d29
commit d9573cdb15
5 changed files with 40 additions and 4 deletions

View File

@@ -53,6 +53,8 @@ func debugCmdConnect(nodeID []byte) {
//fmt.Printf("* Sending ping:\n")
}
// ---- filter for outgoing DHT searches ----
// debug output of monitored keys searched in the DHT
var monitorKeys map[string]struct{}
@@ -100,3 +102,27 @@ func filterSearchStatus(client *dht.SearchClient, function, format string, v ...
fmt.Printf(intend+" "+function+" ["+hex.EncodeToString(keyA)+"] "+format, v...)
}
// ---- filter for incoming information requests ----
var enableWatchIncomingAll = false
func filterIncomingRequest(peer *core.PeerInfo, Action int, Key []byte, Info interface{}) {
if !enableWatchIncomingAll {
return
}
requestType := "UNKNOWN"
switch Action {
case core.ActionFindSelf:
requestType = "FIND_SELF"
case core.ActionFindPeer:
requestType = "FIND_PEER"
case core.ActionFindValue:
requestType = "FIND_VALUE"
case core.ActionInfoStore:
requestType = "INFO_STORE"
}
fmt.Printf("Incoming info request %s from %s for key %s\n", requestType, hex.EncodeToString(peer.NodeID), hex.EncodeToString(Key))
}

View File

@@ -92,7 +92,8 @@ func showHelp() {
"debug key create Create Public-Private Key pair\n" +
"debug key self List current Public-Private Key pair\n" +
"debug connect Attempts to connect to the target peer\n" +
"debug watch searches Watches all outgoing DHT searches\n" +
"debug watch searches Watch all outgoing DHT searches\n" +
"debug watch incoming Watch all incoming information requests\n" +
"hash Create blake3 hash of input\n" +
"warehouse get Get data from local warehouse by hash\n" +
"warehouse store Store data into local warehouse\n" +
@@ -349,6 +350,14 @@ func userCommands() {
enableMonitorAll = number == 1
}
case "debug watch incoming":
fmt.Printf("Enable (1) or disable (0) watching of all incoming information requests? (current setting: %t)\n", enableWatchIncomingAll)
if number, valid := getUserOptionInt(reader); !valid || number < 0 || number > 1 {
fmt.Printf("Invalid option.\n")
} else {
enableWatchIncomingAll = number == 1
}
case "debug bucket refresh":
fmt.Printf("Disable (1) or enable (0) bucket refresh. This can be useful to disable bucket refresh when debugging outgoing DHT searches. (current setting: %t)\n", dht.DisableBucketRefresh)
if number, valid := getUserOptionInt(reader); !valid || number < 0 || number > 1 {

View File

@@ -46,6 +46,7 @@ func init() {
core.UserAgent = appName + "/" + core.Version
core.Filters.LogError = logError
core.Filters.DHTSearchStatus = filterSearchStatus
core.Filters.IncomingRequest = filterIncomingRequest
core.Init()
}

2
go.mod
View File

@@ -3,6 +3,6 @@ module github.com/PeernetOfficial/Cmd
go 1.16
require (
github.com/PeernetOfficial/core v0.0.0-20210729011714-fc1f0407f3af
github.com/PeernetOfficial/core v0.0.0-20210729021053-3233bf5c1bf6
github.com/btcsuite/btcd v0.22.0-beta.0.20210625194946-86a17263b0ff
)

4
go.sum
View File

@@ -1,5 +1,5 @@
github.com/PeernetOfficial/core v0.0.0-20210729011714-fc1f0407f3af h1:oEWnUdo7Ymqc53CzpCZCI5aDmzGT69znMAeEl6G8L64=
github.com/PeernetOfficial/core v0.0.0-20210729011714-fc1f0407f3af/go.mod h1:9aIe6MS6tefJnfmyEZFqaNF4NIeq7wJutV7EU+uowps=
github.com/PeernetOfficial/core v0.0.0-20210729021053-3233bf5c1bf6 h1:J4Tb6sP7fnOrTsrJtXaSDqA1CpEYPmF6lg6QjeOUm0I=
github.com/PeernetOfficial/core v0.0.0-20210729021053-3233bf5c1bf6/go.mod h1:9aIe6MS6tefJnfmyEZFqaNF4NIeq7wJutV7EU+uowps=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.21.0-beta.0.20210401013323-36a96f6a0025/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA=