Browse Source

migrate to consolidated types. (#62)

pull/1424/head
Raúl Kripalani 6 years ago
committed by GitHub
parent
commit
5a33a88caf
  1. 15
      p2p/transport/quic/conn.go
  2. 18
      p2p/transport/quic/conn_test.go
  3. 4
      p2p/transport/quic/crypto.go
  4. 11
      p2p/transport/quic/listener.go
  5. 5
      p2p/transport/quic/listener_test.go
  6. 5
      p2p/transport/quic/stream.go
  7. 9
      p2p/transport/quic/transport.go
  8. 2
      p2p/transport/quic/transport_test.go

15
p2p/transport/quic/conn.go

@ -1,10 +1,11 @@
package libp2pquic
import (
ic "github.com/libp2p/go-libp2p-crypto"
peer "github.com/libp2p/go-libp2p-peer"
tpt "github.com/libp2p/go-libp2p-transport"
smux "github.com/libp2p/go-stream-muxer"
ic "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/mux"
"github.com/libp2p/go-libp2p-core/peer"
tpt "github.com/libp2p/go-libp2p-core/transport"
quic "github.com/lucas-clemente/quic-go"
ma "github.com/multiformats/go-multiaddr"
)
@ -22,7 +23,7 @@ type conn struct {
remoteMultiaddr ma.Multiaddr
}
var _ tpt.Conn = &conn{}
var _ tpt.CapableConn = &conn{}
func (c *conn) Close() error {
return c.sess.Close()
@ -34,13 +35,13 @@ func (c *conn) IsClosed() bool {
}
// OpenStream creates a new stream.
func (c *conn) OpenStream() (smux.Stream, error) {
func (c *conn) OpenStream() (mux.MuxedStream, error) {
qstr, err := c.sess.OpenStreamSync()
return &stream{Stream: qstr}, err
}
// AcceptStream accepts a stream opened by the other side.
func (c *conn) AcceptStream() (smux.Stream, error) {
func (c *conn) AcceptStream() (mux.MuxedStream, error) {
qstr, err := c.sess.AcceptStream()
return &stream{Stream: qstr}, err
}

18
p2p/transport/quic/conn_test.go

@ -10,9 +10,9 @@ import (
"io/ioutil"
"time"
ic "github.com/libp2p/go-libp2p-crypto"
peer "github.com/libp2p/go-libp2p-peer"
tpt "github.com/libp2p/go-libp2p-transport"
ic "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
tpt "github.com/libp2p/go-libp2p-core/transport"
ma "github.com/multiformats/go-multiaddr"
. "github.com/onsi/ginkgo"
@ -35,9 +35,9 @@ var _ = Describe("Connection", func() {
return id, priv
}
runServer := func(tr tpt.Transport, multiaddr string) (ma.Multiaddr, <-chan tpt.Conn) {
runServer := func(tr tpt.Transport, multiaddr string) (ma.Multiaddr, <-chan tpt.CapableConn) {
addrChan := make(chan ma.Multiaddr)
connChan := make(chan tpt.Conn)
connChan := make(chan tpt.CapableConn)
go func() {
defer GinkgoRecover()
addr, err := ma.NewMultiaddr(multiaddr)
@ -204,8 +204,8 @@ var _ = Describe("Connection", func() {
// wait for both servers to accept a connection
// then send some data
go func() {
for _, c := range []tpt.Conn{<-serverConnChan, <-serverConnChan2} {
go func(conn tpt.Conn) {
for _, c := range []tpt.CapableConn{<-serverConnChan, <-serverConnChan2} {
go func(conn tpt.CapableConn) {
defer GinkgoRecover()
str, err := conn.OpenStream()
Expect(err).ToNot(HaveOccurred())
@ -225,8 +225,8 @@ var _ = Describe("Connection", func() {
done := make(chan struct{}, 2)
// receive the data on both connections at the same time
for _, c := range []tpt.Conn{c1, c2} {
go func(conn tpt.Conn) {
for _, c := range []tpt.CapableConn{c1, c2} {
go func(conn tpt.CapableConn) {
defer GinkgoRecover()
str, err := conn.AcceptStream()
Expect(err).ToNot(HaveOccurred())

4
p2p/transport/quic/crypto.go

@ -11,8 +11,8 @@ import (
"time"
"github.com/gogo/protobuf/proto"
ic "github.com/libp2p/go-libp2p-crypto"
pb "github.com/libp2p/go-libp2p-crypto/pb"
ic "github.com/libp2p/go-libp2p-core/crypto"
pb "github.com/libp2p/go-libp2p-core/crypto/pb"
)
// mint certificate selection is broken.

11
p2p/transport/quic/listener.go

@ -4,9 +4,10 @@ import (
"crypto/tls"
"net"
ic "github.com/libp2p/go-libp2p-crypto"
peer "github.com/libp2p/go-libp2p-peer"
tpt "github.com/libp2p/go-libp2p-transport"
ic "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
tpt "github.com/libp2p/go-libp2p-core/transport"
quic "github.com/lucas-clemente/quic-go"
ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr-net"
@ -57,7 +58,7 @@ func newListener(addr ma.Multiaddr, transport tpt.Transport, localPeer peer.ID,
}
// Accept accepts new connections.
func (l *listener) Accept() (tpt.Conn, error) {
func (l *listener) Accept() (tpt.CapableConn, error) {
for {
sess, err := l.quicListener.Accept()
if err != nil {
@ -72,7 +73,7 @@ func (l *listener) Accept() (tpt.Conn, error) {
}
}
func (l *listener) setupConn(sess quic.Session) (tpt.Conn, error) {
func (l *listener) setupConn(sess quic.Session) (tpt.CapableConn, error) {
remotePubKey, err := getRemotePubKey(sess.ConnectionState().PeerCertificates)
if err != nil {
return nil, err

5
p2p/transport/quic/listener_test.go

@ -7,8 +7,9 @@ import (
"fmt"
"net"
ic "github.com/libp2p/go-libp2p-crypto"
tpt "github.com/libp2p/go-libp2p-transport"
ic "github.com/libp2p/go-libp2p-core/crypto"
tpt "github.com/libp2p/go-libp2p-core/transport"
ma "github.com/multiformats/go-multiaddr"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

5
p2p/transport/quic/stream.go

@ -1,7 +1,8 @@
package libp2pquic
import (
smux "github.com/libp2p/go-stream-muxer"
"github.com/libp2p/go-libp2p-core/mux"
quic "github.com/lucas-clemente/quic-go"
)
@ -9,7 +10,7 @@ type stream struct {
quic.Stream
}
var _ smux.Stream = &stream{}
var _ mux.MuxedStream = &stream{}
func (s *stream) Reset() error {
s.Stream.CancelRead(0)

9
p2p/transport/quic/transport.go

@ -9,9 +9,10 @@ import (
"net"
"sync"
ic "github.com/libp2p/go-libp2p-crypto"
peer "github.com/libp2p/go-libp2p-peer"
tpt "github.com/libp2p/go-libp2p-transport"
ic "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
tpt "github.com/libp2p/go-libp2p-core/transport"
quic "github.com/lucas-clemente/quic-go"
ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr-net"
@ -99,7 +100,7 @@ func NewTransport(key ic.PrivKey) (tpt.Transport, error) {
}
// Dial dials a new QUIC connection
func (t *transport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (tpt.Conn, error) {
func (t *transport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (tpt.CapableConn, error) {
network, host, err := manet.DialArgs(raddr)
if err != nil {
return nil, err

2
p2p/transport/quic/transport_test.go

@ -1,7 +1,7 @@
package libp2pquic
import (
tpt "github.com/libp2p/go-libp2p-transport"
tpt "github.com/libp2p/go-libp2p-core/transport"
ma "github.com/multiformats/go-multiaddr"
. "github.com/onsi/ginkgo"

Loading…
Cancel
Save