mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
update
This commit is contained in:
parent
7060eec8d1
commit
f4d24a1f72
1 changed files with 26 additions and 22 deletions
|
@ -123,8 +123,7 @@ func New(ops Options) (c *Client, err error) {
|
||||||
Debug(c.Options.Debug)
|
Debug(c.Options.Debug)
|
||||||
log.Debugf("options: %+v", c.Options)
|
log.Debugf("options: %+v", c.Options)
|
||||||
|
|
||||||
c.conn = make([]*comm.Comm, len(c.Options.RelayPorts))
|
c.conn = make([]*comm.Comm, 16)
|
||||||
|
|
||||||
|
|
||||||
// use default key (no encryption, until PAKE succeeds)
|
// use default key (no encryption, until PAKE succeeds)
|
||||||
c.Key, err = crypt.New(nil, nil)
|
c.Key, err = crypt.New(nil, nil)
|
||||||
|
@ -158,34 +157,30 @@ func (c *Client) Send(options TransferOptions) (err error) {
|
||||||
go func() {
|
go func() {
|
||||||
discoveries, err := peerdiscovery.Discover(peerdiscovery.Settings{
|
discoveries, err := peerdiscovery.Discover(peerdiscovery.Settings{
|
||||||
Limit: 1,
|
Limit: 1,
|
||||||
Payload: []byte(c.Options.RelayPorts[0]),
|
Payload: []byte("9009"),
|
||||||
Delay: 10 * time.Millisecond,
|
Delay: 10 * time.Millisecond,
|
||||||
TimeLimit: 30 * time.Second,
|
TimeLimit: 30 * time.Second,
|
||||||
})
|
})
|
||||||
fmt.Println(discoveries, err)
|
fmt.Println(discoveries, err)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) send(address string) (err error)
|
|
||||||
|
|
||||||
// connect to the relay for messaging
|
// connect to the relay for messaging
|
||||||
log.Debug("establishing connection")
|
errchan := make(chan error, 1)
|
||||||
c.conn[0], err = tcp.ConnectToTCPServer(c.Options.RelayAddress, c.Options.SharedSecret)
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, fmt.Sprintf("could not connect to %s:%s", c.Options.RelayAddress, c.Options.RelayPorts[0]))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Debugf("connection established: %+v", c.conn[0])
|
|
||||||
if c.Options.IsSender {
|
|
||||||
fmt.Println(c.conn[0].Receive())
|
|
||||||
} else {
|
|
||||||
c.conn[0].Send([]byte("hello"))
|
|
||||||
}
|
|
||||||
log.Debug("exchanged header message")
|
|
||||||
|
|
||||||
return c.transfer(options)
|
go func() {
|
||||||
|
log.Debug("establishing connection")
|
||||||
|
c.conn[0], err = tcp.ConnectToTCPServer(c.Options.RelayAddress, c.Options.SharedSecret)
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Wrap(err, fmt.Sprintf("could not connect to %s", c.Options.RelayAddress))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Debugf("connection established: %+v", c.conn[0])
|
||||||
|
fmt.Println(c.conn[0].Receive())
|
||||||
|
log.Debug("exchanged header message")
|
||||||
|
errchan <- c.transfer(options)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return <-errchan
|
||||||
}
|
}
|
||||||
|
|
||||||
// Receive will receive a file
|
// Receive will receive a file
|
||||||
|
@ -199,6 +194,15 @@ func (c *Client) Receive() (err error) {
|
||||||
//})
|
//})
|
||||||
//fmt.Println(discoveries)
|
//fmt.Println(discoveries)
|
||||||
//fmt.Println(err)
|
//fmt.Println(err)
|
||||||
|
log.Debug("establishing connection")
|
||||||
|
c.conn[0], err = tcp.ConnectToTCPServer(c.Options.RelayAddress, c.Options.SharedSecret)
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Wrap(err, fmt.Sprintf("could not connect to %s", c.Options.RelayAddress))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Debugf("connection established: %+v", c.conn[0])
|
||||||
|
c.conn[0].Send([]byte("handshake"))
|
||||||
|
log.Debug("exchanged header message")
|
||||||
return c.transfer(TransferOptions{})
|
return c.transfer(TransferOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue