Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Enhance hole punching #20

Open
wants to merge 2 commits into
base: decentralized-hole-punching
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/pcp/pcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/dennis-tra/pcp/internal/log"
"github.com/dennis-tra/pcp/pkg/receive"
"github.com/dennis-tra/pcp/pkg/send"
logging "github.com/ipfs/go-log/v2"
)

var (
Expand Down Expand Up @@ -45,6 +46,7 @@ func main() {
Before: func(c *cli.Context) error {
if c.Bool("debug") {
log.SetLevel(log.DebugLevel)
logging.SetLogLevel("p2p-holepunch", "debug")
}
return nil
},
Expand Down
14 changes: 14 additions & 0 deletions pkg/node/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"sync"
"time"

"github.com/pkg/errors"

Expand Down Expand Up @@ -130,6 +131,19 @@ func (t *TransferProtocol) onTransfer(s network.Stream) {
// the progress to the user. This function returns when the bytes where transmitted and we have received an
// acknowledgment.
func (t *TransferProtocol) Transfer(ctx context.Context, peerID peer.ID, basePath string) error {

ctx = network.WithForceDirectDial(ctx, "hole-punching")
for i := 0; i < 3; i++ {
if _, err := t.node.Network().DialPeer(ctx, peerID); err == nil {
break
}
select {
case <-ctx.Done():
return nil
case <-time.After(5 * time.Second):
}
}

// Open a new stream to our peer.
s, err := t.node.NewStream(ctx, peerID, ProtocolTransfer)
if err != nil {
Expand Down