Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p2p - dht to addrbook #890

Merged
merged 11 commits into from May 14, 2019

Conversation

Projects
None yet
3 participants
@y0sher
Copy link
Collaborator

commented May 12, 2019

No description provided.

)

// DHT is an interface to a general distributed hash table.
type Interface interface {

This comment has been minimized.

Copy link
@almogdepaz

almogdepaz May 13, 2019

Member

maybe use api or something , because interface is a golang keyword i think it will be clearer

@y0sher y0sher force-pushed the p2p_dht_to_addrbook branch from 9309590 to 01128fc May 13, 2019

}

// SelectPeers asks routing table to randomly select a slice of nodes in size `qty`
func (d *Discovery) SelectPeers(qty int) []node.Node {

This comment has been minimized.

Copy link
@antonlerner

antonlerner May 13, 2019

Member

what happens if no peers are found? is this expected and normal behaviour?

This comment has been minimized.

Copy link
@y0sher

y0sher May 14, 2019

Author Collaborator

yes this is handled because we might actually have an empty table


// Failed attempts deprioritise.
for i := ka.attempts; i > 0; i-- {
c /= 1.5

This comment has been minimized.

Copy link
@antonlerner

antonlerner May 13, 2019

Member

c= c /( 1.5 ^ attempts)

}
}

func (r *refresher) Bootstrap(ctx context.Context, num int) error {

This comment has been minimized.

Copy link
@antonlerner

antonlerner May 13, 2019

Member

rename num


if size-len(r.bootNodes) < num {
r.logger.Info("Bootstrap: starting with %v sized table", size)
res := r.refresh(servers)

This comment has been minimized.

Copy link
@antonlerner

antonlerner May 13, 2019

Member

refresh does not imply anything about what this function actually does. it gets more peers so i'd call it something like refreshPeerList or something

servers = r.bootNodes
}

if size-len(r.bootNodes) < num {

This comment has been minimized.

Copy link
@antonlerner

antonlerner May 13, 2019

Member

I'd refactor this to `if size < num + len' to negative values for size


now := time.Now()

maxPending := 3

This comment has been minimized.

Copy link
@antonlerner

antonlerner May 13, 2019

Member

move to const


}

for _, b := range r.bootNodes {

This comment has been minimized.

Copy link
@antonlerner

antonlerner May 14, 2019

Member

add comment why this is happening

tries := 0
servers := make([]discNode, 0, len(r.bootNodes))
loop:
for {

This comment has been minimized.

Copy link
@antonlerner

antonlerner May 14, 2019

Member

I'd be very happy if you write a short comment on how things work here

return err
}

func expire(m map[p2pcrypto.PublicKey]time.Time) {

This comment has been minimized.

Copy link
@antonlerner

antonlerner May 14, 2019

Member

this function will evict only one item on each call, is this wanted behaviour?

This comment has been minimized.

Copy link
@y0sher

y0sher May 14, 2019

Author Collaborator

yes

}

// pingThenFindNode is sending a ping, then find node, then return results on given chan.
func pingThenFindNode(p Protocol, addr discNode, qr chan queryResult) {

This comment has been minimized.

Copy link
@antonlerner

antonlerner May 14, 2019

Member

rename to pingAndGetAddresses

if err != nil {
return nil, err
}

// response handler
ch := make(chan []discNode)
foo := func(msg []byte) {

This comment has been minimized.

Copy link
@antonlerner

antonlerner May 14, 2019

Member

rename foo

p.logger.Info("handle find_node response")
data := &pb.FindNodeResp{}
//p.logger.Info("handle find_node response from %v", serverNode.String())
data := &pb.Addresses{}
if err := proto.Unmarshal(msg, data); err != nil {
p.logger.Error("could not unmarshal block data")

This comment has been minimized.

Copy link
@antonlerner

antonlerner May 14, 2019

Member

rename error

"net"
)

type discNode struct {

This comment has been minimized.

Copy link
@antonlerner

antonlerner May 14, 2019

Member

consider renaming to NodeAddr or NodeInfo

}

// refresh will crawl the network looking for new peer addresses.
func (r *refresher) refresh(addrs []discNode) []discNode {

This comment has been minimized.

Copy link
@antonlerner

antonlerner May 14, 2019

Member

consider renaming to refreshAddresses

@y0sher y0sher force-pushed the p2p_dht_to_addrbook branch from 092a718 to 2b6d38e May 14, 2019

@y0sher y0sher force-pushed the p2p_dht_to_addrbook branch from 71a30c8 to 6de1044 May 14, 2019

@y0sher y0sher merged commit 28b8653 into develop May 14, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.