@@ -62,22 +62,6 @@ func (saf *strArrFlags) Set(value string) error {
6262 return nil
6363}
6464
65- type uint16ArrFlags []uint16
66-
67- func (uaf * uint16ArrFlags ) String () string {
68- return fmt .Sprint ([]uint16 (* uaf ))
69- }
70-
71- func (uaf * uint16ArrFlags ) Set (value string ) error {
72- n , err := strconv .ParseUint (value , 10 , 16 )
73- if err != nil {
74- return err
75- }
76-
77- * uaf = append (* uaf , uint16 (n ))
78- return nil
79- }
80-
8165var (
8266 fwr * p2pforwarder.Forwarder
8367 fwrCancel func ()
@@ -90,10 +74,10 @@ func main() {
9074 connectIds := strArrFlags {}
9175 flag .Var (& connectIds , "connect" , "Add id you want connect to (can be used multiple times)." )
9276
93- tcpPorts := uint16ArrFlags {}
77+ tcpPorts := strArrFlags {}
9478 flag .Var (& tcpPorts , "tcp" , "Add tcp port you want to open (can be used multiple times)." )
9579
96- udpPorts := uint16ArrFlags {}
80+ udpPorts := strArrFlags {}
9781 flag .Var (& udpPorts , "udp" , "Add udp port you want to open (can be used multiple times)." )
9882
9983 flag .Parse ()
@@ -110,40 +94,14 @@ func main() {
11094 zap .L ().Info ("Your id: " + fwr .ID ())
11195
11296 for _ , port := range tcpPorts {
113- zap .L ().Info ("Opening tcp:" + strconv .FormatUint (uint64 (port ), 10 ))
114-
115- cancel , err := fwr .OpenPort ("tcp" , port )
116- if err != nil {
117- zap .S ().Error (err )
118- continue
119- }
120-
121- openTCPPorts [port ] = cancel
97+ cmdOpen ([]string {"tcp" , port })
12298 }
12399 for _ , port := range udpPorts {
124- zap .L ().Info ("Opening udp: " + strconv .FormatUint (uint64 (port ), 10 ))
125-
126- cancel , err := fwr .OpenPort ("udp" , port )
127- if err != nil {
128- zap .S ().Error (err )
129- continue
130- }
131-
132- openUDPPorts [port ] = cancel
100+ cmdOpen ([]string {"udp" , port })
133101 }
134102
135103 for _ , id := range connectIds {
136- zap .L ().Info ("Connecting to " + id )
137-
138- listenip , cancel , err := fwr .Connect (id )
139- if err != nil {
140- zap .S ().Error (err )
141- continue
142- }
143-
144- connections [id ] = cancel
145-
146- zap .L ().Info ("Connections to " + id + "'s ports are listened on " + listenip )
104+ cmdConnect ([]string {id })
147105 }
148106
149107 zap .L ().Info ("Initialization completed" )
0 commit comments