get tcp port information from banner

This commit is contained in:
Zack Scholl 2019-04-30 17:19:10 -06:00
parent c5bbdb4cb5
commit 1275c6b1b5
3 changed files with 16 additions and 17 deletions

View File

@ -55,14 +55,16 @@ func Run() (err error) {
Action: func(c *cli.Context) error {
return relay(c)
},
Flags: []cli.Flag{
cli.StringFlag{Name: "ports", Value: "9009,9010,9011,9012,9013,9014,9015,9016,9017,9018", Usage: "ports of the relay"},
},
},
}
app.Flags = []cli.Flag{
cli.BoolFlag{Name: "debug", Usage: "increase verbosity (a lot)"},
cli.BoolFlag{Name: "yes", Usage: "automatically agree to all prompts"},
cli.BoolFlag{Name: "stdout", Usage: "redirect file to stdout"},
cli.StringFlag{Name: "relay", Value: "198.199.67.130", Usage: "address of the relay"},
cli.StringFlag{Name: "ports", Value: "9009,9010,9011,9012,9013,9014,9015,9016,9017,9018", Usage: "address of the relay"},
cli.StringFlag{Name: "relay", Value: "198.199.67.130:9009", Usage: "address of the relay"},
cli.StringFlag{Name: "out", Value: ".", Usage: "specify an output folder to receive the file"},
}
app.EnableBashCompletion = true
@ -163,7 +165,6 @@ func send(c *cli.Context) (err error) {
Debug: c.GlobalBool("debug"),
NoPrompt: c.GlobalBool("yes"),
RelayAddress: c.GlobalString("relay"),
RelayPorts: strings.Split(c.GlobalString("ports"), ","),
Stdout: c.GlobalBool("stdout"),
})
if err != nil {
@ -200,7 +201,6 @@ func receive(c *cli.Context) (err error) {
NoPrompt: c.GlobalBool("yes"),
RelayAddress: c.GlobalString("relay"),
Stdout: c.GlobalBool("stdout"),
RelayPorts: strings.Split(c.GlobalString("ports"), ","),
})
if err != nil {
return
@ -215,12 +215,13 @@ func relay(c *cli.Context) (err error) {
debugString = "debug"
}
ports := strings.Split(c.GlobalString("ports"), ",")
tcpPorts := strings.Join(ports[1:], ",")
for i, port := range ports {
if i == 0 {
continue
}
go func(portStr string) {
err = tcp.Run(debugString, portStr, c.GlobalString("ports"))
err = tcp.Run(debugString, portStr, tcpPorts)
if err != nil {
panic(err)
}

View File

@ -262,7 +262,7 @@ func (c *Client) Send(options TransferOptions) (err error) {
time.Sleep(500 * time.Millisecond)
log.Debug("establishing connection")
var banner string
conn, banner, err := tcp.ConnectToTCPServer("localhost:"+c.Options.RelayPorts[0], c.Options.SharedSecret)
conn, banner, err := tcp.ConnectToTCPServer("localhost:9001", c.Options.SharedSecret)
log.Debugf("banner: %s", banner)
if err != nil {
err = errors.Wrap(err, fmt.Sprintf("could not connect to %s", c.Options.RelayAddress))
@ -283,9 +283,9 @@ func (c *Client) Send(options TransferOptions) (err error) {
}
go func() {
log.Debug("establishing connection")
log.Debug("establishing connection to %s", c.Options.RelayAddress)
var banner string
conn, banner, err := tcp.ConnectToTCPServer(c.Options.RelayAddress+":"+c.Options.RelayPorts[0], c.Options.SharedSecret)
conn, banner, err := tcp.ConnectToTCPServer(c.Options.RelayAddress, c.Options.SharedSecret)
log.Debugf("banner: %s", banner)
if err != nil {
err = errors.Wrap(err, fmt.Sprintf("could not connect to %s", c.Options.RelayAddress))
@ -323,7 +323,7 @@ func (c *Client) Receive() (err error) {
log.Debug("establishing connection")
}
var banner string
c.conn[0], banner, err = tcp.ConnectToTCPServer(c.Options.RelayAddress+":"+c.Options.RelayPorts[0], c.Options.SharedSecret)
c.conn[0], banner, err = tcp.ConnectToTCPServer(c.Options.RelayAddress, c.Options.SharedSecret)
log.Debugf("banner: %s", banner)
if err != nil {
err = errors.Wrap(err, fmt.Sprintf("could not connect to %s", c.Options.RelayAddress))
@ -414,8 +414,8 @@ func (c *Client) processMessage(payload []byte) (done bool, err error) {
// connects to the other ports of the server for transfer
var wg sync.WaitGroup
wg.Add(len(c.Options.RelayPorts) - 1)
for i := 1; i < len(c.Options.RelayPorts); i++ {
wg.Add(len(c.Options.RelayPorts))
for i := 0; i < len(c.Options.RelayPorts); i++ {
go func(j int) {
defer wg.Done()
c.conn[j], _, err = tcp.ConnectToTCPServer(
@ -638,7 +638,7 @@ func (c *Client) updateState() (err error) {
// setup the progressbar
c.setBar()
c.TotalSent = 0
for i := 1; i < len(c.Options.RelayPorts); i++ {
for i := 0; i < len(c.Options.RelayPorts); i++ {
go c.sendData(i)
}
}
@ -742,7 +742,7 @@ func (c *Client) sendData(i int) {
panic(err)
}
if math.Mod(curi, float64(len(c.Options.RelayPorts)-1))+1 == float64(i) {
if math.Mod(curi, float64(len(c.Options.RelayPorts))) == float64(i) {
// check to see if this is a chunk that the recipient wants
usableChunk := true
c.mutex.Lock()

View File

@ -26,8 +26,7 @@ func TestCroc(t *testing.T) {
IsSender: true,
SharedSecret: "test",
Debug: true,
RelayAddress: "localhost",
RelayPorts: []string{"8081", "8082", "8083"},
RelayAddress: "localhost:8081",
Stdout: false,
NoPrompt: true,
DisableLocal: true,
@ -41,8 +40,7 @@ func TestCroc(t *testing.T) {
IsSender: false,
SharedSecret: "test",
Debug: true,
RelayAddress: "localhost",
RelayPorts: []string{"8081", "8082", "8083"},
RelayAddress: "localhost:8081",
Stdout: false,
NoPrompt: true,
DisableLocal: true,