@ -1,4 +1,5 @@ |
|||||
id: "0fd85ddddf15aeec2d5d8b01b013dbca030a18d7" |
id: "0fd85ddddf15aeec2d5d8b01b013dbca030a18d7" |
||||
addr: 127.0.0.1 |
addr: 127.0.0.1 |
||||
port: 5000 |
port: 5000 |
||||
|
adminport: 6000 |
||||
storage: "tmp" |
storage: "tmp" |
@ -0,0 +1,9 @@ |
|||||
|
id: "c48d8b53dbefb609ed4e94d386dd5b22efcb2c5b" |
||||
|
addr: 127.0.0.1 |
||||
|
port: 5003 |
||||
|
adminport: 6003 |
||||
|
knownNodes: |
||||
|
- id: "1ff734fb9897600ca54a9c55ace2d22a51afb610" |
||||
|
addr: 127.0.0.1 |
||||
|
port: 5002 |
||||
|
storage: "tmp" |
@ -0,0 +1,78 @@ |
|||||
|
package node |
||||
|
|
||||
|
import ( |
||||
|
"go-dht/config" |
||||
|
"go-dht/kademlia" |
||||
|
"io/ioutil" |
||||
|
"net" |
||||
|
"net/http" |
||||
|
"net/rpc" |
||||
|
|
||||
|
log "github.com/sirupsen/logrus" |
||||
|
) |
||||
|
|
||||
|
type Admin struct { |
||||
|
node Node |
||||
|
disc map[kademlia.ID][]kademlia.ListedNode |
||||
|
} |
||||
|
|
||||
|
func NewAdmin(node Node) Admin { |
||||
|
return Admin{ |
||||
|
node: node, |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (a *Admin) Start() error { |
||||
|
// rpc server
|
||||
|
err := rpc.Register(a) |
||||
|
if err != nil { |
||||
|
return err |
||||
|
} |
||||
|
//
|
||||
|
oldMux := http.DefaultServeMux |
||||
|
mux := http.NewServeMux() |
||||
|
http.DefaultServeMux = mux |
||||
|
//
|
||||
|
rpc.HandleHTTP() |
||||
|
//
|
||||
|
http.DefaultServeMux = oldMux |
||||
|
//
|
||||
|
listener, err := net.Listen("tcp", ":"+config.C.AdminPort) |
||||
|
if err != nil { |
||||
|
return err |
||||
|
} |
||||
|
|
||||
|
err = http.Serve(listener, nil) |
||||
|
if err != nil { |
||||
|
return err |
||||
|
} |
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
func (a *Admin) Find(id kademlia.ID, lns *[]kademlia.ListedNode) error { |
||||
|
log.Info("[admin-rpc] FIND ", id) |
||||
|
|
||||
|
// check if id in current node
|
||||
|
_, err := ioutil.ReadFile(config.C.Storage + "/" + id.String()) |
||||
|
if err == nil { |
||||
|
*lns = []kademlia.ListedNode{ |
||||
|
kademlia.ListedNode{ |
||||
|
ID: a.node.ID(), |
||||
|
Addr: config.C.Addr, |
||||
|
Port: config.C.Port, |
||||
|
}, |
||||
|
} |
||||
|
log.Info("[admin-rpc] FIND found") |
||||
|
return nil |
||||
|
} |
||||
|
log.Info("[admin-rpc] FIND not in local Node, starting NodeLookup") |
||||
|
|
||||
|
rlns, err := a.node.Kademlia().NodeLookup(id) |
||||
|
if err != nil { |
||||
|
log.Debug("[admin-rpc/FIND] ERROR: ", err) |
||||
|
return err |
||||
|
} |
||||
|
*lns = rlns |
||||
|
|
||||
|
return nil |
||||
|
} |
@ -1,13 +1,18 @@ |
|||||
|
#!/bin/sh |
||||
|
|
||||
SESSION='go-dht' |
SESSION='go-dht' |
||||
|
|
||||
tmux new-session -d -s $SESSION |
tmux new-session -d -s $SESSION |
||||
tmux split-window -d -t 0 -v |
tmux split-window -d -t 0 -v |
||||
tmux split-window -d -t 0 -h |
tmux split-window -d -t 0 -h |
||||
|
tmux split-window -d -t 2 -h |
||||
|
|
||||
|
|
||||
tmux send-keys -t 0 'go run main.go --config config.test0.yaml --debug start' enter |
tmux send-keys -t 0 'go run main.go --config config.test0.yaml --debug start' enter |
||||
sleep 2 |
sleep 2 |
||||
tmux send-keys -t 1 'go run main.go --config config.test1.yaml --debug start' enter |
tmux send-keys -t 1 'go run main.go --config config.test1.yaml --debug start' enter |
||||
tmux send-keys -t 2 'go run main.go --config config.test2.yaml --debug start' enter |
tmux send-keys -t 2 'go run main.go --config config.test2.yaml --debug start' enter |
||||
|
sleep 1 |
||||
|
tmux send-keys -t 3 'go run main.go --config config.test3.yaml --debug start' enter |
||||
|
|
||||
tmux attach |
tmux attach |