@@ -40,6 +40,10 @@ import (
40
40
libp2pwebrtc "github.com/libp2p/go-libp2p/p2p/transport/webrtc"
41
41
"github.com/libp2p/go-libp2p/p2p/transport/websocket"
42
42
webtransport "github.com/libp2p/go-libp2p/p2p/transport/webtransport"
43
+ "github.com/libp2p/go-yamux/v5"
44
+ "github.com/pion/webrtc/v4"
45
+ quicgo "github.com/quic-go/quic-go"
46
+ wtgo "github.com/quic-go/webtransport-go"
43
47
"go.uber.org/goleak"
44
48
45
49
ma "github.com/multiformats/go-multiaddr"
@@ -842,3 +846,76 @@ func BenchmarkAllAddrs(b *testing.B) {
842
846
addrsHost .AllAddrs ()
843
847
}
844
848
}
849
+
850
+ func TestConnAs (t * testing.T ) {
851
+ type testCase struct {
852
+ name string
853
+ listenAddr string
854
+ testAs func (t * testing.T , c network.Conn )
855
+ }
856
+
857
+ testCases := []testCase {
858
+ {
859
+ "QUIC" ,
860
+ "/ip4/0.0.0.0/udp/0/quic-v1" ,
861
+ func (t * testing.T , c network.Conn ) {
862
+ var quicConn * quicgo.Conn
863
+ require .True (t , c .As (& quicConn ))
864
+ },
865
+ },
866
+ {
867
+ "TCP+Yamux" ,
868
+ "/ip4/0.0.0.0/tcp/0" ,
869
+ func (t * testing.T , c network.Conn ) {
870
+ var yamuxSession * yamux.Session
871
+ require .True (t , c .As (& yamuxSession ))
872
+ },
873
+ },
874
+ {
875
+ "WebRTC" ,
876
+ "/ip4/0.0.0.0/udp/0/webrtc-direct" ,
877
+ func (t * testing.T , c network.Conn ) {
878
+ var webrtcPC * webrtc.PeerConnection
879
+ require .True (t , c .As (& webrtcPC ))
880
+ },
881
+ },
882
+ {
883
+ "WebTransport Session" ,
884
+ "/ip4/0.0.0.0/udp/0/quic-v1/webtransport" ,
885
+ func (t * testing.T , c network.Conn ) {
886
+ var s * wtgo.Session
887
+ require .True (t , c .As (& s ))
888
+ },
889
+ },
890
+ {
891
+ "WebTransport QUIC Conn" ,
892
+ "/ip4/0.0.0.0/udp/0/quic-v1/webtransport" ,
893
+ func (t * testing.T , c network.Conn ) {
894
+ var quicConn * quicgo.Conn
895
+ require .True (t , c .As (& quicConn ))
896
+ },
897
+ },
898
+ }
899
+
900
+ for _ , tc := range testCases {
901
+ t .Run (tc .name , func (t * testing.T ) {
902
+ h1 , err := New (ListenAddrStrings (
903
+ tc .listenAddr ,
904
+ ))
905
+ require .NoError (t , err )
906
+ defer h1 .Close ()
907
+ h2 , err := New (ListenAddrStrings (
908
+ tc .listenAddr ,
909
+ ))
910
+ require .NoError (t , err )
911
+ defer h2 .Close ()
912
+ err = h1 .Connect (context .Background (), peer.AddrInfo {
913
+ ID : h2 .ID (),
914
+ Addrs : h2 .Addrs (),
915
+ })
916
+ require .NoError (t , err )
917
+ c := h1 .Network ().ConnsToPeer (h2 .ID ())[0 ]
918
+ tc .testAs (t , c )
919
+ })
920
+ }
921
+ }
0 commit comments