diff --git a/cmd/tss/main.go b/cmd/tss/main.go index 9fa47f0..658c3ff 100644 --- a/cmd/tss/main.go +++ b/cmd/tss/main.go @@ -58,7 +58,6 @@ func main() { p2pConf.BootstrapPeers, p2pConf.Port, priKey, - p2pConf.RendezvousString, baseFolder, tssConf, nil, diff --git a/cmd/tss/mock_tss_server.go b/cmd/tss/mock_tss_server.go index 16e9f7a..068e0d6 100644 --- a/cmd/tss/mock_tss_server.go +++ b/cmd/tss/mock_tss_server.go @@ -3,12 +3,12 @@ package main import ( "errors" + "github.com/libp2p/go-libp2p/core/peer" "gitlab.com/thorchain/tss/go-tss/blame" "gitlab.com/thorchain/tss/go-tss/common" "gitlab.com/thorchain/tss/go-tss/conversion" "gitlab.com/thorchain/tss/go-tss/keygen" "gitlab.com/thorchain/tss/go-tss/keysign" - "gitlab.com/thorchain/tss/go-tss/tss" ) type MockTssServer struct { @@ -31,8 +31,8 @@ func (mts *MockTssServer) GetLocalPeerID() string { return conversion.GetRandomPeerID().String() } -func (mts *MockTssServer) GetKnownPeers() []tss.PeerInfo { - return []tss.PeerInfo{} +func (mts *MockTssServer) GetKnownPeers() []peer.AddrInfo { + return []peer.AddrInfo{} } func (mts *MockTssServer) Keygen(req keygen.Request) (keygen.Response, error) { diff --git a/go.mod b/go.mod index 8708105..45c1de5 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( github.com/gorilla/mux v1.8.0 github.com/ipfs/go-log v1.0.5 github.com/libp2p/go-libp2p v0.25.1 - github.com/libp2p/go-libp2p-kad-dht v0.21.0 github.com/libp2p/go-libp2p-testing v0.12.0 github.com/magiconair/properties v1.8.6 github.com/multiformats/go-multiaddr v0.8.0 @@ -97,7 +96,6 @@ require ( github.com/google/btree v1.1.2 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/gopacket v1.1.19 // indirect - github.com/google/uuid v1.4.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect @@ -114,14 +112,9 @@ require ( github.com/huin/goupnp v1.0.3 // indirect github.com/inconshreveable/mousetrap v1.0.1 // indirect github.com/ipfs/go-cid v0.3.2 // indirect - github.com/ipfs/go-datastore v0.6.0 // indirect - github.com/ipfs/go-ipfs-util v0.0.2 // indirect - github.com/ipfs/go-ipns v0.2.0 // indirect github.com/ipfs/go-log/v2 v2.5.1 // indirect - github.com/ipld/go-ipld-prime v0.9.0 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect - github.com/jbenet/goprocess v0.1.4 // indirect github.com/jmhodges/levigo v1.0.0 // indirect github.com/klauspost/compress v1.16.7 // indirect github.com/klauspost/cpuid/v2 v2.2.1 // indirect @@ -132,8 +125,6 @@ require ( github.com/libp2p/go-cidranger v1.1.0 // indirect github.com/libp2p/go-flow-metrics v0.1.0 // indirect github.com/libp2p/go-libp2p-asn-util v0.2.0 // indirect - github.com/libp2p/go-libp2p-kbucket v0.5.0 // indirect - github.com/libp2p/go-libp2p-record v0.2.0 // indirect github.com/libp2p/go-msgio v0.3.0 // indirect github.com/libp2p/go-nat v0.1.0 // indirect github.com/libp2p/go-netroute v0.2.1 // indirect @@ -170,7 +161,6 @@ require ( github.com/pelletier/go-toml/v2 v2.0.7 // indirect github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/polydawn/refmt v0.0.0-20190807091052-3d65705ee9f1 // indirect github.com/prometheus/common v0.42.0 // indirect github.com/prometheus/procfs v0.9.0 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect @@ -189,11 +179,9 @@ require ( github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect github.com/tendermint/go-amino v0.16.0 // indirect github.com/tidwall/btree v1.6.0 // indirect - github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect github.com/zondax/hid v0.9.2 // indirect github.com/zondax/ledger-go v0.14.3 // indirect go.etcd.io/bbolt v1.3.7 // indirect - go.opencensus.io v0.24.0 // indirect go.uber.org/dig v1.15.0 // indirect go.uber.org/fx v1.18.2 // indirect go.uber.org/multierr v1.8.0 // indirect diff --git a/go.sum b/go.sum index f24cf9b..7364e44 100644 --- a/go.sum +++ b/go.sum @@ -292,7 +292,6 @@ github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8 github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20= -github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= @@ -356,7 +355,6 @@ github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4er github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= @@ -402,7 +400,6 @@ github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -432,12 +429,9 @@ github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLe github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= -github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4= @@ -525,32 +519,20 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= -github.com/ipfs/go-cid v0.0.4/go.mod h1:4LLaPOQwmk5z9LBgQnpkivrx8BJjUyGwTXCd5Xfj6+M= github.com/ipfs/go-cid v0.3.2 h1:OGgOd+JCFM+y1DjWPmVH+2/4POtpDzwcr7VgnB7mZXc= github.com/ipfs/go-cid v0.3.2/go.mod h1:gQ8pKqT/sUxGY+tIwy1RPpAojYu7jAyCp5Tz1svoupw= -github.com/ipfs/go-datastore v0.6.0 h1:JKyz+Gvz1QEZw0LsX1IBn+JFCJQH4SJVFtM4uWU0Myk= -github.com/ipfs/go-datastore v0.6.0/go.mod h1:rt5M3nNbSO/8q1t4LNkLyUwRs8HupMeN/8O4Vn9YAT8= github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk= github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= -github.com/ipfs/go-ipfs-util v0.0.2 h1:59Sswnk1MFaiq+VcaknX7aYEyGyGDAA73ilhEK2POp8= -github.com/ipfs/go-ipfs-util v0.0.2/go.mod h1:CbPtkWJzjLdEcezDns2XYaehFVNXG9zrdrtMecczcsQ= -github.com/ipfs/go-ipns v0.2.0 h1:BgmNtQhqOw5XEZ8RAfWEpK4DhqaYiuP6h71MhIp7xXU= -github.com/ipfs/go-ipns v0.2.0/go.mod h1:3cLT2rbvgPZGkHJoPO1YMJeh6LtkxopCkKFcio/wE24= github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= github.com/ipfs/go-log v1.0.5 h1:2dOuUCB1Z7uoczMWgAyDck5JLb72zHzrMnGnCNNbvY8= github.com/ipfs/go-log v1.0.5/go.mod h1:j0b8ZoR+7+R99LD9jZ6+AJsrzkPbSXbZfGakb5JPtIo= github.com/ipfs/go-log/v2 v2.1.3/go.mod h1:/8d0SH3Su5Ooc31QlL1WysJhvyOTDCjcCZ9Axpmri6g= github.com/ipfs/go-log/v2 v2.5.1 h1:1XdUzF7048prq4aBjDQQ4SL5RxftpRGdXhNRwKSAlcY= github.com/ipfs/go-log/v2 v2.5.1/go.mod h1:prSpmC1Gpllc9UYWxDiZDreBYw7zp4Iqp1kOLU9U5UI= -github.com/ipld/go-ipld-prime v0.9.0 h1:N2OjJMb+fhyFPwPnVvJcWU/NsumP8etal+d2v3G4eww= -github.com/ipld/go-ipld-prime v0.9.0/go.mod h1:KvBLMr4PX1gWptgkzRjVZCrLmSGcZCb/jioOQwCqZN8= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= -github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= github.com/jbenet/go-temp-err-catcher v0.1.0 h1:zpb3ZH6wIE8Shj2sKS+khgRvf7T7RABoLk/+KKHggpk= github.com/jbenet/go-temp-err-catcher v0.1.0/go.mod h1:0kJRvmDZXNMIiJirNPEYfhpPwbGVtZVWC34vc5WLsDk= -github.com/jbenet/goprocess v0.1.4 h1:DRGOFReOMqqDNXwW70QkacFW0YN9QnwLV0Vqk+3oU0o= -github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= @@ -567,7 +549,6 @@ github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= @@ -609,12 +590,6 @@ github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFG github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro= github.com/libp2p/go-libp2p-asn-util v0.2.0 h1:rg3+Os8jbnO5DxkC7K/Utdi+DkY3q/d1/1q+8WeNAsw= github.com/libp2p/go-libp2p-asn-util v0.2.0/go.mod h1:WoaWxbHKBymSN41hWSq/lGKJEca7TNm58+gGJi2WsLI= -github.com/libp2p/go-libp2p-kad-dht v0.21.0 h1:J0Yd22VA+sk0CJRGMgtfHvLVIkZDyJ3AJGiljywIw5U= -github.com/libp2p/go-libp2p-kad-dht v0.21.0/go.mod h1:Bhm9diAFmc6qcWAr084bHNL159srVZRKADdp96Qqd1I= -github.com/libp2p/go-libp2p-kbucket v0.5.0 h1:g/7tVm8ACHDxH29BGrpsQlnNeu+6OF1A9bno/4/U1oA= -github.com/libp2p/go-libp2p-kbucket v0.5.0/go.mod h1:zGzGCpQd78b5BNTDGHNDLaTt9aDK/A02xeZp9QeFC4U= -github.com/libp2p/go-libp2p-record v0.2.0 h1:oiNUOCWno2BFuxt3my4i1frNrt7PerzB3queqa1NkQ0= -github.com/libp2p/go-libp2p-record v0.2.0/go.mod h1:I+3zMkvvg5m2OcSdoL0KPljyJyvNDFGKX7QdlpYUcwk= github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA= github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg= github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0= @@ -695,14 +670,11 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= -github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs= github.com/mtibben/percent v0.2.1/go.mod h1:KG9uO+SZkUp+VkRHsCdYQV3XSZrrSpR3O9ibNBTZrns= -github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aGkbLYxPE= github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYgtWibDcT0rExnbI= github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0= @@ -715,22 +687,16 @@ github.com/multiformats/go-multiaddr-dns v0.3.1 h1:QgQgR+LQVt3NPTjbrLLpsaT2ufAA2 github.com/multiformats/go-multiaddr-dns v0.3.1/go.mod h1:G/245BRQ6FJGmryJCrOuTdB37AMA5AMOVuO6NY3JwTk= github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= github.com/multiformats/go-multiaddr-fmt v0.1.0/go.mod h1:hGtDIW4PU4BqJ50gW2quDuPVjyWNZxToGUh/HwTZYJo= -github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multibase v0.1.1 h1:3ASCDsuLX8+j4kx58qnJ4YFq/JWTJpCyDW27ztsVTOI= github.com/multiformats/go-multibase v0.1.1/go.mod h1:ZEjHE+IsUrgp5mhlEAYjMtZwK1k4haNkcaPg9aoe1a8= github.com/multiformats/go-multicodec v0.7.0 h1:rTUjGOwjlhGHbEMbPoSUJowG1spZTVsITRANCjKTUAQ= github.com/multiformats/go-multicodec v0.7.0/go.mod h1:GUC8upxSBE4oG+q3kWZRw/+6yC1BqO550bjhWsJbZlw= github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= -github.com/multiformats/go-multihash v0.0.10/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= -github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc= -github.com/multiformats/go-multihash v0.0.15/go.mod h1:D6aZrWNLFTV/ynMpKsNtB40mJzmCl4jb1alC0OvHiHg= github.com/multiformats/go-multihash v0.2.1 h1:aem8ZT0VA2nCHHk7bPJ1BjUbHNciqZC/d16Vve9l108= github.com/multiformats/go-multihash v0.2.1/go.mod h1:WxoMcYG85AZVQUyRyo9s4wULvW5qrI9vb2Lt6evduFc= github.com/multiformats/go-multistream v0.4.1 h1:rFy0Iiyn3YT0asivDUIR05leAdwZq3de4741sbiSdfo= github.com/multiformats/go-multistream v0.4.1/go.mod h1:Mz5eykRVAjJWckE2U78c6xqdtyNUEhKSM0Lwar2p77Q= github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= -github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= -github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= @@ -814,8 +780,6 @@ github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6J github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polydawn/refmt v0.0.0-20190807091052-3d65705ee9f1 h1:CskT+S6Ay54OwxBGB0R3Rsx4Muto6UnEYTyKJbyRIAI= -github.com/polydawn/refmt v0.0.0-20190807091052-3d65705ee9f1/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= @@ -889,9 +853,7 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa/go.mod h1:oJyF+mSPHbB5mVY2iO9KV3pTt/QbIkGaO8gQ2WrDbP4= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= @@ -980,10 +942,6 @@ github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0 github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= -github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a h1:G++j5e0OC488te356JvdhaM8YS6nMsjLAYF7JxCv07w= -github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw= -github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k= -github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= @@ -1018,8 +976,6 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= -go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= -go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= @@ -1064,7 +1020,6 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= @@ -1153,7 +1108,6 @@ golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= @@ -1252,7 +1206,6 @@ golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1271,7 +1224,6 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= diff --git a/keygen/ecdsa/keygen_test.go b/keygen/ecdsa/keygen_test.go index f13e123..782401b 100644 --- a/keygen/ecdsa/keygen_test.go +++ b/keygen/ecdsa/keygen_test.go @@ -124,13 +124,13 @@ func (s *TssECDSAKeygenTestSuite) SetUpTest(c *C) { buf, err := base64.StdEncoding.DecodeString(testPriKeyArr[i]) c.Assert(err, IsNil) if i == 0 { - comm, err := p2p.NewCommunication("asgard", nil, ports[i], "", whitelistedPeers) + comm, err := p2p.NewCommunication(nil, ports[i], "", whitelistedPeers) c.Assert(err, IsNil) c.Assert(comm.Start(buf[:]), IsNil) s.comms[i] = comm continue } - comm, err := p2p.NewCommunication("asgard", []maddr.Multiaddr{multiAddr}, ports[i], "", whitelistedPeers) + comm, err := p2p.NewCommunication([]maddr.Multiaddr{multiAddr}, ports[i], "", whitelistedPeers) c.Assert(err, IsNil) c.Assert(comm.Start(buf[:]), IsNil) s.comms[i] = comm diff --git a/keygen/eddsa/keygen_test.go b/keygen/eddsa/keygen_test.go index e0bb06a..37a5f23 100644 --- a/keygen/eddsa/keygen_test.go +++ b/keygen/eddsa/keygen_test.go @@ -110,13 +110,13 @@ func (s *EddsaKeygenTestSuite) SetUpTest(c *C) { buf, err := base64.StdEncoding.DecodeString(testPriKeyArr[i]) c.Assert(err, IsNil) if i == 0 { - comm, err := p2p.NewCommunication("asgard", nil, ports[i], "", whitelistedPeers) + comm, err := p2p.NewCommunication(nil, ports[i], "", whitelistedPeers) c.Assert(err, IsNil) c.Assert(comm.Start(buf), IsNil) s.comms[i] = comm continue } - comm, err := p2p.NewCommunication("asgard", []maddr.Multiaddr{multiAddr}, ports[i], "", whitelistedPeers) + comm, err := p2p.NewCommunication([]maddr.Multiaddr{multiAddr}, ports[i], "", whitelistedPeers) c.Assert(err, IsNil) c.Assert(comm.Start(buf), IsNil) s.comms[i] = comm diff --git a/keysign/ecdsa/keysign_old_test.go b/keysign/ecdsa/keysign_old_test.go index e41f34d..c4a7c4c 100644 --- a/keysign/ecdsa/keysign_old_test.go +++ b/keysign/ecdsa/keysign_old_test.go @@ -136,13 +136,13 @@ func (s *TssECDSAKeysignOldTestSuite) SetUpTest(c *C) { buf, err := base64.StdEncoding.DecodeString(testPriKeyArr[i]) c.Assert(err, IsNil) if i == 0 { - comm, err := p2p.NewCommunication("asgard", nil, ports[i], "", whitelistedPeers) + comm, err := p2p.NewCommunication(nil, ports[i], "", whitelistedPeers) c.Assert(err, IsNil) c.Assert(comm.Start(buf), IsNil) s.comms[i] = comm continue } - comm, err := p2p.NewCommunication("asgard", []maddr.Multiaddr{multiAddr}, ports[i], "", whitelistedPeers) + comm, err := p2p.NewCommunication([]maddr.Multiaddr{multiAddr}, ports[i], "", whitelistedPeers) c.Assert(err, IsNil) c.Assert(comm.Start(buf), IsNil) s.comms[i] = comm diff --git a/keysign/ecdsa/keysign_test.go b/keysign/ecdsa/keysign_test.go index 546eea4..8e102d3 100644 --- a/keysign/ecdsa/keysign_test.go +++ b/keysign/ecdsa/keysign_test.go @@ -149,13 +149,13 @@ func (s *TssECDSAKeysignTestSuite) SetUpTest(c *C) { buf, err := base64.StdEncoding.DecodeString(testPriKeyArr[i]) c.Assert(err, IsNil) if i == 0 { - comm, err := p2p.NewCommunication("asgard", nil, ports[i], "", whitelistedPeers) + comm, err := p2p.NewCommunication(nil, ports[i], "", whitelistedPeers) c.Assert(err, IsNil) c.Assert(comm.Start(buf), IsNil) s.comms[i] = comm continue } - comm, err := p2p.NewCommunication("asgard", []maddr.Multiaddr{multiAddr}, ports[i], "", whitelistedPeers) + comm, err := p2p.NewCommunication([]maddr.Multiaddr{multiAddr}, ports[i], "", whitelistedPeers) c.Assert(err, IsNil) c.Assert(comm.Start(buf), IsNil) s.comms[i] = comm diff --git a/keysign/eddsa/keysign_test.go b/keysign/eddsa/keysign_test.go index b122479..181c15d 100644 --- a/keysign/eddsa/keysign_test.go +++ b/keysign/eddsa/keysign_test.go @@ -146,13 +146,13 @@ func (s *EddsaKeysignTestSuite) SetUpTest(c *C) { buf, err := base64.StdEncoding.DecodeString(testPriKeyArr[i]) c.Assert(err, IsNil) if i == 0 { - comm, err := p2p.NewCommunication("asgard", nil, ports[i], "", whitelistedPeers) + comm, err := p2p.NewCommunication(nil, ports[i], "", whitelistedPeers) c.Assert(err, IsNil) c.Assert(comm.Start(buf), IsNil) s.comms[i] = comm continue } - comm, err := p2p.NewCommunication("asgard", []maddr.Multiaddr{multiAddr}, ports[i], "", whitelistedPeers) + comm, err := p2p.NewCommunication([]maddr.Multiaddr{multiAddr}, ports[i], "", whitelistedPeers) c.Assert(err, IsNil) c.Assert(comm.Start(buf), IsNil) s.comms[i] = comm diff --git a/p2p/communication.go b/p2p/communication.go index c1620a5..e3e2e37 100644 --- a/p2p/communication.go +++ b/p2p/communication.go @@ -10,14 +10,11 @@ import ( "time" libp2p "github.com/libp2p/go-libp2p" - dht "github.com/libp2p/go-libp2p-kad-dht" "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/protocol" - discovery_routing "github.com/libp2p/go-libp2p/p2p/discovery/routing" - discovery_util "github.com/libp2p/go-libp2p/p2p/discovery/util" rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager" "github.com/libp2p/go-libp2p/p2p/net/connmgr" "github.com/libp2p/go-libp2p/p2p/protocol/ping" @@ -49,7 +46,6 @@ type Message struct { // Communication use p2p to broadcast messages among all the TSS nodes type Communication struct { - rendezvous string // based on group bootstrapPeers []maddr.Multiaddr logger zerolog.Logger listenAddr maddr.Multiaddr @@ -63,11 +59,11 @@ type Communication struct { externalAddr maddr.Multiaddr streamMgr *StreamMgr whitelistedPeers []peer.ID + discovery *PeerDiscovery } // NewCommunication create a new instance of Communication func NewCommunication( - rendezvous string, bootstrapPeers []maddr.Multiaddr, port int, externalIP string, @@ -85,7 +81,7 @@ func NewCommunication( } } return &Communication{ - rendezvous: rendezvous, + bootstrapPeers: bootstrapPeers, logger: log.With().Str("module", "communication").Logger(), listenAddr: addr, @@ -252,7 +248,7 @@ func (c *Communication) bootStrapConnectivityCheck() error { } func (c *Communication) startChannel(privKeyBytes []byte) error { - ctx := context.Background() + c.logger.Info().Msgf("No DHT enabled; use private gossip instead.") p2pPriKey, err := crypto.UnmarshalSecp256k1PrivateKey(privKeyBytes) if err != nil { c.logger.Error().Msgf("error is %f", err) @@ -310,6 +306,7 @@ func (c *Communication) startChannel(privKeyBytes []byte) error { libp2p.ResourceManager(m), libp2p.ConnectionManager(cmgr), libp2p.ConnectionGater(NewWhitelistConnectionGater(c.whitelistedPeers, c.logger)), + libp2p.DisableRelay(), ) if err != nil { return fmt.Errorf("fail to create p2p host: %w", err) @@ -321,14 +318,6 @@ func (c *Communication) startChannel(privKeyBytes []byte) error { // client because we want each peer to maintain its own local copy of the // DHT, so that the bootstrapping node of the DHT can go down without // inhibiting future peer discovery. - kademliaDHT, err := dht.New(ctx, h, dht.Mode(dht.ModeServer)) - if err != nil { - return fmt.Errorf("fail to create DHT: %w", err) - } - c.logger.Debug().Msg("Bootstrapping the DHT") - if err = kademliaDHT.Bootstrap(ctx); err != nil { - return fmt.Errorf("fail to bootstrap DHT: %w", err) - } var connectionErr error for i := 0; i < 5; i++ { @@ -343,30 +332,28 @@ func (c *Communication) startChannel(privKeyBytes []byte) error { return fmt.Errorf("fail to connect to bootstrap peer: %w", connectionErr) } - // We use a rendezvous point "meet me here" to announce our location. - // This is like telling your friends to meet you at the Eiffel Tower. - routingDiscovery := discovery_routing.NewRoutingDiscovery(kademliaDHT) - discovery_util.Advertise(ctx, routingDiscovery, c.rendezvous) - - // Create a goroutine to shut down the DHT after 5 minutes - go func() { - select { - case <-time.After(5 * time.Minute): - c.logger.Info().Msg("Closing Kademlia DHT after 5 minutes") - if err := kademliaDHT.Close(); err != nil { - c.logger.Error().Err(err).Msg("Failed to close Kademlia DHT") - } - case <-ctx.Done(): - c.logger.Info().Msg("Context done, not waiting for 5 minutes to close DHT") - } - }() - err = c.bootStrapConnectivityCheck() if err != nil { return err } c.logger.Info().Msg("Successfully announced!") + + c.logger.Info().Msg("Start peer discovery/gossip...") + //c.bootstrapPeers + bootstrapPeerAddrInfos := make([]peer.AddrInfo, 0, len(c.bootstrapPeers)) + for _, addr := range c.bootstrapPeers { + peerInfo, err := peer.AddrInfoFromP2pAddr(addr) + if err != nil { + c.logger.Error().Err(err).Msgf("fail to convert multiaddr to peer info: %s", addr) + continue + } + bootstrapPeerAddrInfos = append(bootstrapPeerAddrInfos, *peerInfo) + } + discovery := NewPeerDiscovery(c.host, bootstrapPeerAddrInfos) + c.discovery = discovery + discovery.Start(context.Background()) + return nil } @@ -435,6 +422,9 @@ func (c *Communication) Start(priKeyBytes []byte) error { // Stop communication func (c *Communication) Stop() error { + if c.discovery != nil { + c.discovery.Stop() + } // we need to stop the handler and the p2p services firstly, then terminate the our communication threads if err := c.host.Close(); err != nil { c.logger.Err(err).Msg("fail to close host network") diff --git a/p2p/communication_test.go b/p2p/communication_test.go index 87fc62d..a7d44fb 100644 --- a/p2p/communication_test.go +++ b/p2p/communication_test.go @@ -18,7 +18,7 @@ type CommunicationTestSuite struct{} var _ = Suite(&CommunicationTestSuite{}) func (CommunicationTestSuite) TestBasicCommunication(c *C) { - comm, err := NewCommunication("rendezvous", nil, 6668, "", []peer.ID{}) + comm, err := NewCommunication(nil, 6668, "", []peer.ID{}) c.Assert(err, IsNil) c.Assert(comm, NotNil) comm.SetSubscribe(messages.TSSKeyGenMsg, "hello", make(chan *Message)) @@ -39,6 +39,7 @@ func checkExist(a []maddr.Multiaddr, b string) bool { } func (CommunicationTestSuite) TestEstablishP2pCommunication(c *C) { + bootstrapPeerID, err := peer.Decode("16Uiu2HAm4TmEzUqy3q3Dv7HvdoSboHk5sFj2FH3npiN5vDbJC6gh") c.Assert(err, IsNil) sk1, _, err := crypto.GenerateSecp256k1Key(rand.Reader) @@ -60,13 +61,13 @@ func (CommunicationTestSuite) TestEstablishP2pCommunication(c *C) { c.Assert(err, IsNil) privKey, err := base64.StdEncoding.DecodeString(bootstrapPrivKey) c.Assert(err, IsNil) - comm, err := NewCommunication("commTest", nil, 2220, fakeExternalIP, whitelistedPeers) + comm, err := NewCommunication(nil, 2220, fakeExternalIP, whitelistedPeers) c.Assert(err, IsNil) c.Assert(comm.Start(privKey), IsNil) defer comm.Stop() c.Assert(err, IsNil) - comm2, err := NewCommunication("commTest", []maddr.Multiaddr{validMultiAddr}, 2221, "", whitelistedPeers) + comm2, err := NewCommunication([]maddr.Multiaddr{validMultiAddr}, 2221, "", whitelistedPeers) c.Assert(err, IsNil) err = comm2.Start(sk1raw) c.Assert(err, IsNil) @@ -76,14 +77,14 @@ func (CommunicationTestSuite) TestEstablishP2pCommunication(c *C) { invalidAddr := "/ip4/127.0.0.1/tcp/2220/p2p/" + id2.String() invalidMultiAddr, err := maddr.NewMultiaddr(invalidAddr) c.Assert(err, IsNil) - comm3, err := NewCommunication("commTest", []maddr.Multiaddr{invalidMultiAddr}, 2222, "", whitelistedPeers) + comm3, err := NewCommunication([]maddr.Multiaddr{invalidMultiAddr}, 2222, "", whitelistedPeers) c.Assert(err, IsNil) err = comm3.Start(sk1raw) c.Assert(err, ErrorMatches, "fail to connect to bootstrap peer: fail to connect to any peer") defer comm3.Stop() // we connect to one invalid and one valid address - comm4, err := NewCommunication("commTest", []maddr.Multiaddr{invalidMultiAddr, validMultiAddr}, 2223, "", whitelistedPeers) + comm4, err := NewCommunication([]maddr.Multiaddr{invalidMultiAddr, validMultiAddr}, 2223, "", whitelistedPeers) c.Assert(err, IsNil) err = comm4.Start(sk1raw) c.Assert(err, IsNil) @@ -97,7 +98,7 @@ func (CommunicationTestSuite) TestEstablishP2pCommunication(c *C) { c.Assert(checkExist(ps.Addrs(comm.host.ID()), fakeExternalMultiAddr), Equals, true) // same as above, just without whitelisted peers - comm5, err := NewCommunication("commTest", []maddr.Multiaddr{invalidMultiAddr, validMultiAddr}, 2224, "", []peer.ID{}) + comm5, err := NewCommunication([]maddr.Multiaddr{invalidMultiAddr, validMultiAddr}, 2224, "", []peer.ID{}) c.Assert(err, IsNil) err = comm5.Start(sk1raw) c.Assert(err, ErrorMatches, "fail to connect to bootstrap peer: fail to connect to any peer") diff --git a/p2p/discovery.go b/p2p/discovery.go new file mode 100644 index 0000000..dab53ec --- /dev/null +++ b/p2p/discovery.go @@ -0,0 +1,236 @@ +package p2p + +import ( + "context" + "encoding/json" + "io" + "slices" + "sync" + "time" + + "github.com/libp2p/go-libp2p/core/host" + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/multiformats/go-multiaddr" + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" +) + +const DiscoveryProtocol = "/tss/discovery/1.0.0" + +const MaxGossipConcurrency = 50 + +var GossipInterval = 30 * time.Second + +type PeerDiscovery struct { + host host.Host + knownPeers map[peer.ID]peer.AddrInfo + bootstrapPeers []peer.AddrInfo + mu sync.RWMutex + logger zerolog.Logger + closeChan chan struct{} +} + +func NewPeerDiscovery(h host.Host, bootstrapPeers []peer.AddrInfo) *PeerDiscovery { + pd := &PeerDiscovery{ + host: h, + knownPeers: make(map[peer.ID]peer.AddrInfo), + bootstrapPeers: bootstrapPeers, + logger: log.With().Str("module", "peer-discovery").Logger(), + closeChan: make(chan struct{}), + } + + // Set up discovery protocol handler + h.SetStreamHandler(DiscoveryProtocol, pd.handleDiscovery) + + return pd +} + +// Start begins the discovery process +func (pd *PeerDiscovery) Start(ctx context.Context) { + pd.logger.Info().Msg("Starting peer discovery with bootstrap peers") + // Connect to bootstrap peers first + for _, pinfo := range pd.bootstrapPeers { + if err := pd.host.Connect(ctx, pinfo); err != nil { + pd.logger.Error().Err(err). + Stringer("bootstrap_peer_id", pinfo.ID). + Stringer("bootstrap_peer_info", pinfo). + Msgf("Failed to connect to bootstrap peer") + continue + } + pd.addPeer(pinfo) + } + + //before periodic gossip, start two rounds of warmup; this is to ensure keygen/keysign unit test + // success where there might not be enough time for gossip to propagate before the keygen starts. + pd.gossipPeers(ctx) + time.Sleep(1 * time.Second) + pd.gossipPeers(ctx) + // Start periodic gossip + go pd.startGossip(ctx) +} + +func (pd *PeerDiscovery) Stop() { + close(pd.closeChan) +} + +// addPeer adds a peer to known peers +func (pd *PeerDiscovery) addPeer(pinfo peer.AddrInfo) { + pd.mu.Lock() + defer pd.mu.Unlock() + + if pinfo.ID == pd.host.ID() { + return // Don't add ourselves + } + oldPinfo, ok := pd.knownPeers[pinfo.ID] + if ok { + for _, addr := range pinfo.Addrs { + if !slices.Contains(oldPinfo.Addrs, addr) { + oldPinfo.Addrs = append(oldPinfo.Addrs, addr) + } + } + } else { + oldPinfo = pinfo + } + pd.knownPeers[pinfo.ID] = oldPinfo +} + +// GetPeers returns all known peers +func (pd *PeerDiscovery) GetPeers() []peer.AddrInfo { + pd.mu.RLock() + defer pd.mu.RUnlock() + + peers := make([]peer.AddrInfo, 0, len(pd.knownPeers)) + for _, p := range pd.knownPeers { + peers = append(peers, p) + } + return peers +} + +// handleDiscovery handles incoming discovery streams +func (pd *PeerDiscovery) handleDiscovery(s network.Stream) { + pd.logger.Debug(). + Stringer("from_peer", s.Conn().RemotePeer()). + Msgf("Received discovery stream") + defer s.Close() + + ma := s.Conn().RemoteMultiaddr() + + ai := peer.AddrInfo{ + ID: s.Conn().RemotePeer(), + Addrs: []multiaddr.Multiaddr{ma}, + } + pd.addPeer(ai) + + // Share our known peers + peers := pd.GetPeers() + data, err := json.Marshal(peers) + if err != nil { + pd.logger.Error().Err(err).Msgf("Failed to marshal peers") + return + } + _, err = s.Write(data) + if err != nil { + pd.logger.Error().Err(err).Msgf("Failed to write to stream") + } +} + +// startGossip periodically shares peer information +func (pd *PeerDiscovery) startGossip(ctx context.Context) { + ticker := time.NewTicker(GossipInterval) + defer ticker.Stop() + + for { + select { + case _, ok := <-pd.closeChan: + if !ok { + pd.logger.Info().Msg("Peer discovery stopped") + return + } + pd.logger.Warn().Msg("Should not receive from closed channel!") + case <-ctx.Done(): + return + case <-ticker.C: + pd.gossipPeers(ctx) + } + } +} + +func (pd *PeerDiscovery) gossipPeers(ctx context.Context) { + pd.logger.Debug().Msgf("Gossiping known peers") + peers := pd.GetPeers() + pd.logger.Debug(). + Array("peers", zerolog.Arr().Interface(peers)). + Msgf("current peers") + + ctx, cancel := context.WithTimeout(ctx, 10*time.Second) + defer cancel() + var wg sync.WaitGroup + sem := make(chan struct{}, MaxGossipConcurrency) // Limit concurrency + + for _, p := range peers { + if p.ID == pd.host.ID() { + continue + } + + sem <- struct{}{} + wg.Add(1) + go func(p peer.AddrInfo) { + defer wg.Done() + defer func() { <-sem }() + + err := pd.host.Connect(ctx, p) + if err != nil { + pd.logger.Error().Err(err). + Stringer("to", p.ID). + Msg("Failed to connect to peer") + return + } + pd.logger.Debug(). + Stringer("to", p). + Msg("Connected to peer") + + // Open discovery stream + s, err := pd.host.NewStream(ctx, p.ID, DiscoveryProtocol) + if err != nil { + pd.logger.Error().Err(err). + Stringer("to", p). + Msg("Failed to open discovery stream to peer") + return + } + defer s.Close() + pd.logger.Debug(). + Stringer("to", p). + Msg("Opened discovery stream to peer") + + // Read peer info from stream + // This is a simplified example - implement proper serialization + limitedReader := io.LimitReader(s, 1<<20) // Limit to 1MB + buf, err := io.ReadAll(limitedReader) + if err != nil { + pd.logger.Error().Err(err). + Stringer("from", p). + Msg("Failed to read from stream") + return + } + pd.logger.Debug().Msgf("Received peer data: %s", string(buf)) + + // Parse received peer info and add to known peers + var recvPeers []peer.AddrInfo + err = json.Unmarshal(buf, &recvPeers) + if err != nil { + pd.logger.Error().Err(err). + Stringer("from", p). + Msg("Failed to unmarshal peer data received") + return + } + for _, p := range recvPeers { + pd.logger.Debug(). + Stringer("peer", p). + Msg("Adding peer") + pd.addPeer(p) + } + }(p) + } + wg.Wait() +} diff --git a/p2p/discovery_test.go b/p2p/discovery_test.go new file mode 100644 index 0000000..550d1f9 --- /dev/null +++ b/p2p/discovery_test.go @@ -0,0 +1,86 @@ +package p2p + +import ( + "crypto/rand" + "encoding/base64" + "testing" + "time" + + "github.com/libp2p/go-libp2p/core/crypto" + "github.com/libp2p/go-libp2p/core/peer" + maddr "github.com/multiformats/go-multiaddr" + "github.com/stretchr/testify/assert" +) + +func TestDiscovery(t *testing.T) { + OldGossipInterval := GossipInterval + defer func() { + GossipInterval = OldGossipInterval + }() + GossipInterval = 1 * time.Second + bootstrapPeer := "/ip4/127.0.0.1/tcp/2220/p2p/16Uiu2HAm4TmEzUqy3q3Dv7HvdoSboHk5sFj2FH3npiN5vDbJC6gh" + bootstrapPeerID, err := peer.Decode("16Uiu2HAm4TmEzUqy3q3Dv7HvdoSboHk5sFj2FH3npiN5vDbJC6gh") + + bootstrapPrivKey := "6LABmWB4iXqkqOJ9H0YFEA2CSSx6bA7XAKGyI/TDtas=" + externalIP := "127.0.0.1" + var whitelistedPeers []peer.ID + + //fakeExternalMultiAddr := "/ip4/127.0.0.1/tcp/2220" + validMultiAddr, err := maddr.NewMultiaddr(bootstrapPeer) + assert.NoError(t, err) + privKey, err := base64.StdEncoding.DecodeString(bootstrapPrivKey) + assert.NoError(t, err) + + sk1, _, err := crypto.GenerateSecp256k1Key(rand.Reader) + sk1raw, _ := sk1.Raw() + assert.NoError(t, err) + + sk2, _, err := crypto.GenerateSecp256k1Key(rand.Reader) + assert.NoError(t, err) + sk2raw, _ := sk2.Raw() + sk3, _, err := crypto.GenerateSecp256k1Key(rand.Reader) + assert.NoError(t, err) + sk3raw, _ := sk3.Raw() + id1, err := peer.IDFromPrivateKey(sk1) + id2, err := peer.IDFromPrivateKey(sk2) + id3, err := peer.IDFromPrivateKey(sk3) + whitelistedPeers = append(whitelistedPeers, id1, id2, id3, bootstrapPeerID) + + comm, err := NewCommunication(nil, 2220, externalIP, whitelistedPeers) + assert.NoError(t, err) + assert.NoError(t, comm.Start(privKey)) + defer comm.Stop() + + comm2, err := NewCommunication([]maddr.Multiaddr{validMultiAddr}, 2221, externalIP, whitelistedPeers) + assert.NoError(t, err) + err = comm2.Start(sk1raw) + assert.NoError(t, err) + defer comm2.Stop() + + // we connect to an invalid peer and see + + //id, err := peer.IDFromPrivateKey(sk2) + //assert.NoError(t, err) + //invalidAddr := "/ip4/127.0.0.1/tcp/2220/p2p/" + id.String() + //invalidMultiAddr, err := maddr.NewMultiaddr(invalidAddr) + assert.NoError(t, err) + comm3, err := NewCommunication([]maddr.Multiaddr{validMultiAddr}, 2222, externalIP, whitelistedPeers) + assert.NoError(t, err) + err = comm3.Start(sk2raw) + defer comm3.Stop() + + // we connect to one invalid and one valid address + + comm4, err := NewCommunication([]maddr.Multiaddr{validMultiAddr}, 2223, externalIP, whitelistedPeers) + assert.NoError(t, err) + err = comm4.Start(sk3raw) + assert.NoError(t, err) + defer comm4.Stop() + + time.Sleep(5 * time.Second) + + assert.Equal(t, 4, len(comm.host.Peerstore().Peers())) + assert.Equal(t, 4, len(comm2.host.Peerstore().Peers())) + assert.Equal(t, 4, len(comm3.host.Peerstore().Peers())) + assert.Equal(t, 4, len(comm4.host.Peerstore().Peers())) +} diff --git a/tss/server.go b/tss/server.go index 51d4c62..c02752a 100644 --- a/tss/server.go +++ b/tss/server.go @@ -1,6 +1,7 @@ package tss import ( + "github.com/libp2p/go-libp2p/core/peer" "gitlab.com/thorchain/tss/go-tss/keygen" "gitlab.com/thorchain/tss/go-tss/keysign" ) @@ -10,7 +11,7 @@ type Server interface { Start() error Stop() GetLocalPeerID() string - GetKnownPeers() []PeerInfo + GetKnownPeers() []peer.AddrInfo Keygen(req keygen.Request) (keygen.Response, error) KeygenAllAlgo(req keygen.Request) ([]keygen.Response, error) KeySign(req keysign.Request) (keysign.Response, error) diff --git a/tss/tss.go b/tss/tss.go index fc5294e..353bd2d 100644 --- a/tss/tss.go +++ b/tss/tss.go @@ -53,7 +53,6 @@ func NewTss( cmdBootstrapPeers []maddr.Multiaddr, p2pPort int, priKey tcrypto.PrivKey, - rendezvous, baseFolder string, conf common.TssConfig, preParams *bkeygen.LocalPreParams, @@ -104,7 +103,7 @@ func NewTss( } } - comm, err := p2p.NewCommunication(rendezvous, whitelistedBootstrapPeers, p2pPort, externalIP, whitelistedPeers) + comm, err := p2p.NewCommunication(whitelistedBootstrapPeers, p2pPort, externalIP, whitelistedPeers) if err != nil { return nil, fmt.Errorf("fail to create communication layer: %w", err) } @@ -253,17 +252,16 @@ func (t *TssServer) GetLocalPeerID() string { } // GetKnownPeers return the the ID and IP address of all peers. -func (t *TssServer) GetKnownPeers() []PeerInfo { - infos := []PeerInfo{} +func (t *TssServer) GetKnownPeers() []peer.AddrInfo { + var infos []peer.AddrInfo host := t.p2pCommunication.GetHost() for _, conn := range host.Network().Conns() { - peer := conn.RemotePeer() + p := conn.RemotePeer() addrs := conn.RemoteMultiaddr() - ip, _ := addrs.ValueForProtocol(maddr.P_IP4) - pi := PeerInfo{ - ID: peer.String(), - Address: ip, + pi := peer.AddrInfo{ + p, + []maddr.Multiaddr{addrs}, } infos = append(infos, pi) } diff --git a/tss/tss_4nodes_test.go b/tss/tss_4nodes_test.go index caed466..3ecf985 100644 --- a/tss/tss_4nodes_test.go +++ b/tss/tss_4nodes_test.go @@ -376,7 +376,7 @@ func (s *FourNodeTestSuite) getTssServer(c *C, index int, conf common.TssConfig, c.Assert(err, IsNil) whitelistedPeers = append(whitelistedPeers, peer) } - instance, err := NewTss(peerIDs, s.ports[index], priKey, "Asgard", baseHome, conf, s.preParams[index], "", "password", whitelistedPeers) + instance, err := NewTss(peerIDs, s.ports[index], priKey, baseHome, conf, s.preParams[index], "", "password", whitelistedPeers) c.Assert(err, IsNil) return instance } diff --git a/tss/tss_4nodes_zeta_test.go b/tss/tss_4nodes_zeta_test.go index 1cd3fa4..8b2b087 100644 --- a/tss/tss_4nodes_zeta_test.go +++ b/tss/tss_4nodes_zeta_test.go @@ -241,7 +241,7 @@ func (s *FourNodeScaleZetaSuite) getTssServer(c *C, index int, conf common.TssCo c.Assert(err, IsNil) whitelistedPeers = append(whitelistedPeers, peer) } - instance, err := NewTss(peerIDs, s.ports[index], priKey, "Zeta", baseHome, conf, s.preParams[index], "", "password", whitelistedPeers) + instance, err := NewTss(peerIDs, s.ports[index], priKey, baseHome, conf, s.preParams[index], "", "password", whitelistedPeers) c.Assert(err, IsNil) return instance }