-
-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathmain.go
93 lines (81 loc) · 2.33 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"flag"
"fmt"
"github.com/ergo-services/ergo"
"github.com/ergo-services/ergo/node"
)
func main() {
flag.Parse()
fmt.Printf("Starting node: node1 (cluster 1) ...")
node1, err := ergo.StartNode("node1@localhost", "secret1", node.Options{})
if err != nil {
panic(err)
}
fmt.Println("OK")
fmt.Printf("Starting node: node2 (cluster 1) with Proxy.Transit = true ...")
opts2 := node.Options{}
opts2.Proxy.Transit = true
node2, err := ergo.StartNode("node2@localhost", "secret1", opts2)
if err != nil {
panic(err)
}
fmt.Println("OK")
fmt.Printf("Starting node: node3 (cluster 2) with Proxy.Transit = true ...")
opts3 := node.Options{}
opts3.Proxy.Transit = true
node3, err := ergo.StartNode("node3@localhost", "secret2", opts3)
if err != nil {
panic(err)
}
fmt.Println("OK")
proxyCookie := "abc"
fmt.Printf("Starting node: node4 (cluster 2) with Proxy.Cookie = %q ...", proxyCookie)
opts4 := node.Options{}
opts4.Proxy.Cookie = proxyCookie
node4, err := ergo.StartNode("node4@localhost", "secret2", opts4)
if err != nil {
panic(err)
}
fmt.Println("OK")
fmt.Printf("Add static route on node2 to node3 with custom cookie to get access to the cluster 2 ...")
routeOptions := node.RouteOptions{
Cookie: "secret2",
}
if err := node2.AddStaticRouteOptions(node3.Name(), routeOptions); err != nil {
panic(err)
}
fmt.Println("OK")
fmt.Printf("Add proxy route to node4 via node2 on node1 with proxy cookie = %q and enabled encryption ...", proxyCookie)
proxyRoute1 := node.ProxyRoute{
Proxy: node2.Name(),
Cookie: proxyCookie,
Flags: node.DefaultProxyFlags(),
}
proxyRoute1.Flags.EnableEncryption = true
if err := node1.AddProxyRoute(node4.Name(), proxyRoute1); err != nil {
panic(err)
}
fmt.Println("OK")
fmt.Printf("Add proxy route to node4 via node3 on node2 ...")
proxyRoute2 := node.ProxyRoute{
Proxy: node3.Name(),
}
if err := node2.AddProxyRoute(node4.Name(), proxyRoute2); err != nil {
panic(err)
}
fmt.Println("OK")
fmt.Printf("Connect node1 to node4 ...")
if err := node1.Connect(node4.Name()); err != nil {
panic(err)
}
fmt.Println("OK")
fmt.Println("Peers on node1", node1.Nodes())
fmt.Println("Peers on node2", node2.Nodes())
fmt.Println("Peers on node3", node3.Nodes())
fmt.Println("Peers on node4", node4.Nodes())
node1.Stop()
node2.Stop()
node3.Stop()
node4.Stop()
}