Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Commit

Permalink
Some code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nickname76 committed Aug 10, 2020
1 parent 3e6681c commit 4fbc28f
Showing 1 changed file with 5 additions and 47 deletions.
52 changes: 5 additions & 47 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,6 @@ func (saf *strArrFlags) Set(value string) error {
return nil
}

type uint16ArrFlags []uint16

func (uaf *uint16ArrFlags) String() string {
return fmt.Sprint([]uint16(*uaf))
}

func (uaf *uint16ArrFlags) Set(value string) error {
n, err := strconv.ParseUint(value, 10, 16)
if err != nil {
return err
}

*uaf = append(*uaf, uint16(n))
return nil
}

var (
fwr *p2pforwarder.Forwarder
fwrCancel func()
Expand All @@ -90,10 +74,10 @@ func main() {
connectIds := strArrFlags{}
flag.Var(&connectIds, "connect", "Add id you want connect to (can be used multiple times).")

tcpPorts := uint16ArrFlags{}
tcpPorts := strArrFlags{}
flag.Var(&tcpPorts, "tcp", "Add tcp port you want to open (can be used multiple times).")

udpPorts := uint16ArrFlags{}
udpPorts := strArrFlags{}
flag.Var(&udpPorts, "udp", "Add udp port you want to open (can be used multiple times).")

flag.Parse()
Expand All @@ -110,40 +94,14 @@ func main() {
zap.L().Info("Your id: " + fwr.ID())

for _, port := range tcpPorts {
zap.L().Info("Opening tcp:" + strconv.FormatUint(uint64(port), 10))

cancel, err := fwr.OpenPort("tcp", port)
if err != nil {
zap.S().Error(err)
continue
}

openTCPPorts[port] = cancel
cmdOpen([]string{"tcp", port})
}
for _, port := range udpPorts {
zap.L().Info("Opening udp: " + strconv.FormatUint(uint64(port), 10))

cancel, err := fwr.OpenPort("udp", port)
if err != nil {
zap.S().Error(err)
continue
}

openUDPPorts[port] = cancel
cmdOpen([]string{"udp", port})
}

for _, id := range connectIds {
zap.L().Info("Connecting to " + id)

listenip, cancel, err := fwr.Connect(id)
if err != nil {
zap.S().Error(err)
continue
}

connections[id] = cancel

zap.L().Info("Connections to " + id + "'s ports are listened on " + listenip)
cmdConnect([]string{id})
}

zap.L().Info("Initialization completed")
Expand Down

0 comments on commit 4fbc28f

Please sign in to comment.