-
Notifications
You must be signed in to change notification settings - Fork 2
/
proxy.go
54 lines (45 loc) · 1.25 KB
/
proxy.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 (
"context"
"fmt"
"net"
"pome/define"
"google.golang.org/grpc"
)
func ExecUnitProxy(nodeActiveContext context.Context, nodeActiveContextCancel func(), exitChannel chan bool) {
P.local = nodeGRPC{
addr: "127.0.0.1",
}
lnINgrpc, err := net.Listen("tcp", fmt.Sprintf(":%d", define.SidecarPortOuterGRPC))
if err != nil {
panic(err)
}
srvIN := grpc.NewServer(grpc.UnknownServiceHandler(handlerInGRPC(nodeActiveContext)))
go srvIN.Serve(lnINgrpc)
lnINtcp, err := net.Listen("tcp", fmt.Sprintf(":%d", define.SidecarPortOuterTCP))
if err != nil {
panic(err)
}
go handlerInTCP(nodeActiveContext, lnINtcp)
lnOUTgrpc, err := net.Listen("tcp", fmt.Sprintf(":%d", define.SidecarPortInnerGRPC))
if err != nil {
panic(err)
}
srvOUT := grpc.NewServer(grpc.UnknownServiceHandler(handlerOutGRPC(nodeActiveContext)))
go srvOUT.Serve(lnOUTgrpc)
lnOUTtcp, err := net.Listen("tcp", fmt.Sprintf(":%d", define.SidecarPortInnerTCP))
if err != nil {
panic(err)
}
go handlerOutTCP(nodeActiveContext, lnOUTtcp)
fmt.Println("sidecar proxy listening")
<-nodeActiveContext.Done()
srvIN.GracefulStop()
srvOUT.GracefulStop()
lnINgrpc.Close()
lnOUTgrpc.Close()
lnINtcp.Close()
lnOUTtcp.Close()
exitChannel <- true
fmt.Println("proxy down")
}