-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (49 loc) · 973 Bytes
/
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
package main
import (
"context"
"fmt"
"log"
)
func main() {
ctx := context.Background()
// Arguments
args, err := parseArgs()
if err != nil {
log.Fatal(err)
}
// P2P Host
h, err := newP2P(args.Port)
if err != nil {
log.Fatal(err)
}
defer h.Close()
// Tun interface
i, err := newif(args.Interface)
if err != nil {
log.Fatal(err)
}
defer i.Close()
err = applyif(args.Interface, args.Network)
if err != nil {
log.Fatal(err)
}
// For local-network
dMDNS, err := newMDNS(h, args.Rendezvous)
if err != nil {
log.Fatal(err)
}
// For global-network
dDHT, err := newDHT(ctx, h, args.Rendezvous)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Peer: %s\n", h.ID())
fmt.Printf("VPN Address: %s\n\n", args.Network)
// Discover
go dMDNS.run(args.Network)
go dDHT.run(args.Network)
// Packet
h.SetStreamHandler(MeshProtocol.ID(), meshHandler(i))
h.SetStreamHandler(DiscoveryProtocol.ID(), discoveryHandler)
meshBridge(ctx, h, i)
}