mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
add peer discovery
This commit is contained in:
parent
2c444ad400
commit
b2885a7d95
3 changed files with 16 additions and 7 deletions
18
src/api.go
18
src/api.go
|
@ -15,21 +15,29 @@ func init() {
|
|||
// Relay initiates a relay
|
||||
func (c *Croc) Relay() error {
|
||||
// start relay
|
||||
go c.startRelay(c.TcpPorts)
|
||||
go c.startRelay()
|
||||
|
||||
// start server
|
||||
return c.startServer(c.TcpPorts, c.ServerPort)
|
||||
return c.startServer()
|
||||
}
|
||||
|
||||
// Send will take an existing file or folder and send it through the croc relay
|
||||
func (c *Croc) Send(fname string, codephrase string) (err error) {
|
||||
// start relay for listening
|
||||
go func() {
|
||||
go c.startRelay([]string{"27140,27141"})
|
||||
go c.startServer([]string{"27140,27141"}, "8140")
|
||||
d := c
|
||||
d.ServerPort = "8140"
|
||||
d.TcpPorts = []string{"27140", "27141"}
|
||||
go d.startRelay()
|
||||
go d.startServer()
|
||||
// e := c
|
||||
// time.Sleep(100 * time.Millisecond)
|
||||
// e.WebsocketAddress = "ws://127.0.0.1:8140"
|
||||
// go e.client(0, codephrase, fname)
|
||||
}()
|
||||
|
||||
// start client
|
||||
// start other client
|
||||
c.WebsocketAddress = "ws://127.0.0.1:8140"
|
||||
return c.client(0, codephrase, fname)
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (c *Croc) startRelay(ports []string) {
|
||||
func (c *Croc) startRelay() {
|
||||
ports := c.TcpPorts
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(len(ports))
|
||||
for _, port := range ports {
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
)
|
||||
|
||||
// startServer initiates the server which listens for websocket connections
|
||||
func (c *Croc) startServer(tcpPorts []string, port string) (err error) {
|
||||
func (c *Croc) startServer() (err error) {
|
||||
// start cleanup on dangling channels
|
||||
go c.channelCleanup()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue