-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (61 loc) · 2.08 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"github.com/spf13/cobra"
"github.com/tgermain/grandRepositorySky/communicator/receiver"
"github.com/tgermain/grandRepositorySky/dht"
"github.com/tgermain/grandRepositorySky/node"
"github.com/tgermain/grandRepositorySky/shared"
"github.com/tgermain/grandRepositorySky/web"
"runtime"
"time"
)
func MakeDHTNode(NewId *string, NewIp, NewPort string) *node.DHTnode {
if NewId == nil || *NewId == "" {
tempId := dht.GenerateNodeId()
NewId = &tempId
}
shared.Logger.Notice("Creating node : \nId %v \nIP %s Port %.10s \n", *NewId, NewIp, NewPort)
//Set the globally shared information
shared.LocalId = *NewId
shared.LocalIp = NewIp
shared.LocalPort = NewPort
// create node with its commInterface
newNode, newSenderLink := node.MakeNode()
receiverLink := receiver.MakeReceiver(newNode, newSenderLink)
//Make the commInterface listen to incomming messages on globalIp, globalPort
receiverLink.StartAndListen()
return newNode
}
func main() {
shared.SetupLogger()
var Id string
var Ip string
var Port string
var DistIp string
var DistPort string
var staticPath string
rootCmd := &cobra.Command{Use: "grandRepositorySky",
Run: func(cmd *cobra.Command, args []string) {
node := MakeDHTNode(&Id, Ip, Port)
node.JoinRing(&shared.DistantNode{
"",
DistIp,
DistPort,
})
go web.MakeServer("", Port, node, staticPath)
// go func() {
for {
time.Sleep(time.Second)
runtime.Gosched()
}
// }()
},
}
rootCmd.Flags().StringVarP(&Id, "id", "n", "", "Id you want for your node")
rootCmd.Flags().StringVarP(&Ip, "ip", "i", "", "Ip you want for your node. Localhost by default")
rootCmd.Flags().StringVarP(&Port, "port", "p", "4321", "port you want for your node. 4321 by default")
rootCmd.Flags().StringVarP(&DistIp, "distIp", "w", "localhost", "Ip to an existing node you want to contact")
rootCmd.Flags().StringVarP(&DistPort, "distPort", "d", "4321", "port to an existing node you want to contact")
rootCmd.Flags().StringVarP(&staticPath, "path to static ressources", "s", "web/client", "path to static ressources")
rootCmd.Execute()
}