-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmain.go
81 lines (69 loc) · 1.59 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
// Copyright 2015 The GoTor Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"github.com/tvdw/cgolock"
"log"
"net/http"
"os"
"runtime"
"time"
)
import _ "net/http/pprof"
import _ "expvar"
func main() {
cgolock.Init(runtime.NumCPU())
runtime.GOMAXPROCS(runtime.NumCPU())
SetupRand()
SeedCellBuf()
torConfig := Config{
IsPublicServer: true,
Platform: "Tor 0.2.6.2-alpha on Go",
BandwidthAvg: 1073741824,
BandwidthBurst: 1073741824,
BandwidthObserved: 1 << 16,
}
if err := torConfig.ReadFile(os.Args[1]); err != nil {
log.Panicln(err)
}
or, err := NewOR(&torConfig)
if err != nil {
log.Panicln(err)
}
/*
go func() {
or.RequestCircuit(&CircuitRequest{
localID: 5,
connHint: ConnectionHint{
address: [][]byte{[]byte{127,0,0,1,35,41}},
},
})
}()
*/
anythingFinished := make(chan int)
go func() {
or.Run()
anythingFinished <- 1
}()
go func() {
Log(LOG_WARN, "%v", http.ListenAndServe("localhost:6060", nil))
}()
or.PublishDescriptor()
nextRotate := time.After(time.Hour * 1)
nextPublish := time.After(time.Hour * 18)
for {
select {
case <-nextRotate: //XXX randomer intervals
if err := or.RotateKeys(); err != nil {
Log(LOG_WARN, "%v", err)
}
nextRotate = time.After(time.Hour * 1)
case <-nextPublish:
or.PublishDescriptor()
nextPublish = time.After(time.Hour * 18)
case <-anythingFinished:
log.Panicln("Somehow a main.go goroutine we spawned managed to finish, which is not good")
}
}
}