-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestbed.go
88 lines (73 loc) · 2.2 KB
/
testbed.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
package main
import (
"context"
"fmt"
"net"
"net/http"
"net/url"
"os"
// logging "github.com/ipfs/go-log"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
opentracing "github.com/opentracing/opentracing-go"
"sourcegraph.com/sourcegraph/appdash"
appdashot "sourcegraph.com/sourcegraph/appdash/opentracing"
"sourcegraph.com/sourcegraph/appdash/traceapp"
)
var (
peerCount = 20
log = logging.Logger("testbed")
)
func init() {
logging.Configure(logging.Output(os.Stdout), logging.LevelInfo)
}
func main() {
log.Infof("starting p2p-testbed with %d peers", peerCount)
startAppDash()
ctx := context.Background()
peers, err := Setup(ctx, peerCount)
if err != nil {
log.Fatalf("error setting up network: %s", err.Error())
}
// send a ping
if err := SendPing(peers[0], peers[0].RandomPeer()); err != nil {
log.Errorf("error sending message: %s", err.Error())
}
// take a CL snapshot
InitiateCLSnapshot(peers[1])
// block forever
<-make(chan bool)
}
func startAppDash() {
store := appdash.NewMemoryStore()
// Listen on any available TCP port locally.
l, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0})
if err != nil {
log.Fatal(err)
}
collectorPort := l.Addr().(*net.TCPAddr).Port
collectorAdd := fmt.Sprintf(":%d", collectorPort)
// Start an Appdash collection server that will listen for spans and
// annotations and add them to the local collector (stored in-memory).
cs := appdash.NewServer(l, appdash.NewLocalCollector(store))
go cs.Start()
// Print the URL at which the web UI will be running.
appdashPort := 8700
appdashURLStr := fmt.Sprintf("http://localhost:%d", appdashPort)
appdashURL, err := url.Parse(appdashURLStr)
if err != nil {
log.Fatalf("Error parsing %s: %s", appdashURLStr, err)
}
log.Infof("To see your traces, go to %s/traces", appdashURL)
// Start the web UI in a separate goroutine.
tapp, err := traceapp.New(nil, appdashURL)
if err != nil {
log.Fatal(err)
}
tapp.Store = store
tapp.Queryer = store
go func() {
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", appdashPort), tapp))
}()
tracer := appdashot.NewTracer(appdash.NewRemoteCollector(collectorAdd))
opentracing.InitGlobalTracer(tracer)
}