Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

network/kademlia: add JSON output of Kademlia table#1932

Closed
acud wants to merge 3 commits intomasterfrom
kad-json
Closed

network/kademlia: add JSON output of Kademlia table#1932
acud wants to merge 3 commits intomasterfrom
kad-json

Conversation

@acud
Copy link
Copy Markdown
Contributor

@acud acud commented Nov 7, 2019

This PR adds a JSON output for the Kademlia table.
It is very difficult to debug connectivity issues since we can see only 4 peers on the left side of the table and the right side does not subtract the peers on the left (showing overlapping peers).

This output has different fields for depth, each bin has a size field and list of known addresses.
The output is divided into connected and known peers. Where the peers in connected are subtracted from known. Thus, duplicates should not be shown.

This can probably be improved by adding another output array of all of the known addresses (regardless of being connected or not).

Any ideas to improve would be appreciated

@acud acud requested review from janos, nolash and zelig November 7, 2019 10:10
@acud acud self-assigned this Nov 7, 2019
Copy link
Copy Markdown
Member

@janos janos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did an early review even this PR is still in progress.

po = k.MaxProxDisplay - 1 // why???
}
size := bin.Size
poStr := fmt.Sprintf("%d", po)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To use strconv.Itoa? And in other places also.

numConns = k.conns.Size()
numAddrs = k.addrs.Size()
connectedAddrs = make(map[string]struct{})
connBinMap = make(map[string]string)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have comments on what these strings suppose to be.

return "\n" + strings.Join(rows, "\n")
}

func (k *Kademlia) MarshalJSON() (data []byte, err error) {
Copy link
Copy Markdown
Member

@janos janos Nov 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even this method just returns the representation of Kademlia, it contains logic that should be tested. I think that testing would be beneficial here. It would even help to see what is the actual structure produced, as only maps are used and to see the structure a complete walk thought he code is needed.

I believe that tests would reveal that data argument is not even used in this method, making it not functional.

With the previous observation, I would pull out the logic of constructing maps into a separate method and test only that leaving MarshalJSON only responsible for marshalling.


binMap["addresses"] = strings.Join(addresses, ",")
var binString []byte
binString, err = json.Marshal(binMap)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why marshalling binMap map and assigning it as the string to m map? This will produce an escaped string in the final marshalling, instead a json structure.

@acud acud closed this Feb 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants