-
Notifications
You must be signed in to change notification settings - Fork 0
/
dumbproxy.go
59 lines (47 loc) · 1.25 KB
/
dumbproxy.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
package main
import (
"context"
"os"
"os/signal"
"sync"
"time"
"github.com/sirupsen/logrus"
"github.com/hsmade/comfoconnectbridge/pkg/comfoconnect"
"github.com/hsmade/comfoconnectbridge/pkg/dumbproxy"
"github.com/hsmade/comfoconnectbridge/pkg/instrumentation"
)
func main() {
logrus.SetLevel(logrus.DebugLevel)
customFormatter := new(logrus.TextFormatter)
customFormatter.TimestampFormat = time.StampMilli
logrus.SetFormatter(customFormatter)
customFormatter.FullTimestamp = true
ctx, cancel := context.WithCancel(context.Background())
wg := &sync.WaitGroup{}
closer := instrumentation.EnableTracing("proxy", "tower:5775")
defer closer.Close()
//instrumentation.EnableMetrics()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
gatewayUUID, err := comfoconnect.DiscoverGateway("192.168.0.19")
if err != nil {
logrus.Errorf("failed to discover gateway: %v", err)
return
}
logrus.Infof("got gateway UUID: %x", gatewayUUID)
l := comfoconnect.NewBroadcastListener("192.168.178.52", gatewayUUID)
go l.Run()
defer l.Stop()
p := dumbproxy.DumbProxy{
GatewayIP: "192.168.0.19",
}
go p.Run(ctx, wg)
logrus.Info("waiting for ctrl-c")
for _ = range c {
logrus.Info("closing down")
l.Stop()
cancel()
wg.Wait()
os.Exit(0)
}
}