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 discover topic #8

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Dockerfile.topdisc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Support setting various labels on the final image
ARG COMMIT=""
ARG VERSION=""
ARG BUILDNUM=""

# Build Geth in a stock Go builder container
FROM golang:1.17-alpine as builder

RUN apk add --no-cache gcc musl-dev linux-headers git curl

ADD . /go-ethereum
RUN cd /go-ethereum && go build ./cmd/devp2p
#comment down the below and use entrypoint instead
#RUN cd /go-ethereum && /bin/sh ./run-network.sh 1
WORKDIR /go-ethereum
RUN ./devp2p key generate node.key
EXPOSE 8545 8546 30303 30303/udp
#uncomment and add here a command to run the topdisc node
#CMD /go-ethereum/devp2p --verbosity 5 discv5 listen
#ENTRYPOINT ["app", "arg1", "arg2"]

# Add some metadata labels to help programatic image consumption
ARG COMMIT=""
ARG VERSION=""
ARG BUILDNUM=""

LABEL commit="$COMMIT" version="$VERSION" buildnum="$BUILDNUM"


13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.6'

services:
bootstrap:
image: devp2p
entrypoint: "./devp2p --verbosity 5 discv5 listen --bootnodes enode://582299339f1800f3ff3238ca8772b85543b5f5d4c1fab8d0a00c274a7bcf2cccb02ea72d250ee22b912d006b5a170c15c648cc2476d738baabb8519da7a7bd70@go-ethereum_bootstrap_1:0?discport=32000 --nodekey 7fbc0a865aad6ff63baf1d16e62c07e6cc7427d1f1fc99081af758d6aa27175b --addr go-ethereum_bootstrap_1:32000 --rpc go-ethereum_bootstrap_1:22000"
volumes:
- ./discv5-test:/go-ethereum/discv5-test
devp2p:
image: devp2p
entrypoint: sh start_node.sh
volumes:
- ./discv5-test:/go-ethereum/discv5-test
5 changes: 3 additions & 2 deletions p2p/discover/v5wire/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package v5wire

import (
"encoding/hex"
"fmt"
"net"

Expand Down Expand Up @@ -209,7 +210,7 @@ func (*TalkResponse) Kind() byte { return TalkResponseMsg }
func (p *TalkResponse) RequestID() []byte { return p.ReqID }
func (p *TalkResponse) SetRequestID(id []byte) { p.ReqID = id }

func (*Regtopic) Name() string { return "REGTOPIC/v5" }
func (p *Regtopic) Name() string { return "REGTOPIC/v5:" + hex.EncodeToString(p.Topic[:]) }
func (*Regtopic) Kind() byte { return RegtopicMsg }
func (p *Regtopic) RequestID() []byte { return p.ReqID }
func (p *Regtopic) SetRequestID(id []byte) { p.ReqID = id }
Expand All @@ -219,7 +220,7 @@ func (*Regconfirmation) Kind() byte { return RegconfirmationMsg }
func (p *Regconfirmation) RequestID() []byte { return p.ReqID }
func (p *Regconfirmation) SetRequestID(id []byte) { p.ReqID = id }

func (*TopicQuery) Name() string { return "TOPICQUERY/v5" }
func (p *TopicQuery) Name() string { return "TOPICQUERY/v5:" + hex.EncodeToString(p.Topic[:]) }
func (*TopicQuery) Kind() byte { return TopicQueryMsg }
func (p *TopicQuery) RequestID() []byte { return p.ReqID }
func (p *TopicQuery) SetRequestID(id []byte) { p.ReqID = id }
63 changes: 57 additions & 6 deletions run-network.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env bash

N_NODES=3
N_NODES="${1:-3}"
DIR=discv5-test
IP="172.19."
iface="tap"

# make_keys creates all node keys.
make_keys() {
Expand All @@ -18,7 +20,9 @@ make_keys() {
# get_node_url returns the enode URL of node $i.
get_node_url() {
let "port = 30200 + $1"
./devp2p key to-enode "$DIR/keys/node-$1.key" --tcp 0 --udp $port
subnet="1."
addr=$IP$subnet$1
./devp2p key to-enode "$DIR/keys/node-$1.key" --tcp 0 --udp $port #--ip $addr
}

# start_nodes launches the node processes.
Expand All @@ -27,24 +31,71 @@ start_nodes() {
echo "Bootstrap node: $bootnode"

mkdir -p "$DIR/logs"
subnet=1
sep="."
host=1

for i in $(seq $N_NODES); do
let "port = 30200 + $i"
let "rpc = 20200 + $i"
keyfile="$DIR/keys/node-$i.key"
if test $host -gt 254
then
host=0
subnet=$((subnet+1))
fi
addr=$IP$subnet$sep$host
echo $addr
keyfile="$DIR/keys/node-$i.key"
logfile="$DIR/logs/node-$i.log"
echo "Starting node $i..."
rm -f "$logfile"
./devp2p --verbosity 5 discv5 listen --bootnodes "$bootnode" --nodekey "$(cat $keyfile)" --addr "127.0.0.1:$port" --rpc "127.0.0.1:$rpc" | tee "$logfile" &
./devp2p --verbosity 5 discv5 listen --bootnodes "$bootnode" --nodekey "$(cat $keyfile)" --addr "127.0.0.1:$port" --rpc "127.0.0.1:$rpc" 2>&1 | tee "$logfile" &
host=$((host+1))
done
}

generate_ip_addresses(){

brctl addbr br0
ip link set br0 up
subnet=1
sep="."
host=1
for i in $(seq $N_NODES); do
ifacename=$iface$i
if test $host -gt 254
then
host=0
subnet=$((subnet+1))
fi
addr=$IP$subnet$sep$host
echo $ifacename $addr
ip tuntap add mode tap $ifacename
ip addr add $addr dev $ifacename
ip link set $ifacename up
brctl addif br0 $ifacename
host=$((host+1))
done

}

cleanup(){
kill $(jobs -p)
# ip link del br0
# for i in $(seq $N_NODES); do
# ifacename=$iface$i
# ip link del $ifacename
# done
}

# Generate all keys.
make_keys

#generate_ip_addresses

# Cleanup at exit.
trap 'kill $(jobs -p)' EXIT
trap cleanup EXIT

# Launch nodes.
start_nodes
#start_nodes
wait
9 changes: 9 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

N=1
export COMPOSE_PARALLEL_LIMIT=1000
export COMPOSE_HTTP_TIMEOUT=300
export DOCKER_CLIENT_TIMEOUT=300

docker build . -f Dockerfile.topdisc -t devp2p
docker-compose up --scale devp2p=$N
2 changes: 2 additions & 0 deletions start_node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
./devp2p --verbosity 5 discv5 listen --bootnodes enode://582299339f1800f3ff3238ca8772b85543b5f5d4c1fab8d0a00c274a7bcf2cccb02ea72d250ee22b912d006b5a170c15c648cc2476d738baabb8519da7a7bd70@go-ethereum_bootstrap_1:0?discport=32000 --addr $(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'):32000 --rpc $(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'):22000
4 changes: 4 additions & 0 deletions stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

docker-compose down
docker network prune
Loading