Skip to content

Commit

Permalink
More log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
piegamesde committed Aug 17, 2022
1 parent 1007095 commit 6ba7c16
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions wormhole/file_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"io"
"log"
"math"
"math/big"
"net"
Expand Down Expand Up @@ -184,8 +185,10 @@ func (t *fileTransport) connectViaRelay(otherTransit *transitMsg) (net.Conn, err

var count int
for _, relay := range otherTransit.HintsV1 {
log.Println("relay: ", relay)
if relay.Type == "relay-v1" {
for _, endpoint := range relay.Hints {
log.Println("- endpoint: ", endpoint)
var addr string
switch endpoint.Type {
case "direct-tcp-v1":
Expand All @@ -195,6 +198,7 @@ func (t *fileTransport) connectViaRelay(otherTransit *transitMsg) (net.Conn, err
}
ctx, cancel := context.WithCancel(context.Background())
cancelFuncs[addr] = cancel
log.Println("- addr: ", addr)

count++
go t.connectToRelay(ctx, successChan, failChan)
Expand Down Expand Up @@ -264,9 +268,11 @@ func (t *fileTransport) connectToRelay(ctx context.Context, successChan chan net
var err error
addr := fmt.Sprintf("%s:%s", t.relayURL.Hostname(), t.relayURL.Port())

log.Println("- Relay: ", t.relayURL)
switch t.relayURL.Scheme {
case "tcp":
conn, err = d.DialContext(ctx, "tcp", addr)
log.Println(" - ", conn, err)

if err != nil {
failChan <- addr
Expand All @@ -285,19 +291,22 @@ func (t *fileTransport) connectToRelay(ctx context.Context, successChan chan net
}

_, err = conn.Write(t.relayHandshakeHeader())
log.Println(" - ", err)
if err != nil {
failChan <- addr
return
}
gotOk := make([]byte, 3)
_, err = io.ReadFull(conn, gotOk)
log.Println(" - ", err)
if err != nil {
conn.Close()
failChan <- addr
return
}

if !bytes.Equal(gotOk, []byte("ok\n")) {
log.Println(" - Not OK")
conn.Close()
failChan <- addr
return
Expand Down Expand Up @@ -511,6 +520,7 @@ func (t *fileTransport) listen() error {

func (t *fileTransport) listenRelay(ctx context.Context) (err error) {
var conn net.Conn
log.Println("URL: ", t.relayURL)
switch t.relayURL.Scheme {
case "tcp":
// NB: don't dial the relay if we don't have an address.
Expand Down

0 comments on commit 6ba7c16

Please sign in to comment.