This repository has been archived by the owner on Dec 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
do connection setup here #9
Closed
+1,030
−1,403
Closed
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e4d7c85
more consistent import names
marten-seemann bd7637a
remove dead code
marten-seemann c9c0af8
setup new connections
marten-seemann a8718ed
remove conn.Serve
marten-seemann f8e46f7
reenable the tests, and add some more
marten-seemann a23e5a8
introduce a timeout for dialing and accepting connections
marten-seemann dff3ff6
use the renamed transport interfaces
marten-seemann b2606fa
remove the MultiplexConn type assertions
marten-seemann 1820ac9
simplify accepting new connections
marten-seemann 8e5f941
fix race condition when accepting connections
marten-seemann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package conn | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
ci "github.com/libp2p/go-libp2p-crypto" | ||
iconn "github.com/libp2p/go-libp2p-interface-conn" | ||
peer "github.com/libp2p/go-libp2p-peer" | ||
tpt "github.com/libp2p/go-libp2p-transport" | ||
tcpt "github.com/libp2p/go-tcp-transport" | ||
tu "github.com/libp2p/go-testutil" | ||
ma "github.com/multiformats/go-multiaddr" | ||
yamux "github.com/whyrusleeping/go-smux-yamux" | ||
grc "github.com/whyrusleeping/gorocheck" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestGoLibp2pConn(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "go-libp2p-conn Suite") | ||
} | ||
|
||
var _ = AfterEach(func() { | ||
time.Sleep(300 * time.Millisecond) | ||
Expect(grc.CheckForLeaks(func(r *grc.Goroutine) bool { | ||
return strings.Contains(r.Function, "go-log.") || | ||
strings.Contains(r.Stack[0], "testing.(*T).Run") || | ||
strings.Contains(r.Function, "specrunner.") || | ||
strings.Contains(r.Function, "runtime.gopark") | ||
})).To(Succeed()) | ||
}) | ||
|
||
// the stream muxer used for tests using the single stream connection | ||
var streamMuxer = yamux.DefaultTransport | ||
|
||
// dialRawConn dials a tpt.Conn | ||
// but it stops there. It doesn't do protocol selection and handshake | ||
func dialRawConn(laddr, raddr ma.Multiaddr) tpt.Conn { | ||
d, err := tcpt.NewTCPTransport().Dialer(laddr) | ||
Expect(err).ToNot(HaveOccurred()) | ||
c, err := d.Dial(raddr) | ||
Expect(err).ToNot(HaveOccurred()) | ||
return c | ||
} | ||
|
||
// getTransport gets the right transport for a multiaddr | ||
func getTransport(a ma.Multiaddr) tpt.Transport { | ||
return tcpt.NewTCPTransport() | ||
} | ||
|
||
// getListener creates a listener based on the PeerNetParams | ||
// it updates the PeerNetParams to reflect the local address that was selected by the kernel | ||
func getListener(ctx context.Context, p *tu.PeerNetParams) iconn.Listener { | ||
tptListener, err := getTransport(p.Addr).Listen(p.Addr) | ||
Expect(err).ToNot(HaveOccurred()) | ||
list, err := WrapTransportListener(ctx, tptListener, p.ID, streamMuxer, p.PrivKey) | ||
Expect(err).ToNot(HaveOccurred()) | ||
p.Addr = list.Multiaddr() | ||
return list | ||
} | ||
|
||
func getDialer(localPeer peer.ID, privKey ci.PrivKey, addr ma.Multiaddr) *Dialer { | ||
d := NewDialer(localPeer, privKey, nil, streamMuxer) | ||
d.fallback = nil // unset the fallback dialer. We want tests use the configured dialer, and to fail otherwise | ||
tptd, err := getTransport(addr).Dialer(addr) | ||
Expect(err).ToNot(HaveOccurred()) | ||
d.AddDialer(tptd) | ||
return d | ||
} | ||
|
||
// randPeerNetParams works like testutil.RandPeerNetParams | ||
// if called for a multi-stream transport, it replaces the address with a QUIC address | ||
func randPeerNetParams() *tu.PeerNetParams { | ||
p, err := tu.RandPeerNetParams() | ||
Expect(err).ToNot(HaveOccurred()) | ||
return p | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
remote
is not""
, we should check ifremote == secSession.RemoteID()
here. That way, we do this before doing anything else. Currently, we check in swarm but, IMO, that's too late. Note: this is an improvement, not a bug.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do that in a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough.