From 7d13adbf50569186b1552120737bd0fe7f3bceb8 Mon Sep 17 00:00:00 2001 From: aarshkshah1992 Date: Thu, 14 Jan 2021 14:22:55 +0530 Subject: [PATCH 01/10] support for forced direct connections draft 1 --- go.mod | 6 ++-- go.sum | 33 +++++++------------ swarm.go | 20 ++++++++++++ swarm_dial.go | 89 ++++++++++++++++++++++++++++++++++++--------------- 4 files changed, 98 insertions(+), 50 deletions(-) diff --git a/go.mod b/go.mod index aa8e2425..17bd2de5 100644 --- a/go.mod +++ b/go.mod @@ -6,12 +6,12 @@ require ( github.com/ipfs/go-log v1.0.4 github.com/jbenet/goprocess v0.1.4 github.com/libp2p/go-addr-util v0.0.2 - github.com/libp2p/go-conn-security-multistream v0.2.0 - github.com/libp2p/go-libp2p-core v0.8.0 + github.com/libp2p/go-conn-security-multistream v0.2.1-0.20210112083329-74b9d559ec02 + github.com/libp2p/go-libp2p-core v0.8.1-0.20210114083534-0fe5ddca3190 github.com/libp2p/go-libp2p-loggables v0.1.0 github.com/libp2p/go-libp2p-peerstore v0.2.6 github.com/libp2p/go-libp2p-testing v0.4.0 - github.com/libp2p/go-libp2p-transport-upgrader v0.4.0 + github.com/libp2p/go-libp2p-transport-upgrader v0.4.1-0.20210112104805-7891e47ff469 github.com/libp2p/go-libp2p-yamux v0.5.0 github.com/libp2p/go-stream-muxer-multistream v0.3.0 github.com/libp2p/go-tcp-transport v0.2.0 diff --git a/go.sum b/go.sum index 9a09c73f..1b79fafe 100644 --- a/go.sum +++ b/go.sum @@ -75,7 +75,6 @@ github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUP github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= github.com/ipfs/go-cid v0.0.4/go.mod h1:4LLaPOQwmk5z9LBgQnpkivrx8BJjUyGwTXCd5Xfj6+M= -github.com/ipfs/go-cid v0.0.5 h1:o0Ix8e/ql7Zb5UVUJEUfjsWCIY8t48++9lR8qi6oiJU= github.com/ipfs/go-cid v0.0.5/go.mod h1:plgt+Y5MnOey4vO4UlUazGqdbEXuFYitED67FexhXog= github.com/ipfs/go-cid v0.0.7 h1:ysQJVJA3fNDF1qigJbsSQOdjhVLsOEoPdh0+R97k3jY= github.com/ipfs/go-cid v0.0.7/go.mod h1:6Ux9z5e+HpkQdckYoX1PG/6xqKspzlEIR5SDmgqgC/I= @@ -125,6 +124,8 @@ github.com/libp2p/go-buffer-pool v0.0.2 h1:QNK2iAFa8gjAe1SPz6mHSMuCcjs+X1wlHzeOS github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM= github.com/libp2p/go-conn-security-multistream v0.2.0 h1:uNiDjS58vrvJTg9jO6bySd1rMKejieG7v45ekqHbZ1M= github.com/libp2p/go-conn-security-multistream v0.2.0/go.mod h1:hZN4MjlNetKD3Rq5Jb/P5ohUnFLNzEAR4DLSzpn2QLU= +github.com/libp2p/go-conn-security-multistream v0.2.1-0.20210112083329-74b9d559ec02 h1:/JM8SVfpzFsDxcoAZhUoT+09WU/NWSjK24nEcP7qeyg= +github.com/libp2p/go-conn-security-multistream v0.2.1-0.20210112083329-74b9d559ec02/go.mod h1:zRhNQyRkfE8Q5V6Addrw7UK/R0boRxUUx+xfF9jHBak= github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8= github.com/libp2p/go-flow-metrics v0.0.3 h1:8tAs/hSdNvUiLgtlSy3mxwxWP4I9y/jlkPFT7epKdeM= github.com/libp2p/go-flow-metrics v0.0.3/go.mod h1:HeoSNUrOJVK1jEpDqVEiUOIXqhbnS27omG0uWU5slZs= @@ -135,16 +136,16 @@ github.com/libp2p/go-libp2p-core v0.3.1/go.mod h1:thvWy0hvaSBhnVBaW37BvzgVV68OUh github.com/libp2p/go-libp2p-core v0.5.0/go.mod h1:49XGI+kc38oGVwqSBhDEwytaAxgZasHhFfQKibzTls0= github.com/libp2p/go-libp2p-core v0.5.1/go.mod h1:uN7L2D4EvPCvzSH5SrhR72UWbnSGpt5/a35Sm4upn4Y= github.com/libp2p/go-libp2p-core v0.5.4/go.mod h1:uN7L2D4EvPCvzSH5SrhR72UWbnSGpt5/a35Sm4upn4Y= -github.com/libp2p/go-libp2p-core v0.5.5/go.mod h1:vj3awlOr9+GMZJFH9s4mpt9RHHgGqeHCopzbYKZdRjM= -github.com/libp2p/go-libp2p-core v0.7.0 h1:4a0TMjrWNTZlNvcqxZmrMRDi/NQWrhwO2pkTuLSQ/IQ= -github.com/libp2p/go-libp2p-core v0.7.0/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8= -github.com/libp2p/go-libp2p-core v0.8.0 h1:5K3mT+64qDTKbV3yTdbMCzJ7O6wbNsavAEb8iqBvBcI= github.com/libp2p/go-libp2p-core v0.8.0/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8= +github.com/libp2p/go-libp2p-core v0.8.1-0.20210112053000-24d7f19910e4/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8= +github.com/libp2p/go-libp2p-core v0.8.1-0.20210114083534-0fe5ddca3190 h1:GTpRJA3bjJrlhT/c6MzRYoCc9fZIWTRaJvhLLuv+JqY= +github.com/libp2p/go-libp2p-core v0.8.1-0.20210114083534-0fe5ddca3190/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8= github.com/libp2p/go-libp2p-loggables v0.1.0 h1:h3w8QFfCt2UJl/0/NW4K829HX/0S4KD31PQ7m8UXXO8= github.com/libp2p/go-libp2p-loggables v0.1.0/go.mod h1:EyumB2Y6PrYjr55Q3/tiJ/o3xoDasoRYM7nOzEpoa90= github.com/libp2p/go-libp2p-mplex v0.2.1/go.mod h1:SC99Rxs8Vuzrf/6WhmH41kNn13TiYdAWNYHrwImKLnE= github.com/libp2p/go-libp2p-mplex v0.2.3 h1:2zijwaJvpdesST2MXpI5w9wWFRgYtMcpRX7rrw0jmOo= github.com/libp2p/go-libp2p-mplex v0.2.3/go.mod h1:CK3p2+9qH9x+7ER/gWWDYJ3QW5ZxWDkm+dVvjfuG3ek= +github.com/libp2p/go-libp2p-mplex v0.4.0 h1:ukojv97fEBM3ffCqXuuve2WSHu1HsA4/omMk1h2KFgc= github.com/libp2p/go-libp2p-mplex v0.4.0/go.mod h1:yCyWJE2sc6TBTnFpjvLuEJgTSw/u+MamvzILKdX7asw= github.com/libp2p/go-libp2p-peerstore v0.2.6 h1:2ACefBX23iMdJU9Ke+dcXt3w86MIryes9v7In4+Qq3U= github.com/libp2p/go-libp2p-peerstore v0.2.6/go.mod h1:ss/TWTgHZTMpsU/oKVVPQCGuDHItOpf2W8RxAi50P2s= @@ -154,17 +155,13 @@ github.com/libp2p/go-libp2p-testing v0.0.3/go.mod h1:gvchhf3FQOtBdr+eFUABet5a4MB github.com/libp2p/go-libp2p-testing v0.1.1 h1:U03z3HnGI7Ni8Xx6ONVZvUFOAzWYmolWf5W5jAOPNmU= github.com/libp2p/go-libp2p-testing v0.1.1/go.mod h1:xaZWMJrPUM5GlDBxCeGUi7kI4eqnjVyavGroI2nxEM0= github.com/libp2p/go-libp2p-testing v0.1.2-0.20200422005655-8775583591d8/go.mod h1:Qy8sAncLKpwXtS2dSnDOP8ktexIAHKu+J+pnZOFZLTc= -github.com/libp2p/go-libp2p-testing v0.3.0 h1:ZiBYstPamsi7y6NJZebRudUzsYmVkt998hltyLqf8+g= -github.com/libp2p/go-libp2p-testing v0.3.0/go.mod h1:efZkql4UZ7OVsEfaxNHZPzIehtsBXMrXnCfJIgDti5g= github.com/libp2p/go-libp2p-testing v0.4.0 h1:PrwHRi0IGqOwVQWR3xzgigSlhlLfxgfXgkHxr77EghQ= github.com/libp2p/go-libp2p-testing v0.4.0/go.mod h1:Q+PFXYoiYFN5CAEG2w3gLPEzotlKsNSbKQ/lImlOWF0= github.com/libp2p/go-libp2p-transport-upgrader v0.2.0/go.mod h1:mQcrHj4asu6ArfSoMuyojOdjx73Q47cYD7s5+gZOlns= -github.com/libp2p/go-libp2p-transport-upgrader v0.3.0 h1:q3ULhsknEQ34eVDhv4YwKS8iet69ffs9+Fir6a7weN4= -github.com/libp2p/go-libp2p-transport-upgrader v0.3.0/go.mod h1:i+SKzbRnvXdVbU3D1dwydnTmKRPXiAR/fyvi1dXuL4o= github.com/libp2p/go-libp2p-transport-upgrader v0.4.0 h1:xwj4h3hJdBrxqMOyMUjwscjoVst0AASTsKtZiTChoHI= github.com/libp2p/go-libp2p-transport-upgrader v0.4.0/go.mod h1:J4ko0ObtZSmgn5BX5AmegP+dK3CSnU2lMCKsSq/EY0s= -github.com/libp2p/go-libp2p-yamux v0.4.0 h1:qunEZzWwwmfSBYTtSyd81PlD1TjB5uuWcGYHWVXLbUg= -github.com/libp2p/go-libp2p-yamux v0.4.0/go.mod h1:+DWDjtFMzoAwYLVkNZftoucn7PelNoy5nm3tZ3/Zw30= +github.com/libp2p/go-libp2p-transport-upgrader v0.4.1-0.20210112104805-7891e47ff469 h1:3p3Bqcvv7igAa9FSN38sW2Et5A2eR93Lz0rzjk11TeA= +github.com/libp2p/go-libp2p-transport-upgrader v0.4.1-0.20210112104805-7891e47ff469/go.mod h1:FoWFx/dYdB8sZlKpy1esiHefLt5D2XyhtVPg3KxvtIE= github.com/libp2p/go-libp2p-yamux v0.5.0 h1:ZzmUhbQE+X7NuYUT2naxN31JyebZfRmpZVhKtRP13ys= github.com/libp2p/go-libp2p-yamux v0.5.0/go.mod h1:AyR8k5EzyM2QN9Bbdg6X1SkVVuqLwTGf0L4DFq9g6po= github.com/libp2p/go-maddr-filter v0.0.5/go.mod h1:Jk+36PMfIqCJhAnaASRH83bdAvfDRp/w6ENFaC9bG+M= @@ -172,16 +169,14 @@ github.com/libp2p/go-maddr-filter v0.1.0/go.mod h1:VzZhTXkMucEGGEOSKddrwGiOv0tUh github.com/libp2p/go-mplex v0.1.0/go.mod h1:SXgmdki2kwCUlCCbfGLEgHjC4pFqhTp0ZoV6aiKgxDU= github.com/libp2p/go-mplex v0.1.2 h1:qOg1s+WdGLlpkrczDqmhYzyk3vCfsQ8+RxRTQjOZWwI= github.com/libp2p/go-mplex v0.1.2/go.mod h1:Xgz2RDCi3co0LeZfgjm4OgUF15+sVR8SRcu3SFXI1lk= +github.com/libp2p/go-mplex v0.2.0 h1:Ov/D+8oBlbRkjBs1R1Iua8hJ8cUfbdiW8EOdZuxcgaI= github.com/libp2p/go-mplex v0.2.0/go.mod h1:0Oy/A9PQlwBytDRp4wSkFnzHYDKcpLot35JQ6msjvYQ= -github.com/libp2p/go-msgio v0.0.4 h1:agEFehY3zWJFUHK6SEMR7UYmk2z6kC3oeCM7ybLhguA= github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= github.com/libp2p/go-msgio v0.0.6 h1:lQ7Uc0kS1wb1EfRxO2Eir/RJoHkHn7t6o+EiwsYIKJA= github.com/libp2p/go-msgio v0.0.6/go.mod h1:4ecVB6d9f4BDSL5fqvPiC4A3KivjWn+Venn/1ALLMWA= github.com/libp2p/go-netroute v0.1.2 h1:UHhB35chwgvcRI392znJA3RCBtZ3MpE3ahNCN5MR4Xg= github.com/libp2p/go-netroute v0.1.2/go.mod h1:jZLDV+1PE8y5XxBySEBgbuVAXbhtuHSdmLPL2n9MKbk= github.com/libp2p/go-openssl v0.0.4/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc= -github.com/libp2p/go-openssl v0.0.5 h1:pQkejVhF0xp08D4CQUcw8t+BFJeXowja6RVcb5p++EA= -github.com/libp2p/go-openssl v0.0.5/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc= github.com/libp2p/go-openssl v0.0.7 h1:eCAzdLejcNVBzP/iZM9vqHnQm+XyCEbSSIheIPRGNsw= github.com/libp2p/go-openssl v0.0.7/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc= github.com/libp2p/go-reuseport v0.0.1 h1:7PhkfH73VXfPJYKQ6JwS5I/eVcoyYi9IMNGc6FWpFLw= @@ -194,8 +189,6 @@ github.com/libp2p/go-stream-muxer-multistream v0.3.0 h1:TqnSHPJEIqDEO7h1wZZ0p3DX github.com/libp2p/go-stream-muxer-multistream v0.3.0/go.mod h1:yDh8abSIzmZtqtOt64gFJUXEryejzNb0lisTt+fAMJA= github.com/libp2p/go-tcp-transport v0.2.0 h1:YoThc549fzmNJIh7XjHVtMIFaEDRtIrtWciG5LyYAPo= github.com/libp2p/go-tcp-transport v0.2.0/go.mod h1:vX2U0CnWimU4h0SGSEsg++AzvBcroCGYw28kh94oLe0= -github.com/libp2p/go-yamux v1.4.0 h1:7nqe0T95T2CWh40IdJ/tp8RMor4ubc9/wYZpB2a/Hx0= -github.com/libp2p/go-yamux v1.4.0/go.mod h1:fr7aVgmdNGJK+N1g+b6DW6VxzbRCjCOejR/hkmpooHE= github.com/libp2p/go-yamux v1.4.1 h1:P1Fe9vF4th5JOxxgQvfbOHkrGqIZniTLf+ddhZp8YTI= github.com/libp2p/go-yamux v1.4.1/go.mod h1:fr7aVgmdNGJK+N1g+b6DW6VxzbRCjCOejR/hkmpooHE= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= @@ -242,11 +235,8 @@ github.com/multiformats/go-multiaddr-fmt v0.1.0/go.mod h1:hGtDIW4PU4BqJ50gW2quDu github.com/multiformats/go-multiaddr-net v0.1.2/go.mod h1:QsWt3XK/3hwvNxZJp92iMQKME1qHfpYmyIjFVsSOY6Y= github.com/multiformats/go-multiaddr-net v0.1.3/go.mod h1:ilNnaM9HbmVFqsb/qcNysjCu4PVONlrBZpHIrw/qQuA= github.com/multiformats/go-multiaddr-net v0.1.4/go.mod h1:ilNnaM9HbmVFqsb/qcNysjCu4PVONlrBZpHIrw/qQuA= -github.com/multiformats/go-multiaddr-net v0.1.5 h1:QoRKvu0xHN1FCFJcMQLbG/yQE2z441L5urvG3+qyz7g= -github.com/multiformats/go-multiaddr-net v0.1.5/go.mod h1:ilNnaM9HbmVFqsb/qcNysjCu4PVONlrBZpHIrw/qQuA= github.com/multiformats/go-multiaddr-net v0.2.0 h1:MSXRGN0mFymt6B1yo/6BPnIRpLPEnKgQNvVfCX5VDJk= github.com/multiformats/go-multiaddr-net v0.2.0/go.mod h1:gGdH3UXny6U3cKKYCvpXI5rnK7YaOIEOPVDI9tsJbEA= -github.com/multiformats/go-multibase v0.0.1 h1:PN9/v21eLywrFWdFNsFKaU04kLJzuYzmrJR+ubhT9qA= github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multibase v0.0.3 h1:l/B6bJDQjvQ5G52jw4QGSYeOTZoAwIO77RblWplfIqk= github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc= @@ -260,6 +250,8 @@ github.com/multiformats/go-multihash v0.0.14 h1:QoBceQYQQtNUuf6s7wHxnE2c8bhbMqhf github.com/multiformats/go-multihash v0.0.14/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc= github.com/multiformats/go-multistream v0.1.1 h1:JlAdpIFhBhGRLxe9W6Om0w++Gd6KMWoFPZL/dEnm9nI= github.com/multiformats/go-multistream v0.1.1/go.mod h1:KmHZ40hzVxiaiwlj3MEbYgK9JFk2/9UktWZAF54Du38= +github.com/multiformats/go-multistream v0.2.1-0.20210112051459-b087b1b3f480 h1:iIVA/uN5zlJ9IQrm3GRhRNgkp7OB7i5/igTXGfzN+vM= +github.com/multiformats/go-multistream v0.2.1-0.20210112051459-b087b1b3f480/go.mod h1:5GZPQZbkWOLOn3J2y4Y99vVW7vOfsAflxARk3x14o6k= github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiformats/go-varint v0.0.2/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiformats/go-varint v0.0.5 h1:XVZwSo04Cs3j/jS0uAEPpT3JY6DzMcVLLoWOSnCxOjg= @@ -303,7 +295,6 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/src-d/envconfig v1.0.0/go.mod h1:Q9YQZ7BKITldTBnoxsE5gOeB5y66RyPXeue/R4aaNBc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -320,7 +311,6 @@ github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7V github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.3 h1:8sGtKOrtQqkN1bp2AtX+misvLIlOmsEsNd+9NIcPEm8= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4 h1:LYy1Hy3MJdrCdMwwzxA/dRok4ejH+RwNGbuoD9fCjto= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -337,6 +327,7 @@ go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9E go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.14.1 h1:nYDKopTbvAPq/NrUVZwT15y2lpROBiLLyoRTbXOYWOo= go.uber.org/zap v1.14.1/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= +go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM= go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= diff --git a/swarm.go b/swarm.go index 8f0e18e5..a77de939 100644 --- a/swarm.go +++ b/swarm.go @@ -334,6 +334,7 @@ func (s *Swarm) NewStream(ctx context.Context, p peer.ID) (network.Stream, error // a non-closed connection. dials := 0 for { + // TODO How would this work with forece direct ? c := s.bestConnToPeer(p) if c == nil { if nodial, _ := network.GetNoDial(ctx); nodial { @@ -404,6 +405,25 @@ func (s *Swarm) bestConnToPeer(p peer.ID) *Conn { return best } +// directConnectionToPeer returns a direct non proxied connection to the peer if one exists. +func (s *Swarm) directConnectionToPeer(p peer.ID) *Conn { + s.conns.RLock() + defer s.conns.RUnlock() + + for _, c := range s.conns.m[p] { + if c.conn.IsClosed() { + // We *will* garbage collect this soon anyways. + continue + } + + if !c.conn.Transport().Proxy() { + return c + } + } + + return nil +} + // Connectedness returns our "connectedness" state with the given peer. // // To check if we have an open connection, use `s.Connectedness(p) == diff --git a/swarm_dial.go b/swarm_dial.go index 4dbb1f2d..278ad7e6 100644 --- a/swarm_dial.go +++ b/swarm_dial.go @@ -251,17 +251,25 @@ func (s *Swarm) dialPeer(ctx context.Context, p peer.ID) (*Conn, error) { defer log.EventBegin(ctx, "swarmDialAttemptSync", p).Done() - // check if we already have an open connection first - conn := s.bestConnToPeer(p) - if conn != nil { - return conn, nil + forceDirect, _ := network.GetForceDirectDial(ctx) + if forceDirect { + conn := s.directConnectionToPeer(p) + if conn != nil { + return conn, nil + } + } else { + // check if we already have an open connection first + conn := s.bestConnToPeer(p) + if conn != nil { + return conn, nil + } } // apply the DialPeer timeout ctx, cancel := context.WithTimeout(ctx, network.GetDialPeerTimeout(ctx)) defer cancel() - conn, err = s.dsync.DialLock(ctx, p) + conn, err := s.dsync.DialLock(ctx, p) if err == nil { return conn, nil } @@ -287,9 +295,17 @@ func (s *Swarm) doDial(ctx context.Context, p peer.ID) (*Conn, error) { // Short circuit. // By the time we take the dial lock, we may already *have* a connection // to the peer. - c := s.bestConnToPeer(p) - if c != nil { - return c, nil + forceDirect, _ := network.GetForceDirectDial(ctx) + if forceDirect { + c := s.directConnectionToPeer(p) + if c != nil { + return c, nil + } + } else { + c := s.bestConnToPeer(p) + if c != nil { + return c, nil + } } logdial := lgbl.Dial("swarm", s.LocalPeer(), p, nil, nil) @@ -300,16 +316,23 @@ func (s *Swarm) doDial(ctx context.Context, p peer.ID) (*Conn, error) { conn, err := s.dial(ctx, p) if err != nil { - conn = s.bestConnToPeer(p) - if conn != nil { - // Hm? What error? - // Could have canceled the dial because we received a - // connection or some other random reason. - // Just ignore the error and return the connection. - log.Debugf("ignoring dial error because we have a connection: %s", err) - return conn, nil + if forceDirect { + conn = s.directConnectionToPeer(p) + if conn != nil { + log.Debugf("ignoring dial error because we have a connection: %s", err) + return conn, nil + } + } else { + conn = s.bestConnToPeer(p) + if conn != nil { + // Hm? What error? + // Could have canceled the dial because we received a + // connection or some other random reason. + // Just ignore the error and return the connection. + log.Debugf("ignoring dial error because we have a connection: %s", err) + return conn, nil + } } - // ok, we failed. return nil, err } @@ -321,8 +344,14 @@ func (s *Swarm) canDial(addr ma.Multiaddr) bool { return t != nil && t.CanDial(addr) } +func (s *Swarm) nonProxyAddr(addr ma.Multiaddr) bool { + t := s.TransportForDialing(addr) + return !t.Proxy() +} + // dial is the actual swarm's dial logic, gated by Dial. func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) { + forceDirect, _ := network.GetForceDirectDial(ctx) var logdial = lgbl.Dial("swarm", s.LocalPeer(), p, nil, nil) if p == s.local { log.Event(ctx, "swarmDialDoDialSelf", logdial) @@ -347,17 +376,25 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) { if len(goodAddrs) == 0 { return nil, &DialError{Peer: p, Cause: ErrNoGoodAddresses} } + // TODO Considering dialing private addresses as well + // See https://github.com/libp2p/specs/pull/173/files#r288784559 + if forceDirect { + goodAddrs = addrutil.FilterAddrs(goodAddrs, s.nonProxyAddr, manet.IsPublicAddr) + } - /////// Check backoff andnRank addresses - var nonBackoff bool - for _, a := range goodAddrs { - // skip addresses in back-off - if !s.backf.Backoff(p, a) { - nonBackoff = true + // TODO How do we do backoff for forcedirect + if !forceDirect { + /////// Check backoff andnRank addresses + var nonBackoff bool + for _, a := range goodAddrs { + // skip addresses in back-off + if !s.backf.Backoff(p, a) { + nonBackoff = true + } + } + if !nonBackoff { + return nil, ErrDialBackoff } - } - if !nonBackoff { - return nil, ErrDialBackoff } // ranks addresses in descending order of preference for dialing From 59a5292639101fcb7ad76233c370582d2fd016df Mon Sep 17 00:00:00 2001 From: aarshkshah1992 Date: Thu, 14 Jan 2021 15:01:54 +0530 Subject: [PATCH 02/10] open streams over direct connections --- swarm.go | 7 +++++-- swarm_dial.go | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/swarm.go b/swarm.go index a77de939..d7a1f7d6 100644 --- a/swarm.go +++ b/swarm.go @@ -334,8 +334,11 @@ func (s *Swarm) NewStream(ctx context.Context, p peer.ID) (network.Stream, error // a non-closed connection. dials := 0 for { - // TODO How would this work with forece direct ? - c := s.bestConnToPeer(p) + // if we have a direct connection to the peer, open the stream over it rather than using a proxied connection. + c := s.directConnectionToPeer(p) + if c == nil { + c = s.bestConnToPeer(p) + } if c == nil { if nodial, _ := network.GetNoDial(ctx); nodial { return nil, network.ErrNoConn diff --git a/swarm_dial.go b/swarm_dial.go index 278ad7e6..4eec238b 100644 --- a/swarm_dial.go +++ b/swarm_dial.go @@ -373,14 +373,14 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) { return nil, &DialError{Peer: p, Cause: ErrNoAddresses} } goodAddrs := s.filterKnownUndialables(p, peerAddrs) - if len(goodAddrs) == 0 { - return nil, &DialError{Peer: p, Cause: ErrNoGoodAddresses} - } // TODO Considering dialing private addresses as well // See https://github.com/libp2p/specs/pull/173/files#r288784559 if forceDirect { goodAddrs = addrutil.FilterAddrs(goodAddrs, s.nonProxyAddr, manet.IsPublicAddr) } + if len(goodAddrs) == 0 { + return nil, &DialError{Peer: p, Cause: ErrNoGoodAddresses} + } // TODO How do we do backoff for forcedirect if !forceDirect { From db3134d2609a293155c63bdc291b5c465b810136 Mon Sep 17 00:00:00 2001 From: aarshkshah1992 Date: Thu, 14 Jan 2021 15:41:02 +0530 Subject: [PATCH 03/10] update ctx and docs --- dial_sync.go | 6 +++--- swarm_dial.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dial_sync.go b/dial_sync.go index 4c1230f5..edb6c898 100644 --- a/dial_sync.go +++ b/dial_sync.go @@ -96,13 +96,13 @@ func (ad *activeDial) start(ctx context.Context) { ad.cancel() } -func (ds *DialSync) getActiveDial(p peer.ID) *activeDial { +func (ds *DialSync) getActiveDial(ctx context.Context, p peer.ID) *activeDial { ds.dialsLk.Lock() defer ds.dialsLk.Unlock() actd, ok := ds.dials[p] if !ok { - adctx, cancel := context.WithCancel(context.Background()) + adctx, cancel := context.WithCancel(ctx) actd = &activeDial{ id: p, cancel: cancel, @@ -123,7 +123,7 @@ func (ds *DialSync) getActiveDial(p peer.ID) *activeDial { // DialLock initiates a dial to the given peer if there are none in progress // then waits for the dial to that peer to complete. func (ds *DialSync) DialLock(ctx context.Context, p peer.ID) (*Conn, error) { - return ds.getActiveDial(p).wait(ctx) + return ds.getActiveDial(ctx, p).wait(ctx) } // CancelDial cancels all in-progress dials to the given peer. diff --git a/swarm_dial.go b/swarm_dial.go index 4eec238b..1d5ec01c 100644 --- a/swarm_dial.go +++ b/swarm_dial.go @@ -373,10 +373,10 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) { return nil, &DialError{Peer: p, Cause: ErrNoAddresses} } goodAddrs := s.filterKnownUndialables(p, peerAddrs) - // TODO Considering dialing private addresses as well + // TODO Consider NOT dialing private addresses as well // See https://github.com/libp2p/specs/pull/173/files#r288784559 if forceDirect { - goodAddrs = addrutil.FilterAddrs(goodAddrs, s.nonProxyAddr, manet.IsPublicAddr) + goodAddrs = addrutil.FilterAddrs(goodAddrs, s.nonProxyAddr) } if len(goodAddrs) == 0 { return nil, &DialError{Peer: p, Cause: ErrNoGoodAddresses} From 979b039460cf0a70ca2a922b959bab33d126e842 Mon Sep 17 00:00:00 2001 From: aarshkshah1992 Date: Fri, 15 Jan 2021 10:29:08 +0530 Subject: [PATCH 04/10] do not dial private addrs for hole punching --- swarm_dial.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/swarm_dial.go b/swarm_dial.go index 1d5ec01c..69da503b 100644 --- a/swarm_dial.go +++ b/swarm_dial.go @@ -373,10 +373,10 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) { return nil, &DialError{Peer: p, Cause: ErrNoAddresses} } goodAddrs := s.filterKnownUndialables(p, peerAddrs) - // TODO Consider NOT dialing private addresses as well + // TODO Consider dialing private addresses as well // See https://github.com/libp2p/specs/pull/173/files#r288784559 if forceDirect { - goodAddrs = addrutil.FilterAddrs(goodAddrs, s.nonProxyAddr) + goodAddrs = addrutil.FilterAddrs(goodAddrs, manet.IsPublicAddr, s.nonProxyAddr) } if len(goodAddrs) == 0 { return nil, &DialError{Peer: p, Cause: ErrNoGoodAddresses} @@ -554,7 +554,6 @@ dialLoop: remoteAddrChan = nil continue } - s.limitedDial(ctx, p, addr, respch) active++ case <-ctx.Done(): From fca9031125efdeb804e0a83059646fa89c3f76f2 Mon Sep 17 00:00:00 2001 From: aarshkshah1992 Date: Tue, 19 Jan 2021 14:36:47 +0530 Subject: [PATCH 05/10] force direct connections --- swarm.go | 52 ++++++++++++++++++++++++--------------------------- swarm_dial.go | 45 ++++++++++++++++++-------------------------- 2 files changed, 42 insertions(+), 55 deletions(-) diff --git a/swarm.go b/swarm.go index d7a1f7d6..00e847e7 100644 --- a/swarm.go +++ b/swarm.go @@ -334,11 +334,8 @@ func (s *Swarm) NewStream(ctx context.Context, p peer.ID) (network.Stream, error // a non-closed connection. dials := 0 for { - // if we have a direct connection to the peer, open the stream over it rather than using a proxied connection. - c := s.directConnectionToPeer(p) - if c == nil { - c = s.bestConnToPeer(p) - } + // will prefer direct connections over relayed connections for opening streams + c := s.bestConnToPeer(p) if c == nil { if nodial, _ := network.GetNoDial(ctx); nodial { return nil, network.ErrNoConn @@ -382,9 +379,10 @@ func (s *Swarm) ConnsToPeer(p peer.ID) []network.Conn { // bestConnToPeer returns the best connection to peer. func (s *Swarm) bestConnToPeer(p peer.ID) *Conn { + // Selects the best connection we have to the peer. - // TODO: Prefer some transports over others. Currently, we just select - // the newest non-closed connection with the most streams. + // Prefers direct connections over Relayed connections. + // For tie-breaking, select the newest non-closed connection with the most streams. s.conns.RLock() defer s.conns.RUnlock() @@ -399,32 +397,30 @@ func (s *Swarm) bestConnToPeer(p peer.ID) *Conn { cLen := len(c.streams.m) c.streams.Unlock() - if cLen >= bestLen { - best = c - bestLen = cLen + if isDirectConn(best) { + // Since the best connection we have till now is a direct connection, + // we will ONLY replace it with a direct connection + if !isDirectConn(c) { + continue + } + if cLen >= bestLen { + best = c + bestLen = cLen + } + } else { + // Since the best connection we have till now is a Relayed connection, + // we will simply replace with a newer connection if it has atleast as many streams. + if cLen >= bestLen { + best = c + bestLen = cLen + } } - } return best } -// directConnectionToPeer returns a direct non proxied connection to the peer if one exists. -func (s *Swarm) directConnectionToPeer(p peer.ID) *Conn { - s.conns.RLock() - defer s.conns.RUnlock() - - for _, c := range s.conns.m[p] { - if c.conn.IsClosed() { - // We *will* garbage collect this soon anyways. - continue - } - - if !c.conn.Transport().Proxy() { - return c - } - } - - return nil +func isDirectConn(c *Conn) bool { + return c != nil && !c.conn.Transport().Proxy() } // Connectedness returns our "connectedness" state with the given peer. diff --git a/swarm_dial.go b/swarm_dial.go index 69da503b..34e73400 100644 --- a/swarm_dial.go +++ b/swarm_dial.go @@ -251,25 +251,22 @@ func (s *Swarm) dialPeer(ctx context.Context, p peer.ID) (*Conn, error) { defer log.EventBegin(ctx, "swarmDialAttemptSync", p).Done() + conn := s.bestConnToPeer(p) forceDirect, _ := network.GetForceDirectDial(ctx) if forceDirect { - conn := s.directConnectionToPeer(p) - if conn != nil { + if isDirectConn(conn) { return conn, nil } - } else { + } else if conn != nil { // check if we already have an open connection first - conn := s.bestConnToPeer(p) - if conn != nil { - return conn, nil - } + return conn, nil } // apply the DialPeer timeout ctx, cancel := context.WithTimeout(ctx, network.GetDialPeerTimeout(ctx)) defer cancel() - conn, err := s.dsync.DialLock(ctx, p) + conn, err = s.dsync.DialLock(ctx, p) if err == nil { return conn, nil } @@ -296,16 +293,13 @@ func (s *Swarm) doDial(ctx context.Context, p peer.ID) (*Conn, error) { // By the time we take the dial lock, we may already *have* a connection // to the peer. forceDirect, _ := network.GetForceDirectDial(ctx) + c := s.bestConnToPeer(p) if forceDirect { - c := s.directConnectionToPeer(p) - if c != nil { - return c, nil - } - } else { - c := s.bestConnToPeer(p) - if c != nil { + if isDirectConn(c) { return c, nil } + } else if c != nil { + return c, nil } logdial := lgbl.Dial("swarm", s.LocalPeer(), p, nil, nil) @@ -316,22 +310,19 @@ func (s *Swarm) doDial(ctx context.Context, p peer.ID) (*Conn, error) { conn, err := s.dial(ctx, p) if err != nil { + conn = s.bestConnToPeer(p) if forceDirect { - conn = s.directConnectionToPeer(p) - if conn != nil { - log.Debugf("ignoring dial error because we have a connection: %s", err) - return conn, nil - } - } else { - conn = s.bestConnToPeer(p) - if conn != nil { - // Hm? What error? - // Could have canceled the dial because we received a - // connection or some other random reason. - // Just ignore the error and return the connection. + if isDirectConn(conn) { log.Debugf("ignoring dial error because we have a connection: %s", err) return conn, nil } + } else if conn != nil { + // Hm? What error? + // Could have canceled the dial because we received a + // connection or some other random reason. + // Just ignore the error and return the connection. + log.Debugf("ignoring dial error because we have a connection: %s", err) + return conn, nil } // ok, we failed. return nil, err From 3c217118fc8b1c6b77481c293c8199adae28cfee Mon Sep 17 00:00:00 2001 From: aarshkshah1992 Date: Wed, 17 Feb 2021 14:16:47 +0530 Subject: [PATCH 06/10] fmt --- swarm_dial.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/swarm_dial.go b/swarm_dial.go index 2a6cf8ba..c1e1cfff 100644 --- a/swarm_dial.go +++ b/swarm_dial.go @@ -335,11 +335,10 @@ func (s *Swarm) canDial(addr ma.Multiaddr) bool { return t != nil && t.CanDial(addr) } - func (s *Swarm) nonProxyAddr(addr ma.Multiaddr) bool { t := s.TransportForDialing(addr) return !t.Proxy() -} +} // ranks addresses in descending order of preference for dialing // Private UDP > Public UDP > Private TCP > Public TCP > UDP Relay server > TCP Relay server From b55ba31fa9d703989df892e9027bbeb9bcbc1fe5 Mon Sep 17 00:00:00 2001 From: aarshkshah1992 Date: Thu, 18 Feb 2021 10:45:11 +0530 Subject: [PATCH 07/10] address review --- swarm.go | 34 ++++++++++++++-------------------- swarm_dial.go | 4 +--- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/swarm.go b/swarm.go index 00e847e7..821af12c 100644 --- a/swarm.go +++ b/swarm.go @@ -380,15 +380,16 @@ func (s *Swarm) ConnsToPeer(p peer.ID) []network.Conn { // bestConnToPeer returns the best connection to peer. func (s *Swarm) bestConnToPeer(p peer.ID) *Conn { - // Selects the best connection we have to the peer. - // Prefers direct connections over Relayed connections. + // TODO: Prefer some transports over others. + // For now, prefers direct connections over Relayed connections. // For tie-breaking, select the newest non-closed connection with the most streams. s.conns.RLock() defer s.conns.RUnlock() var best *Conn bestLen := 0 - for _, c := range s.conns.m[p] { + for i := range s.conns.m[p] { + c := s.conns.m[p][i] if c.conn.IsClosed() { // We *will* garbage collect this soon anyways. continue @@ -397,23 +398,16 @@ func (s *Swarm) bestConnToPeer(p peer.ID) *Conn { cLen := len(c.streams.m) c.streams.Unlock() - if isDirectConn(best) { - // Since the best connection we have till now is a direct connection, - // we will ONLY replace it with a direct connection - if !isDirectConn(c) { - continue - } - if cLen >= bestLen { - best = c - bestLen = cLen - } - } else { - // Since the best connection we have till now is a Relayed connection, - // we will simply replace with a newer connection if it has atleast as many streams. - if cLen >= bestLen { - best = c - bestLen = cLen - } + // We will never prefer a Relayed connection over a direct connection. + if isDirectConn(best) && !isDirectConn(c) { + continue + } + + // 1. Always prefer a direct connection over a relayed connection. + // 2. If both conns are direct or relayed, pick the one with as many or more streams. + if (!isDirectConn(best) && isDirectConn(c)) || (cLen >= bestLen) { + best = c + bestLen = cLen } } return best diff --git a/swarm_dial.go b/swarm_dial.go index c1e1cfff..a4362ef5 100644 --- a/swarm_dial.go +++ b/swarm_dial.go @@ -403,10 +403,8 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) { return nil, &DialError{Peer: p, Cause: ErrNoAddresses} } goodAddrs := s.filterKnownUndialables(p, peerAddrs) - // TODO Consider dialing private addresses as well - // See https://github.com/libp2p/specs/pull/173/files#r288784559 if forceDirect { - goodAddrs = addrutil.FilterAddrs(goodAddrs, manet.IsPublicAddr, s.nonProxyAddr) + goodAddrs = addrutil.FilterAddrs(goodAddrs, s.nonProxyAddr) } if len(goodAddrs) == 0 { return nil, &DialError{Peer: p, Cause: ErrNoGoodAddresses} From 56ecb0fe0d09b83f071f8691a532863c6f5e6188 Mon Sep 17 00:00:00 2001 From: aarshkshah1992 Date: Thu, 18 Feb 2021 13:50:29 +0530 Subject: [PATCH 08/10] address changes --- swarm_dial.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/swarm_dial.go b/swarm_dial.go index a4362ef5..a3740983 100644 --- a/swarm_dial.go +++ b/swarm_dial.go @@ -313,7 +313,7 @@ func (s *Swarm) doDial(ctx context.Context, p peer.ID) (*Conn, error) { conn = s.bestConnToPeer(p) if forceDirect { if isDirectConn(conn) { - log.Debugf("ignoring dial error because we have a connection: %s", err) + log.Debugf("ignoring dial error because we already have a direct connection: %s", err) return conn, nil } } else if conn != nil { @@ -321,9 +321,10 @@ func (s *Swarm) doDial(ctx context.Context, p peer.ID) (*Conn, error) { // Could have canceled the dial because we received a // connection or some other random reason. // Just ignore the error and return the connection. - log.Debugf("ignoring dial error because we have a connection: %s", err) + log.Debugf("ignoring dial error because we already have a connection: %s", err) return conn, nil } + // ok, we failed. return nil, err } @@ -410,7 +411,6 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) { return nil, &DialError{Peer: p, Cause: ErrNoGoodAddresses} } - // TODO How do we do backoff for forcedirect if !forceDirect { /////// Check backoff andnRank addresses var nonBackoff bool From 8b8bc9a697ae8ddc159f54f81eb31b456359faf1 Mon Sep 17 00:00:00 2001 From: aarshkshah1992 Date: Thu, 18 Feb 2021 13:58:10 +0530 Subject: [PATCH 09/10] restore newline --- go.mod | 2 +- go.sum | 2 ++ swarm_dial.go | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index be76cdfa..5dceff46 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/jbenet/goprocess v0.1.4 github.com/libp2p/go-addr-util v0.0.2 github.com/libp2p/go-conn-security-multistream v0.2.1 - github.com/libp2p/go-libp2p-core v0.8.2 + github.com/libp2p/go-libp2p-core v0.8.3 github.com/libp2p/go-libp2p-loggables v0.1.0 github.com/libp2p/go-libp2p-peerstore v0.2.6 github.com/libp2p/go-libp2p-quic-transport v0.10.0 diff --git a/go.sum b/go.sum index ce327ec1..34920884 100644 --- a/go.sum +++ b/go.sum @@ -194,6 +194,8 @@ github.com/libp2p/go-libp2p-core v0.8.0/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJB github.com/libp2p/go-libp2p-core v0.8.1/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8= github.com/libp2p/go-libp2p-core v0.8.2 h1:/eaSZACWftJZYm07S0nRxdI84v1hSmgnCXrGOvJdpNQ= github.com/libp2p/go-libp2p-core v0.8.2/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8= +github.com/libp2p/go-libp2p-core v0.8.3 h1:BZTReEF6o8g/n4DwxTyeFannOeae35Xy0TD+mES3CNE= +github.com/libp2p/go-libp2p-core v0.8.3/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8= github.com/libp2p/go-libp2p-loggables v0.1.0 h1:h3w8QFfCt2UJl/0/NW4K829HX/0S4KD31PQ7m8UXXO8= github.com/libp2p/go-libp2p-loggables v0.1.0/go.mod h1:EyumB2Y6PrYjr55Q3/tiJ/o3xoDasoRYM7nOzEpoa90= github.com/libp2p/go-libp2p-mplex v0.2.1/go.mod h1:SC99Rxs8Vuzrf/6WhmH41kNn13TiYdAWNYHrwImKLnE= diff --git a/swarm_dial.go b/swarm_dial.go index a3740983..052da67f 100644 --- a/swarm_dial.go +++ b/swarm_dial.go @@ -542,6 +542,7 @@ dialLoop: remoteAddrChan = nil continue } + s.limitedDial(ctx, p, addr, respch) active++ case <-ctx.Done(): From 874c8176a6db71612610ed1dc1ed42b2858dd525 Mon Sep 17 00:00:00 2001 From: aarshkshah1992 Date: Thu, 18 Feb 2021 14:16:07 +0530 Subject: [PATCH 10/10] fixed loop --- swarm.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/swarm.go b/swarm.go index 7536d97d..68f7603f 100644 --- a/swarm.go +++ b/swarm.go @@ -402,8 +402,7 @@ func (s *Swarm) bestConnToPeer(p peer.ID) *Conn { var best *Conn bestLen := 0 - for i := range s.conns.m[p] { - c := s.conns.m[p][i] + for _, c := range s.conns.m[p] { if c.conn.IsClosed() { // We *will* garbage collect this soon anyways. continue