forked from blink-cdn/Swami-Delivery-Network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.go
98 lines (74 loc) · 2.42 KB
/
node.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
94
95
96
97
98
package main
import (
"fmt"
"net"
"os"
"time"
// Blink library import needs "./"
"./blink"
"./blink/blinkEstimators"
)
var (
RoutingTable map[string]*blink.Link
localNode *net.UDPAddr
oracleAddr *net.UDPAddr
nextNode *blink.Link
finalBuffer []byte
)
func main() {
if len(os.Args) != 7 {
fmt.Println("Incorrect Amount of Inputs")
os.Exit(1)
}
defer fmt.Println(time.Now())
// CREATE data FILE
file, err := os.Create("data.txt")
blink.CheckError(err)
defer file.Close()
// Set Up Addresses to use
localNodeAddr, err := net.ResolveUDPAddr("udp", os.Args[1])
blink.CheckError(err)
nodeAddr1, err := net.ResolveUDPAddr("udp", os.Args[2])
blink.CheckError(err)
nodeAddr2, err := net.ResolveUDPAddr("udp", os.Args[3])
blink.CheckError(err)
nodeAddr3, err := net.ResolveUDPAddr("udp", os.Args[4])
blink.CheckError(err)
oracleAddr, err = net.ResolveUDPAddr("udp", os.Args[5])
blink.CheckError(err)
blink.LocalAddrString = os.Args[6] + os.Args[1]
// Setup Routing Table and It's Links
RoutingTable = make(map[string]*blink.Link)
var link1 blink.Link
link1.Addr = nodeAddr1.String()
link1.Latency = 50
link1.TTLExpiration = time.Now().Add(blink.ROUTE_TTL * time.Millisecond)
RoutingTable[nodeAddr1.String()] = &link1
var link2 blink.Link
link2.Addr = nodeAddr2.String()
link2.Latency = 50
link2.TTLExpiration = time.Now().Add(blink.ROUTE_TTL * time.Millisecond)
RoutingTable[nodeAddr2.String()] = &link2
var link3 blink.Link
link3.Addr = nodeAddr3.String()
link3.Latency = 50
link3.TTLExpiration = time.Now().Add(blink.ROUTE_TTL * time.Millisecond)
RoutingTable[nodeAddr3.String()] = &link3
blink.SetLatencyEstimatorFunction(blinkEstimators.ProbabilisticEstimator)
// Initialize Decision Table
DecisionTable := make(map[string][]string)
DecisionTable[""] = []string{"k", "l", "m"}
blink.SetDecisionTable(DecisionTable)
// Let Blink Know What Variables are What
blink.SetRoutingTable(RoutingTable)
blink.SetLocalAddr(localNodeAddr)
blink.SetOracleAddr(oracleAddr)
blink.SetupListener()
/* Go Check Expiration of Routing Table and Listen for Incoming Data
This is the actual functionality of the nodes, with 2 go routines Checking
to see if they should initalize a probe to another node (1 node per routine)
the third function being the active listener, whihc will determine what to do
with or in response to the incoming packets*/
blink.StartNode()
time.Sleep(30 * time.Second)
}