-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
54 lines (47 loc) · 1.21 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
package main
import (
"flag"
log "github.com/sirupsen/logrus"
)
func main() {
var crypto string
var bind string
var bindPort int
var dial string
var dialPort int
flag.StringVar(&crypto, "crypto", "bitcoin", "cryptocurrency to proxy")
flag.StringVar(&bind, "bind", "0.0.0.0", "address to bind")
flag.IntVar(&bindPort, "bind-port", 8333, "port to bind")
flag.StringVar(&dial, "dial", "", "bitcoin node to proxy to")
flag.IntVar(&dialPort, "dial-port", 8333, "port to dial for bitcoin node")
flag.Parse()
listener := openBind(bind, bindPort)
for {
client, err := listener.Accept()
if err != nil {
log.WithFields(log.Fields{
"at": "main",
"error": err.Error(),
}).Error("error accepting connection from client")
continue
} else {
log.WithFields(log.Fields{
"at": "main",
"client": client.RemoteAddr().String(),
}).Info("new connection from a client")
}
node, err := openProxy(dial, dialPort)
if err != nil {
log.WithFields(log.Fields{
"at": "main",
"error": err.Error(),
"node": dial,
"port": dialPort,
}).Error("error connecting back to actual node")
client.Close()
continue
} else {
go intercept(crypto, client, node)
}
}
}