diff --git a/go.mod b/go.mod index b5b30299dbb3741e1f2c39a153005ad8d82dc5a0..9bc9742cb2f826efae4f90157e45c9362261a5ba 100644 --- a/go.mod +++ b/go.mod @@ -3,27 +3,27 @@ module github.com/iotaledger/goshimmer go 1.13 require ( - github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect github.com/dgraph-io/badger v1.6.0 github.com/dgrijalva/jwt-go v3.2.0+incompatible + github.com/dgryski/go-farm v0.0.0-20191112170834-c2139c5d712b // indirect github.com/ethereum/go-ethereum v1.9.3 github.com/gdamore/tcell v1.2.0 github.com/go-zeromq/zmq4 v0.5.0 - github.com/golang/protobuf v1.3.2 // indirect - github.com/google/open-location-code/go v0.0.0-20190723034300-2c7115db77a3 + github.com/google/open-location-code/go v0.0.0-20190903173953-119bc96a3a51 github.com/gorilla/websocket v1.4.1 - github.com/iotaledger/iota.go v1.0.0-beta.7 - github.com/kr/pretty v0.1.0 // indirect + github.com/iotaledger/autopeering-sim v0.0.0-20191120103907-203d7715f04c + github.com/iotaledger/hive.go v0.0.0-20191118130432-89eebe8fe8eb + github.com/iotaledger/iota.go v1.0.0-beta.9 github.com/labstack/echo v3.3.10+incompatible - github.com/labstack/gommon v0.3.0 // indirect github.com/magiconair/properties v1.8.1 github.com/pkg/errors v0.8.1 github.com/rivo/tview v0.0.0-20190829161255-f8bc69b90341 - github.com/rivo/uniseg v0.1.0 // indirect + go.uber.org/atomic v1.5.1 // indirect + go.uber.org/multierr v1.4.0 // indirect + go.uber.org/zap v1.13.0 // indirect golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 - golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 - golang.org/x/sys v0.0.0-20190904154756-749cb33beabd // indirect - golang.org/x/text v0.3.2 // indirect - gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect - gopkg.in/zeromq/goczmq.v4 v4.1.0 // indirect + golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914 + golang.org/x/sys v0.0.0-20191119195528-f068ffe820e4 // indirect + golang.org/x/tools v0.0.0-20191120001058-ad01d5993d97 // indirect + google.golang.org/grpc v1.21.0 ) diff --git a/go.sum b/go.sum index 3df102786afb3eeee10747d3452e60d64e12eb1b..2372f44c502fa78abee26ed7fb4bb53c6a6697f1 100644 --- a/go.sum +++ b/go.sum @@ -1,112 +1,262 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 h1:cTp8I5+VIoKjsnZuH8vjyaysT/ses3EvZeaV/1UkF2M= github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/DATA-DOG/go-sqlmock v1.3.3 h1:CWUqKXe0s8A2z6qCgkP4Kru7wC11YoAnoupUKFDnH08= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= +github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0= +github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/apsdehal/go-logger v0.0.0-20190506062552-f85330a4b532/go.mod h1:U3/8D6R9+bVpX0ORZjV+3mU9pQ86m7h1lESgJbXNvXA= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/beevik/ntp v0.2.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgraph-io/badger v1.5.4/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ= +github.com/dgraph-io/badger v1.6.0 h1:DshxFxZWXUcO0xX476VJC07Xsr6ZCBVRHKZ93Oh7Evo= github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-farm v0.0.0-20190323231341-8198c7b169ec/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= +github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= +github.com/dgryski/go-farm v0.0.0-20191112170834-c2139c5d712b h1:SeiGBzKrEtuDddnBABHkp4kq9sBGE9nuYmk6FPTg0zg= +github.com/dgryski/go-farm v0.0.0-20191112170834-c2139c5d712b/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/ethereum/go-ethereum v1.9.3 h1:v3bE4abkXknLcyWCf4TRFn+Ecmm9thPtfLFvTEQ+1+U= github.com/ethereum/go-ethereum v1.9.3/go.mod h1:PwpWDrCLZrV+tfrhqqF6kPknbISMHaJv9Ln3kPCZLwY= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= github.com/gdamore/tcell v1.1.2/go.mod h1:h3kq4HO9l2On+V9ed8w8ewqQEmGCSSHOgQ+2h8uzurE= +github.com/gdamore/tcell v1.2.0 h1:ikixzsxc8K8o3V2/CEmyoEW8mJZaNYQQ3NP3VIQdUe4= github.com/gdamore/tcell v1.2.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-zeromq/zmq4 v0.5.0 h1:DijriKlrr2b48mymvAsZApiPzrbxQodYKG1aDH1rz8c= github.com/go-zeromq/zmq4 v0.5.0/go.mod h1:6p7pjNlkfrQQVipmEuZDk7fakLZCqPPVK+Iq3jfbDg8= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/open-location-code/go v0.0.0-20190723034300-2c7115db77a3/go.mod h1:eJfRN6aj+kR/rnua/rw9jAgYhqoMHldQkdTi+sePRKk= +github.com/google/open-location-code/go v0.0.0-20190903173953-119bc96a3a51 h1:OdVal38kmXn0U3M3CYmPF4cpMLLvD4ioshwrooNfmxs= +github.com/google/open-location-code/go v0.0.0-20190903173953-119bc96a3a51/go.mod h1:eJfRN6aj+kR/rnua/rw9jAgYhqoMHldQkdTi+sePRKk= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/iotaledger/autopeering-sim v0.0.0-20191115173310-317faa63cf9c h1:1rTNwCmbnt16oL4wwvvaftvEpOLjiBafftAjvsc5GRs= +github.com/iotaledger/autopeering-sim v0.0.0-20191115173310-317faa63cf9c/go.mod h1:cRYqXkJh2PDyW9voFcTOqvCPJaZOmA4u78yb3zuFJNw= +github.com/iotaledger/autopeering-sim v0.0.0-20191118112632-0056a04132b5 h1:VdX7IbHWdi6bPboVschNmzY4tKLMuqYuvF1s/c/RQS8= +github.com/iotaledger/autopeering-sim v0.0.0-20191118112632-0056a04132b5/go.mod h1:LDtLLYVjSuwAH2k3onNt9qhm0EPHLMXRnslsTzn7Yu8= +github.com/iotaledger/autopeering-sim v0.0.0-20191120093237-9e81a790d189 h1:JF1Ky6w0vNk53yMHtW4OgBinE8ZDftPS4LwAs1yJXhY= +github.com/iotaledger/autopeering-sim v0.0.0-20191120093237-9e81a790d189/go.mod h1:/vE248gYTjvoSQ/oL/EIO8sxIDEM/H/n1B9Oubg8C34= +github.com/iotaledger/autopeering-sim v0.0.0-20191120103907-203d7715f04c h1:S8UKkR+lbYVquuQE9nvmjYGLvHrWU3HFBcjxmlRbJ5I= +github.com/iotaledger/autopeering-sim v0.0.0-20191120103907-203d7715f04c/go.mod h1:/vE248gYTjvoSQ/oL/EIO8sxIDEM/H/n1B9Oubg8C34= +github.com/iotaledger/goshimmer v0.0.0-20191113134331-c2d1b2f9d533/go.mod h1:7vYiofXphp9+PkgVAEM0pvw3aoi4ksrZ7lrEgX50XHs= +github.com/iotaledger/hive.go v0.0.0-20191115134440-92f05839b6e0/go.mod h1:Ks2y/bEyfvb7nUA7l69a+8Epsv16UlGev0BvxggHius= +github.com/iotaledger/hive.go v0.0.0-20191116130349-b8be71b827be h1:8aE2Pv9Z2db42CscDf78Yt/uHzHnkAOLmaXvzFqlX7o= +github.com/iotaledger/hive.go v0.0.0-20191116130349-b8be71b827be/go.mod h1:Ks2y/bEyfvb7nUA7l69a+8Epsv16UlGev0BvxggHius= +github.com/iotaledger/hive.go v0.0.0-20191118130432-89eebe8fe8eb h1:nuS/LETRJ8obUyBIZeyxeei0ZPlyOMj8YPziOgSM4Og= +github.com/iotaledger/hive.go v0.0.0-20191118130432-89eebe8fe8eb/go.mod h1:1Thhlil4lHzuy53EVvmEbEvWBFY0Tasp4kCBfxBCPIk= github.com/iotaledger/iota.go v1.0.0-beta.7 h1:OaUNahPvOdQz2nKcgeAfcUdxlEDlEV3xwLIkwzZ1B/U= github.com/iotaledger/iota.go v1.0.0-beta.7/go.mod h1:dMps6iMVU1pf5NDYNKIw4tRsPeC8W3ZWjOvYHOO1PMg= +github.com/iotaledger/iota.go v1.0.0-beta.9 h1:c654s9pkdhMBkABUvWg+6k91MEBbdtmZXP1xDfQpajg= +github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg= github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s= github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0= github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= +github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09mS6CXfO4= github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg= github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= +github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= +github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ= +github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/rivo/tview v0.0.0-20190829161255-f8bc69b90341 h1:d2Z5U4d3fenPRFFweaMCogbXiRywM5kgYtu20/hol3M= github.com/rivo/tview v0.0.0-20190829161255-f8bc69b90341/go.mod h1:+rKjP5+h9HMwWRpAfhIkkQ9KE3m3Nz5rwn7YtUpwgqk= github.com/rivo/uniseg v0.0.0-20190513083848-b9f5b9457d44/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/sasha-s/go-deadlock v0.2.0 h1:lMqc+fUb7RrFS3gQLtoQsJ7/6TV/pAIFvBsqX73DK8Y= +github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10= +github.com/simia-tech/env v0.1.0/go.mod h1:eVRQ7W5NXXHifpPAcTJ3r5EmoGgMn++dXfSVbZv3Opo= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/spf13/viper v1.5.0/go.mod h1:AkYRkVJF8TkSG/xet6PzXX+l39KhhXa2pdqVSxnTcn4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +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= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8= github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= +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= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.mongodb.org/mongo-driver v1.0.0/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= +go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= +go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.5.1 h1:rsqfU5vBkVknbhUGbAUwQKR2H4ItV8tjJ+6kJX4cxHM= +go.uber.org/atomic v1.5.1/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= +go.uber.org/multierr v1.4.0 h1:f3WCSC2KzAcBXGATIxAB1E2XuCpNU255wNKZ505qi3E= +go.uber.org/multierr v1.4.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= +go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU= +go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 h1:Gv7RPwsi3eZ2Fgewe3CBsuOebPwO27PoXzRpJPsvSSM= golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM= golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191116160921-f9c825593386 h1:ktbWvQrW08Txdxno1PiDpSxPXG6ndGsfnJjRRtkM0LQ= +golang.org/x/net v0.0.0-20191116160921-f9c825593386/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914 h1:MlY3mEfbnWGmUi4rtHOtNnnnN4UJRGSyLPx+DXA5Sq4= +golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -115,19 +265,51 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd h1:DBH9mDw0zluJT/R+nGuV3jWFWLFaHyYZWD4tOT+cjn0= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191118090420-b5d5184f72d2 h1:LEXoa2mfx+ZHKVuyzu3/fnknuCCoTfywJVHMkWECH3Y= +golang.org/x/sys v0.0.0-20191118090420-b5d5184f72d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191119195528-f068ffe820e4 h1:FjhQftcbpdYXneEYSWZO7+6Bu+Bi1A8VPvGYWOIzIbw= +golang.org/x/sys v0.0.0-20191119195528-f068ffe820e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191118051429-5a76f03bc7c3 h1:3gzOmNy3PLCZ+3Ru/n5Gh7pPjsieiytYSDxFj6QY/oI= +golang.org/x/tools v0.0.0-20191118051429-5a76f03bc7c3/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191120001058-ad01d5993d97 h1:u8hSFDulpuhoY0GHMbG6Rp23PzphtTnZrQX3dOvEae0= +golang.org/x/tools v0.0.0-20191120001058-ad01d5993d97/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.21.0 h1:G+97AoqBnmZIT91cLG/EkCoK9NSelj64P8bOHHNmGn0= +google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/h2non/gock.v1 v1.0.14/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/zeromq/goczmq.v4 v4.1.0 h1:CE+FE81mGVs2aSlnbfLuS1oAwdcVywyMM2AC1g33imI= gopkg.in/zeromq/goczmq.v4 v4.1.0/go.mod h1:h4IlfePEYMpFdywGr5gAwKhBBj+hiBl/nF4VoSE4k+0= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= diff --git a/packages/accountability/accountability.go b/packages/accountability/accountability.go index c8d66002a918d43cc4b79491f9d143fc4c2e7ec5..6eff4ddd1e69e85654f87b127cb596ae7a77e3a1 100644 --- a/packages/accountability/accountability.go +++ b/packages/accountability/accountability.go @@ -3,13 +3,15 @@ package accountability import ( "sync" - "github.com/iotaledger/goshimmer/packages/database" + "github.com/dgraph-io/badger" "github.com/iotaledger/goshimmer/packages/identity" "github.com/iotaledger/goshimmer/packages/settings" ) -var ownId *identity.Identity +// Name of the key under which the node identity is stored. +const identityKey = "IDENTITY" +var ownId *identity.Identity var lazyInit sync.Once func OwnId() *identity.Identity { @@ -23,13 +25,13 @@ func initOwnId() { } func generateNewIdentity() *identity.Identity { - newIdentity := identity.GenerateRandomIdentity() - if err := settings.Set([]byte("ACCOUNTABILITY_PUBLIC_KEY"), newIdentity.PublicKey); err != nil { - panic(err) - } + newIdentity := identity.GeneratePrivateIdentity() + + key := []byte(identityKey) + value := newIdentity.Marshal() - if err := settings.Set([]byte("ACCOUNTABILITY_PRIVATE_KEY"), newIdentity.PrivateKey); err != nil { + if err := settings.Set(key, value); err != nil { panic(err) } @@ -37,23 +39,21 @@ func generateNewIdentity() *identity.Identity { } func getIdentity() *identity.Identity { - publicKey, err := settings.Get([]byte("ACCOUNTABILITY_PUBLIC_KEY")) + key := []byte(identityKey) + + value, err := settings.Get(key) if err != nil { - if err == database.ErrKeyNotFound { + if err == badger.ErrKeyNotFound { return generateNewIdentity() } else { panic(err) } } - privateKey, err := settings.Get([]byte("ACCOUNTABILITY_PRIVATE_KEY")) + result, err := identity.Unmarshal(value) if err != nil { - if err == database.ErrKeyNotFound { - return generateNewIdentity() - } else { - panic(err) - } + panic(err) } - return identity.NewIdentity(publicKey, privateKey) + return result } diff --git a/packages/daemon/events.go b/packages/daemon/events.go index dd3953287de61468d50a613d8eb3b7d466474d56..256d4c43f44889a4512718763bd5ba427f16724c 100644 --- a/packages/daemon/events.go +++ b/packages/daemon/events.go @@ -1,7 +1,7 @@ package daemon import ( - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" ) var Events = struct { diff --git a/packages/identity/constants.go b/packages/identity/constants.go index e7440a45d085b8a9c8dbf4bfbe75e297c9fee5c2..0e23d6ede985f84190bf29282726a50d10eeef53 100644 --- a/packages/identity/constants.go +++ b/packages/identity/constants.go @@ -1,8 +1,20 @@ package identity +import "crypto/ed25519" + const ( - PRIVATE_TYPE = IdentityType(0) - PUBLIC_TYPE = IdentityType(1) + IDENTIFIER_BYTE_LENGTH = 20 + PUBLIC_KEY_BYTE_LENGTH = ed25519.PublicKeySize + SIGNATURE_BYTE_LENGTH = ed25519.PublicKeySize + ed25519.SignatureSize + + MARSHALED_IDENTITY_PUBLIC_KEY_START = 0 + MARSHALED_IDENTITY_PRIVATE_KEY_START = MARSHALED_IDENTITY_PUBLIC_KEY_END + + MARSHALED_IDENTITY_PUBLIC_KEY_SIZE = PUBLIC_KEY_BYTE_LENGTH + MARSHALED_IDENTITY_PRIVATE_KEY_SIZE = ed25519.PrivateKeySize + + MARSHALED_IDENTITY_PUBLIC_KEY_END = MARSHALED_IDENTITY_PUBLIC_KEY_START + MARSHALED_IDENTITY_PUBLIC_KEY_SIZE + MARSHALED_IDENTITY_PRIVATE_KEY_END = MARSHALED_IDENTITY_PRIVATE_KEY_START + MARSHALED_IDENTITY_PRIVATE_KEY_SIZE - PUBLIC_KEY_BYTE_LENGTH = 65 + MARSHALED_IDENTITY_TOTAL_SIZE = MARSHALED_IDENTITY_PRIVATE_KEY_END ) diff --git a/packages/identity/errors.go b/packages/identity/errors.go new file mode 100644 index 0000000000000000000000000000000000000000..60f5d59b12356acd5153808fe10f9546e7116e1e --- /dev/null +++ b/packages/identity/errors.go @@ -0,0 +1,8 @@ +package identity + +import "errors" + +var ( + ErrInvalidDataLen = errors.New("identity: invalid input data length") + ErrInvalidSignature = errors.New("identity: invalid signature") +) diff --git a/packages/identity/identity.go b/packages/identity/identity.go index 022af162586fa9bd2e66d406c15697bd3ed39891..14fc16fa9f15d0e1d10e86ca2cdab3fb7973d212 100644 --- a/packages/identity/identity.go +++ b/packages/identity/identity.go @@ -1,89 +1,120 @@ package identity import ( - "crypto/ecdsa" - "crypto/elliptic" - "crypto/rand" + "crypto/ed25519" "crypto/sha256" - "fmt" + "encoding/hex" - "github.com/ethereum/go-ethereum/crypto/secp256k1" - "github.com/iotaledger/goshimmer/packages/crypto" + "github.com/iotaledger/autopeering-sim/peer" ) type Identity struct { - Type IdentityType - Identifier []byte + Identifier peer.ID StringIdentifier string - PublicKey []byte - PrivateKey []byte + PublicKey ed25519.PublicKey + privateKey ed25519.PrivateKey } -func NewIdentity(publicKey []byte, optionalPrivateKey ...[]byte) *Identity { - this := &Identity{ - Identifier: crypto.Hash20(publicKey), - PublicKey: make([]byte, len(publicKey)), +// Creates a new identity based on the given public key. +func NewPublicIdentity(publicKey ed25519.PublicKey) *Identity { + identifier := sha256.Sum256(publicKey) + + return &Identity{ + Identifier: identifier, + StringIdentifier: hex.EncodeToString(identifier[:8]), + PublicKey: publicKey, + privateKey: nil, } +} + +// Generates a identity based on a newly generated public/private key pair. +// It will panic if no such pair could be generated. +func GeneratePrivateIdentity() *Identity { + publicKey, privateKey, err := ed25519.GenerateKey(nil) + if err != nil { + panic("identity: failed generating key: " + err.Error()) + } + + return newPrivateIdentity(publicKey, privateKey) +} - copy(this.PublicKey, publicKey) +// Sign signs the message with privateKey and returns the message plus the signature. +func (id *Identity) AddSignature(msg []byte) []byte { + signatureStart := len(msg) - this.StringIdentifier = fmt.Sprintf("%x", this.Identifier) + signature := ed25519.Sign(id.privateKey, msg) - if len(optionalPrivateKey) == 1 { - this.Type = PRIVATE_TYPE - this.PrivateKey = optionalPrivateKey[0] - } else { - this.Type = PUBLIC_TYPE + data := make([]byte, signatureStart+SIGNATURE_BYTE_LENGTH) + + copy(data[:signatureStart], msg) + + // add public key and signature + copy(data[signatureStart:signatureStart+ed25519.PublicKeySize], id.PublicKey) + copy(data[signatureStart+ed25519.PublicKeySize:], signature) + + return data +} + +// Verifies whether the data contains a valid signature of the message. +func (id *Identity) VerifySignature(data []byte) error { + signatureStart := len(data) - SIGNATURE_BYTE_LENGTH + if signatureStart <= 0 { + return ErrInvalidDataLen } - return this + msg := data[:signatureStart] + + // ignore the public key + sig := data[signatureStart+ed25519.PublicKeySize:] + + if !ed25519.Verify(id.PublicKey, msg, sig) { + return ErrInvalidSignature + } + + return nil } -func (this *Identity) Sign(data []byte) ([]byte, error) { - sha256Hasher := sha256.New() - sha256Hasher.Write(data) +// Returns the identitiy derived from the signed message. +func FromSignedData(data []byte) (*Identity, error) { + signatureStart := len(data) - SIGNATURE_BYTE_LENGTH + if signatureStart <= 0 { + return nil, ErrInvalidDataLen + } - sig, err := secp256k1.Sign(sha256Hasher.Sum(nil), this.PrivateKey) - if err != nil { + pubKey := data[signatureStart : signatureStart+ed25519.PublicKeySize] + + identity := NewPublicIdentity(pubKey) + if err := identity.VerifySignature(data); err != nil { return nil, err } - return sig, nil + return identity, nil } -func (this *Identity) VerifySignature(data []byte, signature []byte) bool { - sha256Hasher := sha256.New() - sha256Hasher.Write(data) +func (id *Identity) Marshal() []byte { + data := make([]byte, MARSHALED_IDENTITY_TOTAL_SIZE) - return secp256k1.VerifySignature(this.PublicKey, sha256Hasher.Sum(nil), signature[:64]) + copy(data[MARSHALED_IDENTITY_PUBLIC_KEY_START:MARSHALED_IDENTITY_PUBLIC_KEY_END], id.PublicKey) + copy(data[MARSHALED_IDENTITY_PRIVATE_KEY_START:MARSHALED_IDENTITY_PRIVATE_KEY_END], id.privateKey) + + return data } -func GenerateRandomIdentity() *Identity { - // generate key pair - keyPair, err := ecdsa.GenerateKey(secp256k1.S256(), rand.Reader) - if err != nil { - panic(err) +func Unmarshal(data []byte) (*Identity, error) { + if len(data) != MARSHALED_IDENTITY_TOTAL_SIZE { + return nil, ErrInvalidDataLen } - // build public key bytes - publicKey := elliptic.Marshal(secp256k1.S256(), keyPair.X, keyPair.Y) - - // build private key bytes - privkey := make([]byte, 32) - blob := keyPair.D.Bytes() - copy(privkey[32-len(blob):], blob) + publicKey := data[MARSHALED_IDENTITY_PUBLIC_KEY_START:MARSHALED_IDENTITY_PUBLIC_KEY_END] + privateKey := data[MARSHALED_IDENTITY_PRIVATE_KEY_START:MARSHALED_IDENTITY_PRIVATE_KEY_END] - return NewIdentity(publicKey, privkey) + return newPrivateIdentity(publicKey, privateKey), nil } -func FromSignedData(data []byte, signature []byte) (*Identity, error) { - sha256Hasher := sha256.New() - sha256Hasher.Write(data) +func newPrivateIdentity(publicKey []byte, privateKey []byte) *Identity { - pubKey, err := secp256k1.RecoverPubkey(sha256Hasher.Sum(nil), signature) - if err != nil { - return nil, err - } + identity := NewPublicIdentity(publicKey) + identity.privateKey = privateKey - return NewIdentity(pubKey), nil + return identity } diff --git a/packages/network/events.go b/packages/network/events.go index 0096c1b59f36ce2fe4fa350ce774a6f26eed7c80..7903376b6b4b18ad7622707354bea038ad235ce6 100644 --- a/packages/network/events.go +++ b/packages/network/events.go @@ -1,7 +1,7 @@ package network import ( - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" ) type BufferedConnectionEvents struct { diff --git a/packages/network/managed_connection.go b/packages/network/managed_connection.go index 30b48a894cd6cfdc10933fce3aa61731edf2b962..012a59d8a7134e3411971ab5635b457819cbeaf4 100644 --- a/packages/network/managed_connection.go +++ b/packages/network/managed_connection.go @@ -6,7 +6,7 @@ import ( "sync" "time" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" ) type ManagedConnection struct { diff --git a/packages/network/tcp/server.go b/packages/network/tcp/server.go index 67b70b26a8744075ac7afc49836b1ddf359711f9..5bef906f4da85a47e81c30a0c460222b90a2f03c 100644 --- a/packages/network/tcp/server.go +++ b/packages/network/tcp/server.go @@ -5,7 +5,7 @@ import ( "strconv" "sync" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/network" ) diff --git a/packages/network/tcp/server_events.go b/packages/network/tcp/server_events.go index b5f3fbbeabf7b710b517a2984abc828171dda41b..3ce91184bdcc5ea37d3953f9b05e37dcb652f16e 100644 --- a/packages/network/tcp/server_events.go +++ b/packages/network/tcp/server_events.go @@ -1,7 +1,7 @@ package tcp import ( - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/network" ) diff --git a/packages/network/udp/events.go b/packages/network/udp/events.go index dc797d0e5caebe5d6a136b36d3aa609aabad1c76..590c6c256b07500a11f109e7d406717de6cca1a9 100644 --- a/packages/network/udp/events.go +++ b/packages/network/udp/events.go @@ -3,7 +3,7 @@ package udp import ( "net" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" ) type serverEvents struct { diff --git a/packages/network/udp/server.go b/packages/network/udp/server.go index 3c77a0e8ab0227803ef5e0f69d7d7313fb8c7fd8..00fe86864cc01c3f31cdf7cb14d9e64444213714 100644 --- a/packages/network/udp/server.go +++ b/packages/network/udp/server.go @@ -5,7 +5,7 @@ import ( "strconv" "sync" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" ) type Server struct { diff --git a/packages/node/events.go b/packages/node/events.go index 4b5a8e80d1d915e40fa7932a28cc09966a969ed8..820be882c8c2ff6b1e394a754824bbd572c27198 100644 --- a/packages/node/events.go +++ b/packages/node/events.go @@ -1,7 +1,7 @@ package node import ( - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" ) type pluginEvents struct { diff --git a/packages/node/plugin.go b/packages/node/plugin.go index bb7efa8494c53492686f30877b9413398f33565f..c7d1af3d5fa10dcb00d54db31485a3ad6bd5eef7 100644 --- a/packages/node/plugin.go +++ b/packages/node/plugin.go @@ -4,7 +4,7 @@ import ( "strings" "sync" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/parameter" ) diff --git a/packages/parameter/events.go b/packages/parameter/events.go index b755a038485a09e01eb0c20ddd9ceaa2496dc7ab..dea861ea56b92e25c07bb34f6270bba280cee459 100644 --- a/packages/parameter/events.go +++ b/packages/parameter/events.go @@ -1,7 +1,7 @@ package parameter import ( - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" ) var Events = struct { diff --git a/plugins/analysis/client/plugin.go b/plugins/analysis/client/plugin.go index 7bd42836dcc54850451676065c3c5eefa672b63c..fa7099e65250f83acc62b113f98ba9d41b739b8d 100644 --- a/plugins/analysis/client/plugin.go +++ b/plugins/analysis/client/plugin.go @@ -4,9 +4,10 @@ import ( "net" "time" + "github.com/iotaledger/autopeering-sim/discover" + "github.com/iotaledger/autopeering-sim/selection" "github.com/iotaledger/goshimmer/packages/accountability" "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/events" "github.com/iotaledger/goshimmer/packages/network" "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/timeutil" @@ -14,10 +15,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/analysis/types/connectnodes" "github.com/iotaledger/goshimmer/plugins/analysis/types/disconnectnodes" "github.com/iotaledger/goshimmer/plugins/analysis/types/ping" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" + "github.com/iotaledger/hive.go/events" ) func Run(plugin *node.Plugin) { @@ -63,7 +61,7 @@ func getEventDispatchers(conn *network.ManagedConnection) *EventDispatchers { } func reportCurrentStatus(eventDispatchers *EventDispatchers) { - eventDispatchers.AddNode(accountability.OwnId().Identifier) + eventDispatchers.AddNode(accountability.OwnId().Identifier.Bytes()) reportChosenNeighbors(eventDispatchers) } @@ -71,43 +69,38 @@ func reportCurrentStatus(eventDispatchers *EventDispatchers) { func setupHooks(conn *network.ManagedConnection, eventDispatchers *EventDispatchers) { // define hooks //////////////////////////////////////////////////////////////////////////////////////////////////// - onDiscoverPeer := events.NewClosure(func(p *peer.Peer) { - go eventDispatchers.AddNode(p.GetIdentity().Identifier) + onDiscoverPeer := events.NewClosure(func(ev *discover.DiscoveredEvent) { + go eventDispatchers.AddNode(ev.Peer.ID().Bytes()) }) - onAddAcceptedNeighbor := events.NewClosure(func(p *peer.Peer) { - eventDispatchers.ConnectNodes(p.GetIdentity().Identifier, accountability.OwnId().Identifier) + onAddAcceptedNeighbor := events.NewClosure(func(ev *selection.PeeringEvent) { + eventDispatchers.ConnectNodes(ev.Peer.ID().Bytes(), accountability.OwnId().Identifier.Bytes()) }) - onRemoveAcceptedNeighbor := events.NewClosure(func(p *peer.Peer) { - eventDispatchers.DisconnectNodes(p.GetIdentity().Identifier, accountability.OwnId().Identifier) + onRemoveNeighbor := events.NewClosure(func(ev *selection.DroppedEvent) { + eventDispatchers.DisconnectNodes(ev.DroppedID.Bytes(), accountability.OwnId().Identifier.Bytes()) + eventDispatchers.DisconnectNodes(accountability.OwnId().Identifier.Bytes(), ev.DroppedID.Bytes()) }) - onAddChosenNeighbor := events.NewClosure(func(p *peer.Peer) { - eventDispatchers.ConnectNodes(accountability.OwnId().Identifier, p.GetIdentity().Identifier) - }) - - onRemoveChosenNeighbor := events.NewClosure(func(p *peer.Peer) { - eventDispatchers.DisconnectNodes(accountability.OwnId().Identifier, p.GetIdentity().Identifier) + onAddChosenNeighbor := events.NewClosure(func(ev *selection.PeeringEvent) { + eventDispatchers.ConnectNodes(accountability.OwnId().Identifier.Bytes(), ev.Peer.ID().Bytes()) }) // setup hooks ///////////////////////////////////////////////////////////////////////////////////////////////////// - knownpeers.INSTANCE.Events.Add.Attach(onDiscoverPeer) - acceptedneighbors.INSTANCE.Events.Add.Attach(onAddAcceptedNeighbor) - acceptedneighbors.INSTANCE.Events.Remove.Attach(onRemoveAcceptedNeighbor) - chosenneighbors.INSTANCE.Events.Add.Attach(onAddChosenNeighbor) - chosenneighbors.INSTANCE.Events.Remove.Attach(onRemoveChosenNeighbor) + discover.Events.PeerDiscovered.Attach(onDiscoverPeer) + selection.Events.IncomingPeering.Attach(onAddAcceptedNeighbor) + selection.Events.OutgoingPeering.Attach(onAddChosenNeighbor) + selection.Events.Dropped.Attach(onRemoveNeighbor) // clean up hooks on close ///////////////////////////////////////////////////////////////////////////////////////// var onClose *events.Closure onClose = events.NewClosure(func() { - knownpeers.INSTANCE.Events.Add.Detach(onDiscoverPeer) - acceptedneighbors.INSTANCE.Events.Add.Detach(onAddAcceptedNeighbor) - acceptedneighbors.INSTANCE.Events.Remove.Detach(onRemoveAcceptedNeighbor) - chosenneighbors.INSTANCE.Events.Add.Detach(onAddChosenNeighbor) - chosenneighbors.INSTANCE.Events.Remove.Detach(onRemoveChosenNeighbor) + discover.Events.PeerDiscovered.Detach(onDiscoverPeer) + selection.Events.IncomingPeering.Detach(onAddAcceptedNeighbor) + selection.Events.OutgoingPeering.Detach(onAddChosenNeighbor) + selection.Events.Dropped.Detach(onRemoveNeighbor) conn.Events.Close.Detach(onClose) }) @@ -115,12 +108,12 @@ func setupHooks(conn *network.ManagedConnection, eventDispatchers *EventDispatch } func reportChosenNeighbors(dispatchers *EventDispatchers) { - for _, chosenNeighbor := range chosenneighbors.INSTANCE.Peers.GetMap() { - dispatchers.AddNode(chosenNeighbor.GetIdentity().Identifier) - } - for _, chosenNeighbor := range chosenneighbors.INSTANCE.Peers.GetMap() { - dispatchers.ConnectNodes(accountability.OwnId().Identifier, chosenNeighbor.GetIdentity().Identifier) - } + // for _, chosenNeighbor := range chosenneighbors.INSTANCE.Peers.GetMap() { + // dispatchers.AddNode(chosenNeighbor.GetIdentity().Identifier) + // } + // for _, chosenNeighbor := range chosenneighbors.INSTANCE.Peers.GetMap() { + // dispatchers.ConnectNodes(accountability.OwnId().Identifier, chosenNeighbor.GetIdentity().Identifier) + // } } func keepConnectionAlive(conn *network.ManagedConnection) bool { diff --git a/plugins/analysis/plugin.go b/plugins/analysis/plugin.go index 44268dd0c077025e796cea7df2c859ef74f78061..54ca295475b564dfb6f046db076f70917951dc5e 100644 --- a/plugins/analysis/plugin.go +++ b/plugins/analysis/plugin.go @@ -2,7 +2,7 @@ package analysis import ( "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/analysis/client" "github.com/iotaledger/goshimmer/plugins/analysis/server" diff --git a/plugins/analysis/server/events.go b/plugins/analysis/server/events.go index e66359ff38a60031c0c12e9e1cf30314704c176d..979dddec563888fc68a2c18a572a8f3f83741d83 100644 --- a/plugins/analysis/server/events.go +++ b/plugins/analysis/server/events.go @@ -1,7 +1,7 @@ package server import ( - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" ) var Events = struct { diff --git a/plugins/analysis/server/plugin.go b/plugins/analysis/server/plugin.go index cbcbb7259b81acf2e4177bc91fa4a7435b321363..36b8670843301df53fe39bc011c7e6a276d7a4a3 100644 --- a/plugins/analysis/server/plugin.go +++ b/plugins/analysis/server/plugin.go @@ -6,7 +6,7 @@ import ( "strconv" "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/network" "github.com/iotaledger/goshimmer/packages/network/tcp" "github.com/iotaledger/goshimmer/packages/node" diff --git a/plugins/analysis/webinterface/httpserver/data_stream.go b/plugins/analysis/webinterface/httpserver/data_stream.go index 66f611279705543af71733b10c1aa6a54fcc5ea0..2548064908015efa85319a6bbb0e7c96340d8276 100644 --- a/plugins/analysis/webinterface/httpserver/data_stream.go +++ b/plugins/analysis/webinterface/httpserver/data_stream.go @@ -3,7 +3,7 @@ package httpserver import ( "fmt" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/plugins/analysis/server" "github.com/iotaledger/goshimmer/plugins/analysis/webinterface/recordedevents" "github.com/iotaledger/goshimmer/plugins/analysis/webinterface/types" diff --git a/plugins/analysis/webinterface/httpserver/plugin.go b/plugins/analysis/webinterface/httpserver/plugin.go index a6b62cbb12f33087fbdf7e58b2b2eb2dfacd8833..a7c8daf9ff6ca2cfa8eac097d3c84eaba821e511 100644 --- a/plugins/analysis/webinterface/httpserver/plugin.go +++ b/plugins/analysis/webinterface/httpserver/plugin.go @@ -5,7 +5,7 @@ import ( "time" "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/node" "golang.org/x/net/context" "golang.org/x/net/websocket" diff --git a/plugins/analysis/webinterface/recordedevents/recorded_events.go b/plugins/analysis/webinterface/recordedevents/recorded_events.go index 3110aa6a70614faaf0a066e7f2aa0588d51d7b50..882696997bd0d5223a6701bd094685cd166950dc 100644 --- a/plugins/analysis/webinterface/recordedevents/recorded_events.go +++ b/plugins/analysis/webinterface/recordedevents/recorded_events.go @@ -3,7 +3,7 @@ package recordedevents import ( "sync" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/analysis/server" "github.com/iotaledger/goshimmer/plugins/analysis/webinterface/types" diff --git a/plugins/autopeering/autopeering.go b/plugins/autopeering/autopeering.go new file mode 100644 index 0000000000000000000000000000000000000000..bd0ae9ef4bf8bee0728794137f40f8621320ba27 --- /dev/null +++ b/plugins/autopeering/autopeering.go @@ -0,0 +1,138 @@ +package autopeering + +import ( + "encoding/base64" + "fmt" + "log" + "net" + "strings" + + "github.com/iotaledger/autopeering-sim/discover" + "github.com/iotaledger/autopeering-sim/logger" + "github.com/iotaledger/autopeering-sim/peer" + "github.com/iotaledger/autopeering-sim/selection" + "github.com/iotaledger/autopeering-sim/server" + "github.com/iotaledger/autopeering-sim/transport" + "github.com/iotaledger/goshimmer/packages/errors" + "github.com/iotaledger/goshimmer/packages/node" +) + +var ( + PLUGIN = node.NewPlugin("Auto Peering", node.Enabled, configure, run) + close = make(chan struct{}, 1) + srv *server.Server + Discovery *discover.Protocol + Selection *selection.Protocol +) + +const defaultZLC = `{ + "level": "info", + "development": false, + "outputPaths": ["stdout"], + "errorOutputPaths": ["stderr"], + "encoding": "console", + "encoderConfig": { + "timeKey": "ts", + "levelKey": "level", + "nameKey": "logger", + "callerKey": "caller", + "messageKey": "msg", + "stacktraceKey": "stacktrace", + "lineEnding": "", + "levelEncoder": "", + "timeEncoder": "iso8601", + "durationEncoder": "", + "callerEncoder": "" + } + }` + +func start() { + var ( + listenAddr = "127.0.0.1:14626" //flag.String("addr", "127.0.0.1:14626", "listen address") + gossipAddr = "127.0.0.1:14666" + masterPeer = "" //flag.String("master", "", "master node as 'pubKey@address' where pubKey is in Base64") + + err error + ) + // flag.Parse() + + logger := logger.NewLogger(defaultZLC, "debug") + defer func() { _ = logger.Sync() }() // ignore the returned error + + addr, err := net.ResolveUDPAddr("udp", listenAddr) + if err != nil { + log.Fatalf("ResolveUDPAddr: %v", err) + } + conn, err := net.ListenUDP("udp", addr) + if err != nil { + log.Fatalf("ListenUDP: %v", err) + } + defer conn.Close() + + var masterPeers []*peer.Peer + master, err := parseMaster(masterPeer) + if err != nil { + log.Printf("Ignoring master: %v\n", err) + } else if master != nil { + masterPeers = []*peer.Peer{master} + } + + // use the UDP connection for transport + trans := transport.Conn(conn, func(network, address string) (net.Addr, error) { return net.ResolveUDPAddr(network, address) }) + defer trans.Close() + + // create a new local node + db := peer.NewPersistentDB(logger.Named("db")) + defer db.Close() + local, err := peer.NewLocal(db) + if err != nil { + log.Fatalf("ListenUDP: %v", err) + } + // add a service for the peering + local.Services()["peering"] = peer.NetworkAddress{Network: "udp", Address: listenAddr} + // add a service for the gossip + local.Services()["gossip"] = peer.NetworkAddress{Network: "tcp", Address: gossipAddr} + + Discovery = discover.New(local, discover.Config{ + Log: logger.Named("disc"), + MasterPeers: masterPeers, + }) + Selection = selection.New(local, Discovery, selection.Config{ + Log: logger.Named("sel"), + SaltLifetime: selection.DefaultSaltLifetime, + }) + + // start a server doing discovery and peering + srv = server.Listen(local, trans, logger.Named("srv"), Discovery, Selection) + defer srv.Close() + + // start the discovery on that connection + Discovery.Start(srv) + defer Discovery.Close() + + // start the peering on that connection + Selection.Start(srv) + defer Selection.Close() + + id := base64.StdEncoding.EncodeToString(local.PublicKey()) + fmt.Println("Discovery protocol started: ID=" + id + ", address=" + srv.LocalAddr()) + + <-close +} + +func parseMaster(s string) (*peer.Peer, error) { + if len(s) == 0 { + return nil, nil + } + + parts := strings.Split(s, "@") + if len(parts) != 2 { + return nil, errors.New("parseMaster") + } + pubKey, err := base64.StdEncoding.DecodeString(parts[0]) + if err != nil { + return nil, errors.Wrap(err, "parseMaster") + } + + return peer.NewPeer(pubKey, parts[1]), nil +} diff --git a/plugins/autopeering/instances/acceptedneighbors/distance.go b/plugins/autopeering/instances/acceptedneighbors/distance.go deleted file mode 100644 index b2b8dae55a8f736d5ddcead0daa56db561a49f34..0000000000000000000000000000000000000000 --- a/plugins/autopeering/instances/acceptedneighbors/distance.go +++ /dev/null @@ -1,32 +0,0 @@ -package acceptedneighbors - -import ( - "hash/fnv" - - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/ownpeer" - "github.com/iotaledger/goshimmer/plugins/autopeering/saltmanager" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" -) - -var DISTANCE = func(anchor *peer.Peer) func(p *peer.Peer) uint64 { - return func(p *peer.Peer) uint64 { - saltedIdentifier := make([]byte, len(anchor.GetIdentity().Identifier)+len(saltmanager.PRIVATE_SALT.GetBytes())) - copy(saltedIdentifier[0:], anchor.GetIdentity().Identifier) - copy(saltedIdentifier[len(anchor.GetIdentity().Identifier):], saltmanager.PRIVATE_SALT.GetBytes()) - - return hash(saltedIdentifier) ^ hash(p.GetIdentity().Identifier) - } -} - -var OWN_DISTANCE func(p *peer.Peer) uint64 - -func configureOwnDistance() { - OWN_DISTANCE = DISTANCE(ownpeer.INSTANCE) -} - -func hash(data []byte) uint64 { - h := fnv.New64a() - h.Write(data) - - return h.Sum64() -} diff --git a/plugins/autopeering/instances/acceptedneighbors/furthest_neighbor.go b/plugins/autopeering/instances/acceptedneighbors/furthest_neighbor.go deleted file mode 100644 index 201b4827b10850d3428018df71127a29f4ff9587..0000000000000000000000000000000000000000 --- a/plugins/autopeering/instances/acceptedneighbors/furthest_neighbor.go +++ /dev/null @@ -1,45 +0,0 @@ -package acceptedneighbors - -import ( - "sync" - - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" -) - -var FURTHEST_NEIGHBOR *peer.Peer - -var FURTHEST_NEIGHBOR_DISTANCE = uint64(0) - -var FurthestNeighborLock sync.RWMutex - -func configureFurthestNeighbor() { - INSTANCE.Events.Add.Attach(events.NewClosure(func(p *peer.Peer) { - FurthestNeighborLock.Lock() - defer FurthestNeighborLock.Unlock() - - updateFurthestNeighbor(p) - })) - - INSTANCE.Events.Remove.Attach(events.NewClosure(func(p *peer.Peer) { - FurthestNeighborLock.Lock() - defer FurthestNeighborLock.Unlock() - - if p.GetIdentity().StringIdentifier == FURTHEST_NEIGHBOR.GetIdentity().StringIdentifier { - FURTHEST_NEIGHBOR_DISTANCE = uint64(0) - FURTHEST_NEIGHBOR = nil - - for _, furthestNeighborCandidate := range INSTANCE.Peers.GetMap() { - updateFurthestNeighbor(furthestNeighborCandidate) - } - } - })) -} - -func updateFurthestNeighbor(p *peer.Peer) { - distance := OWN_DISTANCE(p) - if distance > FURTHEST_NEIGHBOR_DISTANCE { - FURTHEST_NEIGHBOR = p - FURTHEST_NEIGHBOR_DISTANCE = distance - } -} diff --git a/plugins/autopeering/instances/acceptedneighbors/instance.go b/plugins/autopeering/instances/acceptedneighbors/instance.go deleted file mode 100644 index 1990c8a3a0093214595d86738a749b7579d08155..0000000000000000000000000000000000000000 --- a/plugins/autopeering/instances/acceptedneighbors/instance.go +++ /dev/null @@ -1,5 +0,0 @@ -package acceptedneighbors - -import "github.com/iotaledger/goshimmer/plugins/autopeering/types/peerregister" - -var INSTANCE = peerregister.New() diff --git a/plugins/autopeering/instances/acceptedneighbors/plugin.go b/plugins/autopeering/instances/acceptedneighbors/plugin.go deleted file mode 100644 index 9870c182bb37f7d7e3cb5dd8c6a58d5c6086ffc8..0000000000000000000000000000000000000000 --- a/plugins/autopeering/instances/acceptedneighbors/plugin.go +++ /dev/null @@ -1,8 +0,0 @@ -package acceptedneighbors - -import "github.com/iotaledger/goshimmer/packages/node" - -func Configure(plugin *node.Plugin) { - configureOwnDistance() - configureFurthestNeighbor() -} diff --git a/plugins/autopeering/instances/chosenneighbors/candidates.go b/plugins/autopeering/instances/chosenneighbors/candidates.go deleted file mode 100644 index a993e5adc601cc1cfb263766a50bf0409fb5d944..0000000000000000000000000000000000000000 --- a/plugins/autopeering/instances/chosenneighbors/candidates.go +++ /dev/null @@ -1,20 +0,0 @@ -package chosenneighbors - -import ( - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/neighborhood" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/ownpeer" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peerlist" -) - -var CANDIDATES *peerlist.PeerList - -func configureCandidates() { - CANDIDATES = peerlist.NewPeerList() - updateNeighborCandidates() - - neighborhood.Events.Update.Attach(updateNeighborCandidates) -} - -func updateNeighborCandidates() { - CANDIDATES.Update(neighborhood.LIST_INSTANCE.Sort(DISTANCE(ownpeer.INSTANCE)).GetPeers()) -} diff --git a/plugins/autopeering/instances/chosenneighbors/distance.go b/plugins/autopeering/instances/chosenneighbors/distance.go deleted file mode 100644 index 384e29ca279f1f26f58e4c09ee6a61f641ed85cc..0000000000000000000000000000000000000000 --- a/plugins/autopeering/instances/chosenneighbors/distance.go +++ /dev/null @@ -1,31 +0,0 @@ -package chosenneighbors - -import ( - "hash/fnv" - - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/ownpeer" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" -) - -var DISTANCE = func(anchor *peer.Peer) func(p *peer.Peer) uint64 { - return func(p *peer.Peer) uint64 { - saltedIdentifier := make([]byte, len(anchor.GetIdentity().Identifier)+len(anchor.GetSalt().GetBytes())) - copy(saltedIdentifier[0:], anchor.GetIdentity().Identifier) - copy(saltedIdentifier[len(anchor.GetIdentity().Identifier):], anchor.GetSalt().GetBytes()) - - return hash(anchor.GetIdentity().Identifier) ^ hash(p.GetIdentity().Identifier) - } -} - -var OWN_DISTANCE func(p *peer.Peer) uint64 - -func configureOwnDistance() { - OWN_DISTANCE = DISTANCE(ownpeer.INSTANCE) -} - -func hash(data []byte) uint64 { - h := fnv.New64a() - h.Write(data) - - return h.Sum64() -} diff --git a/plugins/autopeering/instances/chosenneighbors/furthest_neighbor.go b/plugins/autopeering/instances/chosenneighbors/furthest_neighbor.go deleted file mode 100644 index 5040a89af97296fab70e09033b4af174e36e7508..0000000000000000000000000000000000000000 --- a/plugins/autopeering/instances/chosenneighbors/furthest_neighbor.go +++ /dev/null @@ -1,45 +0,0 @@ -package chosenneighbors - -import ( - "sync" - - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" -) - -var FURTHEST_NEIGHBOR *peer.Peer - -var FURTHEST_NEIGHBOR_DISTANCE = uint64(0) - -var FurthestNeighborLock sync.RWMutex - -func configureFurthestNeighbor() { - INSTANCE.Events.Add.Attach(events.NewClosure(func(p *peer.Peer) { - FurthestNeighborLock.Lock() - defer FurthestNeighborLock.Unlock() - - distance := OWN_DISTANCE(p) - if distance > FURTHEST_NEIGHBOR_DISTANCE { - FURTHEST_NEIGHBOR = p - FURTHEST_NEIGHBOR_DISTANCE = distance - } - })) - - INSTANCE.Events.Remove.Attach(events.NewClosure(func(p *peer.Peer) { - FurthestNeighborLock.Lock() - defer FurthestNeighborLock.Unlock() - - if p == FURTHEST_NEIGHBOR { - FURTHEST_NEIGHBOR_DISTANCE = uint64(0) - FURTHEST_NEIGHBOR = nil - - for _, furthestNeighborCandidate := range INSTANCE.Peers.GetMap() { - distance := OWN_DISTANCE(furthestNeighborCandidate) - if distance > FURTHEST_NEIGHBOR_DISTANCE { - FURTHEST_NEIGHBOR = furthestNeighborCandidate - FURTHEST_NEIGHBOR_DISTANCE = distance - } - } - } - })) -} diff --git a/plugins/autopeering/instances/chosenneighbors/instance.go b/plugins/autopeering/instances/chosenneighbors/instance.go deleted file mode 100644 index c7deb649fbd30df93db2af6ca85555cb2a159839..0000000000000000000000000000000000000000 --- a/plugins/autopeering/instances/chosenneighbors/instance.go +++ /dev/null @@ -1,5 +0,0 @@ -package chosenneighbors - -import "github.com/iotaledger/goshimmer/plugins/autopeering/types/peerregister" - -var INSTANCE = peerregister.New() diff --git a/plugins/autopeering/instances/chosenneighbors/plugin.go b/plugins/autopeering/instances/chosenneighbors/plugin.go deleted file mode 100644 index 0e1224fc75ae8dbb594d1938d14c442e04832214..0000000000000000000000000000000000000000 --- a/plugins/autopeering/instances/chosenneighbors/plugin.go +++ /dev/null @@ -1,11 +0,0 @@ -package chosenneighbors - -import ( - "github.com/iotaledger/goshimmer/packages/node" -) - -func Configure(plugin *node.Plugin) { - configureCandidates() - configureOwnDistance() - configureFurthestNeighbor() -} diff --git a/plugins/autopeering/instances/entrynodes/instance.go b/plugins/autopeering/instances/entrynodes/instance.go deleted file mode 100644 index 31e94076f4334b7cbf86be104e7a568f83ef5b17..0000000000000000000000000000000000000000 --- a/plugins/autopeering/instances/entrynodes/instance.go +++ /dev/null @@ -1,83 +0,0 @@ -package entrynodes - -import ( - "encoding/hex" - "net" - "strconv" - "strings" - - "github.com/iotaledger/goshimmer/packages/identity" - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/plugins/autopeering/parameters" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peerlist" -) - -var INSTANCE *peerlist.PeerList - -func Configure(node *node.Plugin) { - INSTANCE = parseEntryNodes() -} - -func parseEntryNodes() *peerlist.PeerList { - result := peerlist.NewPeerList() - - for _, entryNodeDefinition := range strings.Fields(*parameters.ENTRY_NODES.Value) { - if entryNodeDefinition == "" { - continue - } - - entryNode := &peer.Peer{} - - identityBits := strings.Split(entryNodeDefinition, "@") - if len(identityBits) != 2 { - panic("error while parsing identity of entry node: " + entryNodeDefinition) - } - if decodedIdentifier, err := hex.DecodeString(identityBits[0]); err != nil { - panic("error while parsing identity of entry node: " + entryNodeDefinition) - } else { - entryNode.SetIdentity(&identity.Identity{ - Identifier: decodedIdentifier, - StringIdentifier: identityBits[0], - }) - } - - addressBits := strings.Split(identityBits[1], ":") - switch len(addressBits) { - case 2: - host := addressBits[0] - port, err := strconv.Atoi(addressBits[1]) - if err != nil { - panic("error while parsing port of entry in list of entry nodes") - } - - ip := net.ParseIP(host) - if ip == nil { - panic("error while parsing ip of entry in list of entry nodes") - } - - entryNode.SetAddress(ip) - entryNode.SetPeeringPort(uint16(port)) - case 6: - host := strings.Join(addressBits[:5], ":") - port, err := strconv.Atoi(addressBits[5]) - if err != nil { - panic("error while parsing port of entry in list of entry nodes") - } - - ip := net.ParseIP(host) - if ip == nil { - panic("error while parsing ip of entry in list of entry nodes") - } - - entryNode.SetAddress(ip) - entryNode.SetPeeringPort(uint16(port)) - default: - panic("invalid entry in list of trusted entry nodes: " + entryNodeDefinition) - } - - result.AddPeer(entryNode) - } - - return result -} diff --git a/plugins/autopeering/instances/knownpeers/instance.go b/plugins/autopeering/instances/knownpeers/instance.go deleted file mode 100644 index 1cf3c56db76628059af51a96ca4072e2752dfef6..0000000000000000000000000000000000000000 --- a/plugins/autopeering/instances/knownpeers/instance.go +++ /dev/null @@ -1,22 +0,0 @@ -package knownpeers - -import ( - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/entrynodes" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peerregister" -) - -var INSTANCE *peerregister.PeerRegister - -func Configure(plugin *node.Plugin) { - INSTANCE = initKnownPeers() -} - -func initKnownPeers() *peerregister.PeerRegister { - knownPeers := peerregister.New() - for _, entryNode := range entrynodes.INSTANCE.GetPeers() { - knownPeers.AddOrUpdate(entryNode) - } - - return knownPeers -} diff --git a/plugins/autopeering/instances/neighborhood/events.go b/plugins/autopeering/instances/neighborhood/events.go deleted file mode 100644 index b748822f6067a9cd1317e1e9407556d8b616dd90..0000000000000000000000000000000000000000 --- a/plugins/autopeering/instances/neighborhood/events.go +++ /dev/null @@ -1,31 +0,0 @@ -package neighborhood - -import "reflect" - -var Events = moduleEvents{ - Update: &callbackEvent{make(map[uintptr]Callback)}, -} - -type moduleEvents struct { - Update *callbackEvent -} - -type callbackEvent struct { - callbacks map[uintptr]Callback -} - -func (this *callbackEvent) Attach(callback Callback) { - this.callbacks[reflect.ValueOf(callback).Pointer()] = callback -} - -func (this *callbackEvent) Detach(callback Callback) { - delete(this.callbacks, reflect.ValueOf(callback).Pointer()) -} - -func (this *callbackEvent) Trigger() { - for _, callback := range this.callbacks { - callback() - } -} - -type Callback = func() diff --git a/plugins/autopeering/instances/neighborhood/instance.go b/plugins/autopeering/instances/neighborhood/instance.go deleted file mode 100644 index 8c693d0ffae98084443ec711d20cc4da48ce3225..0000000000000000000000000000000000000000 --- a/plugins/autopeering/instances/neighborhood/instance.go +++ /dev/null @@ -1,54 +0,0 @@ -package neighborhood - -import ( - "time" - - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/packages/timeutil" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/outgoingrequest" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peerlist" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peerregister" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/request" -) - -var INSTANCE *peerregister.PeerRegister - -var LIST_INSTANCE *peerlist.PeerList - -// Selects a fixed neighborhood from all known peers - this allows nodes to "stay in the same circles" that share their -// view on the ledger an is a preparation for economic clustering -var NEIGHBORHOOD_SELECTOR = func(this *peerregister.PeerRegister, req *request.Request) *peerregister.PeerRegister { - filteredPeers := peerregister.New() - for id, peer := range this.Peers.GetMap() { - filteredPeers.Peers.Store(id, peer) - } - - return filteredPeers -} - -var lastUpdate = time.Now() - -func Configure(plugin *node.Plugin) { - LIST_INSTANCE = peerlist.NewPeerList() - updateNeighborHood() -} - -func Run(plugin *node.Plugin) { - daemon.BackgroundWorker("Neighborhood Updater", func() { - timeutil.Ticker(updateNeighborHood, 1*time.Second) - }) -} - -func updateNeighborHood() { - if INSTANCE == nil || float64(INSTANCE.Peers.Len())*1.2 <= float64(knownpeers.INSTANCE.Peers.Len()) || lastUpdate.Before(time.Now().Add(-300*time.Second)) { - INSTANCE = knownpeers.INSTANCE.Filter(NEIGHBORHOOD_SELECTOR, outgoingrequest.INSTANCE) - - LIST_INSTANCE.Update(INSTANCE.List()) - - lastUpdate = time.Now() - - Events.Update.Trigger() - } -} diff --git a/plugins/autopeering/instances/outgoingrequest/instance.go b/plugins/autopeering/instances/outgoingrequest/instance.go deleted file mode 100644 index 6fdf7a79e31f3efc999741703a7483f2384092eb..0000000000000000000000000000000000000000 --- a/plugins/autopeering/instances/outgoingrequest/instance.go +++ /dev/null @@ -1,23 +0,0 @@ -package outgoingrequest - -import ( - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/ownpeer" - "github.com/iotaledger/goshimmer/plugins/autopeering/saltmanager" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/request" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/salt" -) - -var INSTANCE *request.Request - -func Configure(plugin *node.Plugin) { - INSTANCE = &request.Request{ - Issuer: ownpeer.INSTANCE, - } - INSTANCE.Sign() - - saltmanager.Events.UpdatePublicSalt.Attach(events.NewClosure(func(salt *salt.Salt) { - INSTANCE.Sign() - })) -} diff --git a/plugins/autopeering/instances/ownpeer/instance.go b/plugins/autopeering/instances/ownpeer/instance.go deleted file mode 100644 index 39f7cc552a80598e4b1b63c520728e261d659ab4..0000000000000000000000000000000000000000 --- a/plugins/autopeering/instances/ownpeer/instance.go +++ /dev/null @@ -1,24 +0,0 @@ -package ownpeer - -import ( - "net" - - "github.com/iotaledger/goshimmer/packages/accountability" - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/plugins/autopeering/parameters" - "github.com/iotaledger/goshimmer/plugins/autopeering/saltmanager" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" - "github.com/iotaledger/goshimmer/plugins/gossip" -) - -var INSTANCE *peer.Peer - -func Configure(plugin *node.Plugin) { - INSTANCE = &peer.Peer{} - INSTANCE.SetIdentity(accountability.OwnId()) - INSTANCE.SetPeeringPort(uint16(*parameters.PORT.Value)) - INSTANCE.SetGossipPort(uint16(*gossip.PORT.Value)) - INSTANCE.SetAddress(net.IPv4(0, 0, 0, 0)) - INSTANCE.SetSalt(saltmanager.PUBLIC_SALT) - -} diff --git a/plugins/autopeering/instances/plugin.go b/plugins/autopeering/instances/plugin.go deleted file mode 100644 index ed02fdf6abf9db47f53daa712f406ecb36578883..0000000000000000000000000000000000000000 --- a/plugins/autopeering/instances/plugin.go +++ /dev/null @@ -1,26 +0,0 @@ -package instances - -import ( - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/entrynodes" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/neighborhood" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/outgoingrequest" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/ownpeer" -) - -func Configure(plugin *node.Plugin) { - ownpeer.Configure(plugin) - entrynodes.Configure(plugin) - knownpeers.Configure(plugin) - neighborhood.Configure(plugin) - outgoingrequest.Configure(plugin) - chosenneighbors.Configure(plugin) - acceptedneighbors.Configure(plugin) -} - -func Run(plugin *node.Plugin) { - neighborhood.Run(plugin) -} diff --git a/plugins/autopeering/parameters/parameters.go b/plugins/autopeering/parameters/parameters.go deleted file mode 100644 index 8332389119f7dd07ab7aed9065beaf63d9485e5a..0000000000000000000000000000000000000000 --- a/plugins/autopeering/parameters/parameters.go +++ /dev/null @@ -1,11 +0,0 @@ -package parameters - -import "github.com/iotaledger/goshimmer/packages/parameter" - -var ( - ADDRESS = parameter.AddString("AUTOPEERING/ADDRESS", "0.0.0.0", "address to bind for incoming peering requests") - ENTRY_NODES = parameter.AddString("AUTOPEERING/ENTRY_NODES", "7f7a876a4236091257e650da8dcf195fbe3cb625@159.69.158.51:14626", "list of trusted entry nodes for auto peering") - PORT = parameter.AddInt("AUTOPEERING/PORT", 14626, "tcp port for incoming peering requests") - ACCEPT_REQUESTS = parameter.AddBool("AUTOPEERING/ACCEPT_REQUESTS", true, "accept incoming autopeering requests") - SEND_REQUESTS = parameter.AddBool("AUTOPEERING/SEND_REQUESTS", true, "send autopeering requests") -) diff --git a/plugins/autopeering/peerstorage/peerstorage.go b/plugins/autopeering/peerstorage/peerstorage.go deleted file mode 100644 index 5f205decee17a81633b3e89696e2542a5f74a0c3..0000000000000000000000000000000000000000 --- a/plugins/autopeering/peerstorage/peerstorage.go +++ /dev/null @@ -1,88 +0,0 @@ -package peerstorage - -import ( - "bytes" - "strconv" - "sync" - - "github.com/iotaledger/goshimmer/packages/database" - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" -) - -const peerDbName string = "peers" - -var peerDb database.Database -var once sync.Once - -func initDb() { - db, err := database.Get(peerDbName) - if err != nil { - panic(err) - } - - peerDb = db -} - -func getDb() database.Database { - once.Do(initDb) - - return peerDb -} - -func storePeer(p *peer.Peer) { - err := getDb().Set(p.GetIdentity().Identifier, p.Marshal()) - if err != nil { - panic(err) - } -} - -func removePeer(p *peer.Peer) { - err := getDb().Delete(p.GetIdentity().Identifier) - if err != nil { - panic(err) - } -} - -func loadPeers(plugin *node.Plugin) { - var count int - - err := getDb().ForEach(func(key []byte, value []byte) { - peer, err := peer.Unmarshal(value) - if err != nil { - panic(err) - } - // the peers are stored by identifier in the db - if !bytes.Equal(key, peer.GetIdentity().Identifier) { - panic("Invalid item in '" + peerDbName + "' database") - } - - knownpeers.INSTANCE.AddOrUpdate(peer) - count++ - plugin.LogDebug("Added stored peer: " + peer.GetAddress().String() + " / " + peer.GetIdentity().StringIdentifier) - }) - if err != nil { - panic(err) - } - - plugin.LogSuccess("Restored " + strconv.Itoa(count) + " peers from database") -} - -func Configure(plugin *node.Plugin) { - // do not store the entry nodes by ignoring all peers currently contained in konwnpeers - // add peers from db - loadPeers(plugin) - - // subscribe to all known peers' events - knownpeers.INSTANCE.Events.Add.Attach(events.NewClosure(func(p *peer.Peer) { - storePeer(p) - })) - knownpeers.INSTANCE.Events.Update.Attach(events.NewClosure(func(p *peer.Peer) { - storePeer(p) - })) - knownpeers.INSTANCE.Events.Remove.Attach(events.NewClosure(func(p *peer.Peer) { - removePeer(p) - })) -} diff --git a/plugins/autopeering/plugin.go b/plugins/autopeering/plugin.go index 430e3a7a2583cdbbd536c4ba4c6c895bc7894637..b5e9e5ffad576322633c30808b18af257a1725ad 100644 --- a/plugins/autopeering/plugin.go +++ b/plugins/autopeering/plugin.go @@ -1,83 +1,53 @@ package autopeering import ( + "net" + + "github.com/iotaledger/autopeering-sim/discover" + "github.com/iotaledger/autopeering-sim/selection" "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/events" "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" - "github.com/iotaledger/goshimmer/plugins/autopeering/peerstorage" - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol" - "github.com/iotaledger/goshimmer/plugins/autopeering/saltmanager" - "github.com/iotaledger/goshimmer/plugins/autopeering/server" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" "github.com/iotaledger/goshimmer/plugins/gossip" + "github.com/iotaledger/hive.go/events" ) -var PLUGIN = node.NewPlugin("Auto Peering", node.Enabled, configure, run) - func configure(plugin *node.Plugin) { - saltmanager.Configure(plugin) - instances.Configure(plugin) - server.Configure(plugin) - protocol.Configure(plugin) - peerstorage.Configure(plugin) - daemon.Events.Shutdown.Attach(events.NewClosure(func() { - server.Shutdown(plugin) + close <- struct{}{} })) configureLogging(plugin) } func run(plugin *node.Plugin) { - instances.Run(plugin) - server.Run(plugin) - protocol.Run(plugin) + go start() } func configureLogging(plugin *node.Plugin) { gossip.Events.RemoveNeighbor.Attach(events.NewClosure(func(peer *gossip.Neighbor) { - chosenneighbors.INSTANCE.Remove(peer.GetIdentity().StringIdentifier) - acceptedneighbors.INSTANCE.Remove(peer.GetIdentity().StringIdentifier) - })) - - acceptedneighbors.INSTANCE.Events.Add.Attach(events.NewClosure(func(p *peer.Peer) { - plugin.LogDebug("accepted neighbor added: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier) - - gossip.AddNeighbor(gossip.NewNeighbor(p.GetIdentity(), p.GetAddress(), p.GetGossipPort())) + Selection.DropPeer(peer.Peer) })) - acceptedneighbors.INSTANCE.Events.Remove.Attach(events.NewClosure(func(p *peer.Peer) { - plugin.LogDebug("accepted neighbor removed: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier) - gossip.RemoveNeighbor(p.GetIdentity().StringIdentifier) + selection.Events.Dropped.Attach(events.NewClosure(func(ev *selection.DroppedEvent) { + plugin.LogDebug("neighbor removed: " + ev.DroppedID.String()) + gossip.RemoveNeighbor(ev.DroppedID.String()) })) - chosenneighbors.INSTANCE.Events.Add.Attach(events.NewClosure(func(p *peer.Peer) { - plugin.LogDebug("chosen neighbor added: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier) - - gossip.AddNeighbor(gossip.NewNeighbor(p.GetIdentity(), p.GetAddress(), p.GetGossipPort())) + selection.Events.IncomingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) { + plugin.LogDebug("accepted neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String()) + address, _, _ := net.SplitHostPort(ev.Peer.Address()) + port := ev.Services["gossip"].Address + gossip.AddNeighbor(gossip.NewNeighbor(ev.Peer, address, port)) })) - chosenneighbors.INSTANCE.Events.Remove.Attach(events.NewClosure(func(p *peer.Peer) { - plugin.LogDebug("chosen neighbor removed: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier) - - gossip.RemoveNeighbor(p.GetIdentity().StringIdentifier) - })) - - knownpeers.INSTANCE.Events.Add.Attach(events.NewClosure(func(p *peer.Peer) { - plugin.LogInfo("new peer discovered: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier) - if _, exists := gossip.GetNeighbor(p.GetIdentity().StringIdentifier); exists { - gossip.AddNeighbor(gossip.NewNeighbor(p.GetIdentity(), p.GetAddress(), p.GetGossipPort())) - } + selection.Events.OutgoingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) { + plugin.LogDebug("chosen neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String()) + address, _, _ := net.SplitHostPort(ev.Peer.Address()) + port := ev.Services["gossip"].Address + gossip.AddNeighbor(gossip.NewNeighbor(ev.Peer, address, port)) })) - knownpeers.INSTANCE.Events.Update.Attach(events.NewClosure(func(p *peer.Peer) { - plugin.LogDebug("peer updated: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier) - if _, exists := gossip.GetNeighbor(p.GetIdentity().StringIdentifier); exists { - gossip.AddNeighbor(gossip.NewNeighbor(p.GetIdentity(), p.GetAddress(), p.GetGossipPort())) - } + discover.Events.PeerDiscovered.Attach(events.NewClosure(func(ev *discover.DiscoveredEvent) { + plugin.LogInfo("new peer discovered: " + ev.Peer.Address() + " / " + ev.Peer.ID().String()) })) } diff --git a/plugins/autopeering/protocol/accepted_neighbor_dropper.go b/plugins/autopeering/protocol/accepted_neighbor_dropper.go deleted file mode 100644 index f11c9169cd894cdf0f7ff4606e2afe952e522035..0000000000000000000000000000000000000000 --- a/plugins/autopeering/protocol/accepted_neighbor_dropper.go +++ /dev/null @@ -1,40 +0,0 @@ -package protocol - -import ( - "time" - - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/packages/timeutil" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/ownpeer" - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/constants" - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/types" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/drop" -) - -func createAcceptedNeighborDropper(plugin *node.Plugin) func() { - return func() { - timeutil.Ticker(func() { - if acceptedneighbors.INSTANCE.Peers.Len() > constants.NEIGHBOR_COUNT/2 { - defer acceptedneighbors.INSTANCE.Lock()() - for acceptedneighbors.INSTANCE.Peers.Len() > constants.NEIGHBOR_COUNT/2 { - acceptedneighbors.FurthestNeighborLock.RLock() - furthestNeighbor := acceptedneighbors.FURTHEST_NEIGHBOR - acceptedneighbors.FurthestNeighborLock.RUnlock() - - if furthestNeighbor != nil { - dropMessage := &drop.Drop{Issuer: ownpeer.INSTANCE} - dropMessage.Sign() - - acceptedneighbors.INSTANCE.Remove(furthestNeighbor.GetIdentity().StringIdentifier) - go func() { - if _, err := furthestNeighbor.Send(dropMessage.Marshal(), types.PROTOCOL_TYPE_UDP, false); err != nil { - plugin.LogDebug("error when sending drop message to" + acceptedneighbors.FURTHEST_NEIGHBOR.String()) - } - }() - } - } - } - }, 1*time.Second) - } -} diff --git a/plugins/autopeering/protocol/chosen_neighbor_dropper.go b/plugins/autopeering/protocol/chosen_neighbor_dropper.go deleted file mode 100644 index 23d2353302373cebecb8e082e72dd8eb63d9be88..0000000000000000000000000000000000000000 --- a/plugins/autopeering/protocol/chosen_neighbor_dropper.go +++ /dev/null @@ -1,40 +0,0 @@ -package protocol - -import ( - "time" - - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/packages/timeutil" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/ownpeer" - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/constants" - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/types" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/drop" -) - -func createChosenNeighborDropper(plugin *node.Plugin) func() { - return func() { - timeutil.Ticker(func() { - if chosenneighbors.INSTANCE.Peers.Len() > constants.NEIGHBOR_COUNT/2 { - defer chosenneighbors.INSTANCE.Lock()() - for chosenneighbors.INSTANCE.Peers.Len() > constants.NEIGHBOR_COUNT/2 { - chosenneighbors.FurthestNeighborLock.RLock() - furthestNeighbor := chosenneighbors.FURTHEST_NEIGHBOR - chosenneighbors.FurthestNeighborLock.RUnlock() - - if furthestNeighbor != nil { - dropMessage := &drop.Drop{Issuer: ownpeer.INSTANCE} - dropMessage.Sign() - - chosenneighbors.INSTANCE.Remove(furthestNeighbor.GetIdentity().StringIdentifier) - go func() { - if _, err := furthestNeighbor.Send(dropMessage.Marshal(), types.PROTOCOL_TYPE_UDP, false); err != nil { - plugin.LogDebug("error when sending drop message to" + chosenneighbors.FURTHEST_NEIGHBOR.String()) - } - }() - } - } - } - }, 1*time.Second) - } -} diff --git a/plugins/autopeering/protocol/constants/constants.go b/plugins/autopeering/protocol/constants/constants.go deleted file mode 100644 index 10e60f30ca34dd5ddc7d3f7ed6bf8aba8fa6d4c9..0000000000000000000000000000000000000000 --- a/plugins/autopeering/protocol/constants/constants.go +++ /dev/null @@ -1,18 +0,0 @@ -package constants - -import "time" - -const ( - NEIGHBOR_COUNT = 8 - - FIND_NEIGHBOR_INTERVAL = 10 * time.Second - - // How often does the outgoing ping processor check if new pings should be sent. - PING_PROCESS_INTERVAL = 1 * time.Second - - // The amount of times each neighbor should be contacted in this cycle. - PING_CONTACT_COUNT_PER_CYCLE = 2 - - // The length of a ping cycle (after this time we have sent randomized pings to all of our neighbors). - PING_CYCLE_LENGTH = 900 * time.Second -) diff --git a/plugins/autopeering/protocol/error_handler.go b/plugins/autopeering/protocol/error_handler.go deleted file mode 100644 index a97e5bf76216a731cb82d8e03a5c707aef732558..0000000000000000000000000000000000000000 --- a/plugins/autopeering/protocol/error_handler.go +++ /dev/null @@ -1,14 +0,0 @@ -package protocol - -import ( - "net" - - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/packages/node" -) - -func createErrorHandler(plugin *node.Plugin) *events.Closure { - return events.NewClosure(func(ip net.IP, err error) { - plugin.LogDebug("error when communicating with " + ip.String() + ": " + err.Error()) - }) -} diff --git a/plugins/autopeering/protocol/incoming_drop_processor.go b/plugins/autopeering/protocol/incoming_drop_processor.go deleted file mode 100644 index 60909e0a81113e828a1d8e6281d52fcff3192fef..0000000000000000000000000000000000000000 --- a/plugins/autopeering/protocol/incoming_drop_processor.go +++ /dev/null @@ -1,18 +0,0 @@ -package protocol - -import ( - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/drop" -) - -func createIncomingDropProcessor(plugin *node.Plugin) *events.Closure { - return events.NewClosure(func(drop *drop.Drop) { - plugin.LogDebug("received drop message from " + drop.Issuer.String()) - - chosenneighbors.INSTANCE.Remove(drop.Issuer.GetIdentity().StringIdentifier) - acceptedneighbors.INSTANCE.Remove(drop.Issuer.GetIdentity().StringIdentifier) - }) -} diff --git a/plugins/autopeering/protocol/incoming_ping_processor.go b/plugins/autopeering/protocol/incoming_ping_processor.go deleted file mode 100644 index 39124bfa6d3f44207b69f10caba02b2ef26023ee..0000000000000000000000000000000000000000 --- a/plugins/autopeering/protocol/incoming_ping_processor.go +++ /dev/null @@ -1,19 +0,0 @@ -package protocol - -import ( - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/ping" -) - -func createIncomingPingProcessor(plugin *node.Plugin) *events.Closure { - return events.NewClosure(func(ping *ping.Ping) { - plugin.LogDebug("received ping from " + ping.Issuer.String()) - - knownpeers.INSTANCE.AddOrUpdate(ping.Issuer) - for _, neighbor := range ping.Neighbors.GetPeers() { - knownpeers.INSTANCE.AddOrUpdate(neighbor) - } - }) -} diff --git a/plugins/autopeering/protocol/incoming_request_processor.go b/plugins/autopeering/protocol/incoming_request_processor.go deleted file mode 100644 index dcad375195ec4b8c051fdc1162a2bd88af554dfe..0000000000000000000000000000000000000000 --- a/plugins/autopeering/protocol/incoming_request_processor.go +++ /dev/null @@ -1,78 +0,0 @@ -package protocol - -import ( - "math/rand" - - "github.com/iotaledger/goshimmer/plugins/autopeering/parameters" - - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/neighborhood" - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/constants" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peerlist" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/request" -) - -func createIncomingRequestProcessor(plugin *node.Plugin) *events.Closure { - return events.NewClosure(func(req *request.Request) { - go processIncomingRequest(plugin, req) - }) -} - -func processIncomingRequest(plugin *node.Plugin, req *request.Request) { - plugin.LogDebug("received peering request from " + req.Issuer.String()) - - knownpeers.INSTANCE.AddOrUpdate(req.Issuer) - - if *parameters.ACCEPT_REQUESTS.Value && requestShouldBeAccepted(req) { - defer acceptedneighbors.INSTANCE.Lock()() - - if requestShouldBeAccepted(req) { - acceptedneighbors.INSTANCE.AddOrUpdate(req.Issuer) - - acceptRequest(plugin, req) - - return - } - } - - rejectRequest(plugin, req) -} - -func requestShouldBeAccepted(req *request.Request) bool { - return acceptedneighbors.INSTANCE.Peers.Len() < constants.NEIGHBOR_COUNT/2 || - acceptedneighbors.INSTANCE.Contains(req.Issuer.GetIdentity().StringIdentifier) || - acceptedneighbors.OWN_DISTANCE(req.Issuer) < acceptedneighbors.FURTHEST_NEIGHBOR_DISTANCE -} - -func acceptRequest(plugin *node.Plugin, req *request.Request) { - if err := req.Accept(generateProposedPeeringCandidates(req).GetPeers()); err != nil { - plugin.LogDebug("error when sending response to" + req.Issuer.String()) - } - - plugin.LogDebug("sent positive peering response to " + req.Issuer.String()) - - acceptedneighbors.INSTANCE.AddOrUpdate(req.Issuer) -} - -func rejectRequest(plugin *node.Plugin, req *request.Request) { - if err := req.Reject(generateProposedPeeringCandidates(req).GetPeers()); err != nil { - plugin.LogDebug("error when sending response to" + req.Issuer.String()) - } - - plugin.LogDebug("sent negative peering response to " + req.Issuer.String()) -} - -func generateProposedPeeringCandidates(req *request.Request) *peerlist.PeerList { - proposedPeers := neighborhood.LIST_INSTANCE.Filter(func(p *peer.Peer) bool { - return p.GetIdentity().PublicKey != nil - }) - rand.Shuffle(proposedPeers.Len(), func(i, j int) { - proposedPeers.SwapPeers(i, j) - }) - - return proposedPeers -} diff --git a/plugins/autopeering/protocol/incoming_response_processor.go b/plugins/autopeering/protocol/incoming_response_processor.go deleted file mode 100644 index 56324d540b170de4ec47b577daab6390c20f063d..0000000000000000000000000000000000000000 --- a/plugins/autopeering/protocol/incoming_response_processor.go +++ /dev/null @@ -1,34 +0,0 @@ -package protocol - -import ( - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/response" -) - -func createIncomingResponseProcessor(plugin *node.Plugin) *events.Closure { - return events.NewClosure(func(peeringResponse *response.Response) { - go processIncomingResponse(plugin, peeringResponse) - }) -} - -func processIncomingResponse(plugin *node.Plugin, peeringResponse *response.Response) { - plugin.LogDebug("received peering response from " + peeringResponse.Issuer.String()) - - if conn := peeringResponse.Issuer.GetConn(); conn != nil { - _ = conn.Close() - } - - knownpeers.INSTANCE.AddOrUpdate(peeringResponse.Issuer) - for _, peer := range peeringResponse.Peers { - knownpeers.INSTANCE.AddOrUpdate(peer) - } - - if peeringResponse.Type == response.TYPE_ACCEPT { - defer chosenneighbors.INSTANCE.Lock()() - - chosenneighbors.INSTANCE.AddOrUpdate(peeringResponse.Issuer) - } -} diff --git a/plugins/autopeering/protocol/outgoing_ping_processor.go b/plugins/autopeering/protocol/outgoing_ping_processor.go deleted file mode 100644 index 2ac0d02dcdc8b9b664ed280c0ffc9ab9c9b93c88..0000000000000000000000000000000000000000 --- a/plugins/autopeering/protocol/outgoing_ping_processor.go +++ /dev/null @@ -1,86 +0,0 @@ -package protocol - -import ( - "math/rand" - "time" - - "github.com/iotaledger/goshimmer/packages/accountability" - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/neighborhood" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/ownpeer" - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/constants" - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/types" - "github.com/iotaledger/goshimmer/plugins/autopeering/saltmanager" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/ping" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/salt" -) - -var lastPing time.Time - -func createOutgoingPingProcessor(plugin *node.Plugin) func() { - return func() { - plugin.LogInfo("Starting Ping Processor ...") - plugin.LogSuccess("Starting Ping Processor ... done") - - lastPing = time.Now().Add(-constants.PING_CYCLE_LENGTH) - - outgoingPing := &ping.Ping{ - Issuer: ownpeer.INSTANCE, - } - outgoingPing.Sign() - - saltmanager.Events.UpdatePublicSalt.Attach(events.NewClosure(func(salt *salt.Salt) { - outgoingPing.Sign() - })) - - pingPeers(plugin, outgoingPing) - - ticker := time.NewTicker(constants.PING_PROCESS_INTERVAL) - ticker: - for { - select { - case <-daemon.ShutdownSignal: - plugin.LogInfo("Stopping Ping Processor ...") - - break ticker - case <-ticker.C: - pingPeers(plugin, outgoingPing) - } - } - - plugin.LogSuccess("Stopping Ping Processor ... done") - } -} - -func pingPeers(plugin *node.Plugin, outgoingPing *ping.Ping) { - if neighborhood.LIST_INSTANCE.Len() >= 1 { - pingDelay := constants.PING_CYCLE_LENGTH / time.Duration(neighborhood.LIST_INSTANCE.Len()) - - if lastPing.Add(pingDelay).Before(time.Now()) { - chosenPeers := make(map[string]*peer.Peer) - - for i := 0; i < constants.PING_CONTACT_COUNT_PER_CYCLE; i++ { - randomNeighborHoodPeer := neighborhood.LIST_INSTANCE.GetPeers()[rand.Intn(neighborhood.LIST_INSTANCE.Len())] - - if randomNeighborHoodPeer.GetIdentity().StringIdentifier != accountability.OwnId().StringIdentifier { - chosenPeers[randomNeighborHoodPeer.GetIdentity().StringIdentifier] = randomNeighborHoodPeer - } - } - - for _, chosenPeer := range chosenPeers { - go func(chosenPeer *peer.Peer) { - if _, err := chosenPeer.Send(outgoingPing.Marshal(), types.PROTOCOL_TYPE_UDP, false); err != nil { - plugin.LogDebug("error when sending ping to " + chosenPeer.String() + ": " + err.Error()) - } else { - plugin.LogDebug("sent ping to " + chosenPeer.String()) - } - }(chosenPeer) - } - - lastPing = time.Now() - } - } -} diff --git a/plugins/autopeering/protocol/outgoing_request_processor.go b/plugins/autopeering/protocol/outgoing_request_processor.go deleted file mode 100644 index f36c08af7c6e9f06d523b08befcf96b36291400a..0000000000000000000000000000000000000000 --- a/plugins/autopeering/protocol/outgoing_request_processor.go +++ /dev/null @@ -1,85 +0,0 @@ -package protocol - -import ( - "time" - - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/outgoingrequest" - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/types" - "github.com/iotaledger/goshimmer/plugins/autopeering/server/tcp" - - "github.com/iotaledger/goshimmer/packages/timeutil" - - "github.com/iotaledger/goshimmer/packages/accountability" - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/constants" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" -) - -func createOutgoingRequestProcessor(plugin *node.Plugin) func() { - return func() { - plugin.LogInfo("Starting Chosen Neighbor Processor ...") - plugin.LogSuccess("Starting Chosen Neighbor Processor ... done") - - sendOutgoingRequests(plugin) - - ticker := time.NewTicker(constants.FIND_NEIGHBOR_INTERVAL) - ticker: - for { - select { - case <-daemon.ShutdownSignal: - plugin.LogInfo("Stopping Chosen Neighbor Processor ...") - - break ticker - case <-ticker.C: - sendOutgoingRequests(plugin) - } - } - - plugin.LogSuccess("Stopping Chosen Neighbor Processor ... done") - } -} - -func sendOutgoingRequests(plugin *node.Plugin) { - for _, chosenNeighborCandidate := range chosenneighbors.CANDIDATES.GetPeers() { - timeutil.Sleep(5 * time.Second) - - if candidateShouldBeContacted(chosenNeighborCandidate) { - doneChan := make(chan int, 1) - - go func(doneChan chan int) { - if dialed, err := chosenNeighborCandidate.Send(outgoingrequest.INSTANCE.Marshal(), types.PROTOCOL_TYPE_TCP, true); err != nil { - plugin.LogDebug(err.Error()) - } else { - plugin.LogDebug("sent peering request to " + chosenNeighborCandidate.String()) - - if dialed { - tcp.HandleConnection(chosenNeighborCandidate.GetConn()) - } - } - - close(doneChan) - }(doneChan) - - select { - case <-daemon.ShutdownSignal: - return - case <-doneChan: - continue - } - } - } -} - -func candidateShouldBeContacted(candidate *peer.Peer) bool { - nodeId := candidate.GetIdentity().StringIdentifier - - chosenneighbors.FurthestNeighborLock.RLock() - defer chosenneighbors.FurthestNeighborLock.RUnlock() - - return (!acceptedneighbors.INSTANCE.Contains(nodeId) && !chosenneighbors.INSTANCE.Contains(nodeId) && - accountability.OwnId().StringIdentifier != nodeId) && (chosenneighbors.INSTANCE.Peers.Len() < constants.NEIGHBOR_COUNT/2 || - chosenneighbors.OWN_DISTANCE(candidate) < chosenneighbors.FURTHEST_NEIGHBOR_DISTANCE) -} diff --git a/plugins/autopeering/protocol/plugin.go b/plugins/autopeering/protocol/plugin.go deleted file mode 100644 index a72f522d80d04700762b44948f23b60043bdf4ed..0000000000000000000000000000000000000000 --- a/plugins/autopeering/protocol/plugin.go +++ /dev/null @@ -1,32 +0,0 @@ -package protocol - -import ( - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/plugins/autopeering/parameters" - "github.com/iotaledger/goshimmer/plugins/autopeering/server/tcp" - "github.com/iotaledger/goshimmer/plugins/autopeering/server/udp" -) - -func Configure(plugin *node.Plugin) { - errorHandler := createErrorHandler(plugin) - - udp.Events.ReceiveDrop.Attach(createIncomingDropProcessor(plugin)) - udp.Events.ReceivePing.Attach(createIncomingPingProcessor(plugin)) - udp.Events.Error.Attach(errorHandler) - - tcp.Events.ReceiveRequest.Attach(createIncomingRequestProcessor(plugin)) - tcp.Events.ReceiveResponse.Attach(createIncomingResponseProcessor(plugin)) - tcp.Events.Error.Attach(errorHandler) -} - -func Run(plugin *node.Plugin) { - daemon.BackgroundWorker("Autopeering Chosen Neighbor Dropper", createChosenNeighborDropper(plugin)) - daemon.BackgroundWorker("Autopeering Accepted Neighbor Dropper", createAcceptedNeighborDropper(plugin)) - - if *parameters.SEND_REQUESTS.Value { - daemon.BackgroundWorker("Autopeering Outgoing Request Processor", createOutgoingRequestProcessor(plugin)) - } - - daemon.BackgroundWorker("Autopeering Outgoing Ping Processor", createOutgoingPingProcessor(plugin)) -} diff --git a/plugins/autopeering/protocol/types/constants.go b/plugins/autopeering/protocol/types/constants.go deleted file mode 100644 index a4dc301c991c8288a112721f126052b8bb17630d..0000000000000000000000000000000000000000 --- a/plugins/autopeering/protocol/types/constants.go +++ /dev/null @@ -1,9 +0,0 @@ -package types - -const ( - PROTOCOL_TYPE_TCP = ProtocolType(0) - PROTOCOL_TYPE_UDP = ProtocolType(1) - - ADDRESS_TYPE_IPV4 = AddressType(0) - ADDRESS_TYPE_IPV6 = AddressType(1) -) diff --git a/plugins/autopeering/protocol/types/types.go b/plugins/autopeering/protocol/types/types.go deleted file mode 100644 index 3b68f5dae31ea0b1180bfc5f4f95c8d643e57067..0000000000000000000000000000000000000000 --- a/plugins/autopeering/protocol/types/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package types - -type AddressType = byte - -type ProtocolType = byte diff --git a/plugins/autopeering/saltmanager/constants.go b/plugins/autopeering/saltmanager/constants.go deleted file mode 100644 index 4fe475f4015a05d60958f918a0be9f1463e5e009..0000000000000000000000000000000000000000 --- a/plugins/autopeering/saltmanager/constants.go +++ /dev/null @@ -1,13 +0,0 @@ -package saltmanager - -import "time" - -const ( - PUBLIC_SALT_LIFETIME = 1800 * time.Second - PRIVATE_SALT_LIFETIME = 1800 * time.Second -) - -var ( - PUBLIC_SALT_SETTINGS_KEY = []byte("PUBLIC_SALT") - PRIVATE_SALT_SETTINGS_KEY = []byte("PRIVATE_SALT") -) diff --git a/plugins/autopeering/saltmanager/errors.go b/plugins/autopeering/saltmanager/errors.go deleted file mode 100644 index 4436630107263c49a75104f29cfa3aae70c807ec..0000000000000000000000000000000000000000 --- a/plugins/autopeering/saltmanager/errors.go +++ /dev/null @@ -1,8 +0,0 @@ -package saltmanager - -import "github.com/pkg/errors" - -var ( - ErrPublicSaltExpired = errors.New("expired public salt in ping") - ErrPublicSaltInvalidLifetime = errors.New("invalid public salt lifetime in ping") -) diff --git a/plugins/autopeering/saltmanager/events.go b/plugins/autopeering/saltmanager/events.go deleted file mode 100644 index 26f207e7385adc9a280bb1aacd297f6c66075b34..0000000000000000000000000000000000000000 --- a/plugins/autopeering/saltmanager/events.go +++ /dev/null @@ -1,18 +0,0 @@ -package saltmanager - -import ( - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/salt" -) - -var Events = struct { - UpdatePublicSalt *events.Event - UpdatePrivateSalt *events.Event -}{ - UpdatePublicSalt: events.NewEvent(saltCaller), - UpdatePrivateSalt: events.NewEvent(saltCaller), -} - -func saltCaller(handler interface{}, params ...interface{}) { - handler.(func(*salt.Salt))(params[0].(*salt.Salt)) -} diff --git a/plugins/autopeering/saltmanager/saltmanager.go b/plugins/autopeering/saltmanager/saltmanager.go deleted file mode 100644 index 6cb06a9a13dcc9db776076a9bf9ad072fe76e80c..0000000000000000000000000000000000000000 --- a/plugins/autopeering/saltmanager/saltmanager.go +++ /dev/null @@ -1,88 +0,0 @@ -package saltmanager - -import ( - "time" - - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/database" - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/packages/settings" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/salt" -) - -var ( - PRIVATE_SALT *salt.Salt - PUBLIC_SALT *salt.Salt -) - -func Configure(plugin *node.Plugin) { - PRIVATE_SALT = createSalt(PRIVATE_SALT_SETTINGS_KEY, PRIVATE_SALT_LIFETIME, Events.UpdatePrivateSalt.Trigger) - PUBLIC_SALT = createSalt(PUBLIC_SALT_SETTINGS_KEY, PUBLIC_SALT_LIFETIME, Events.UpdatePublicSalt.Trigger) -} - -func generateNewSalt(key []byte, lifetime time.Duration) *salt.Salt { - newSalt := salt.New(lifetime) - - if err := settings.Set(key, newSalt.Marshal()); err != nil { - panic(err) - } - - return newSalt -} - -func getSalt(key []byte, lifetime time.Duration) *salt.Salt { - saltBytes, err := settings.Get(key) - if err != nil { - if err == database.ErrKeyNotFound { - return generateNewSalt(key, lifetime) - } else { - panic(err) - } - } - - if resultingSalt, err := salt.Unmarshal(saltBytes); err != nil { - panic(err) - } else { - return resultingSalt - } -} - -func updatePublicSalt(saltToUpdate *salt.Salt, settingsKey []byte, lifeSpan time.Duration, updateCallback func(params ...interface{})) { - newSalt := salt.New(lifeSpan) - - saltToUpdate.SetBytes(newSalt.GetBytes()) - saltToUpdate.SetExpirationTime(newSalt.GetExpirationTime()) - - if err := settings.Set(settingsKey, saltToUpdate.Marshal()); err != nil { - panic(err) - } - - updateCallback(saltToUpdate) - - scheduleUpdateForSalt(saltToUpdate, settingsKey, lifeSpan, updateCallback) -} - -func scheduleUpdateForSalt(saltToUpdate *salt.Salt, settingsKey []byte, lifeSpan time.Duration, callback func(params ...interface{})) { - now := time.Now() - - if saltToUpdate.GetExpirationTime().Before(now) { - updatePublicSalt(saltToUpdate, settingsKey, lifeSpan, callback) - } else { - daemon.BackgroundWorker("Salt Updater", func() { - select { - case <-time.After(saltToUpdate.GetExpirationTime().Sub(now)): - updatePublicSalt(saltToUpdate, settingsKey, lifeSpan, callback) - case <-daemon.ShutdownSignal: - return - } - }) - } -} - -func createSalt(settingsKey []byte, lifeSpan time.Duration, updateCallback func(params ...interface{})) *salt.Salt { - newSalt := getSalt(settingsKey, lifeSpan) - - scheduleUpdateForSalt(newSalt, settingsKey, lifeSpan, updateCallback) - - return newSalt -} diff --git a/plugins/autopeering/saltmanager/utils.go b/plugins/autopeering/saltmanager/utils.go deleted file mode 100644 index cdbfca95816bec02ef384c2eef46c1318689f8af..0000000000000000000000000000000000000000 --- a/plugins/autopeering/saltmanager/utils.go +++ /dev/null @@ -1,19 +0,0 @@ -package saltmanager - -import ( - "time" - - "github.com/iotaledger/goshimmer/plugins/autopeering/types/salt" -) - -func CheckSalt(saltToCheck *salt.Salt) error { - now := time.Now() - if saltToCheck.GetExpirationTime().Before(now.Add(-1 * time.Minute)) { - return ErrPublicSaltExpired - } - if saltToCheck.GetExpirationTime().After(now.Add(PUBLIC_SALT_LIFETIME + 1*time.Minute)) { - return ErrPublicSaltInvalidLifetime - } - - return nil -} diff --git a/plugins/autopeering/server/server.go b/plugins/autopeering/server/server.go deleted file mode 100644 index cf51cd303e76dffd36b7d8e3c980e712a6a13b56..0000000000000000000000000000000000000000 --- a/plugins/autopeering/server/server.go +++ /dev/null @@ -1,22 +0,0 @@ -package server - -import ( - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/plugins/autopeering/server/tcp" - "github.com/iotaledger/goshimmer/plugins/autopeering/server/udp" -) - -func Configure(plugin *node.Plugin) { - udp.ConfigureServer(plugin) - tcp.ConfigureServer(plugin) -} - -func Run(plugin *node.Plugin) { - udp.RunServer(plugin) - tcp.RunServer(plugin) -} - -func Shutdown(plugin *node.Plugin) { - udp.ShutdownUDPServer(plugin) - tcp.ShutdownServer(plugin) -} diff --git a/plugins/autopeering/server/tcp/constants.go b/plugins/autopeering/server/tcp/constants.go deleted file mode 100644 index c108d820e10625eb646069507b9d716c1e7a0044..0000000000000000000000000000000000000000 --- a/plugins/autopeering/server/tcp/constants.go +++ /dev/null @@ -1,12 +0,0 @@ -package tcp - -import "time" - -const ( - IDLE_TIMEOUT = 5 * time.Second - - STATE_INITIAL = byte(0) - STATE_REQUEST = byte(1) - STATE_RESPONSE = byte(2) - STATE_PING = byte(3) -) diff --git a/plugins/autopeering/server/tcp/events.go b/plugins/autopeering/server/tcp/events.go deleted file mode 100644 index 2b9110fa4089961cc4956f0347adeb86cd060b83..0000000000000000000000000000000000000000 --- a/plugins/autopeering/server/tcp/events.go +++ /dev/null @@ -1,35 +0,0 @@ -package tcp - -import ( - "net" - - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/ping" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/request" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/response" -) - -var Events = struct { - ReceivePing *events.Event - ReceiveRequest *events.Event - ReceiveResponse *events.Event - Error *events.Event -}{ - events.NewEvent(pingCaller), - events.NewEvent(requestCaller), - events.NewEvent(responseCaller), - events.NewEvent(errorCaller), -} - -func pingCaller(handler interface{}, params ...interface{}) { - handler.(func(*ping.Ping))(params[0].(*ping.Ping)) -} -func requestCaller(handler interface{}, params ...interface{}) { - handler.(func(*request.Request))(params[0].(*request.Request)) -} -func responseCaller(handler interface{}, params ...interface{}) { - handler.(func(*response.Response))(params[0].(*response.Response)) -} -func errorCaller(handler interface{}, params ...interface{}) { - handler.(func(net.IP, error))(params[0].(net.IP), params[1].(error)) -} diff --git a/plugins/autopeering/server/tcp/server.go b/plugins/autopeering/server/tcp/server.go deleted file mode 100644 index 71d965b8dc867f17ebb3596f2bd97073faa61059..0000000000000000000000000000000000000000 --- a/plugins/autopeering/server/tcp/server.go +++ /dev/null @@ -1,225 +0,0 @@ -package tcp - -import ( - "math" - "net" - "strconv" - - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/packages/network" - "github.com/iotaledger/goshimmer/packages/network/tcp" - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/plugins/autopeering/parameters" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/ping" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/request" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/response" - "github.com/pkg/errors" -) - -var server = tcp.NewServer() - -func ConfigureServer(plugin *node.Plugin) { - server.Events.Connect.Attach(events.NewClosure(HandleConnection)) - server.Events.Error.Attach(events.NewClosure(func(err error) { - plugin.LogFailure("error in tcp server: " + err.Error()) - })) - server.Events.Start.Attach(events.NewClosure(func() { - if *parameters.ADDRESS.Value == "0.0.0.0" { - plugin.LogSuccess("Starting TCP Server (port " + strconv.Itoa(*parameters.PORT.Value) + ") ... done") - } else { - plugin.LogSuccess("Starting TCP Server (" + *parameters.ADDRESS.Value + ":" + strconv.Itoa(*parameters.PORT.Value) + ") ... done") - } - })) - server.Events.Shutdown.Attach(events.NewClosure(func() { - plugin.LogSuccess("Stopping TCP Server ... done") - })) -} - -func RunServer(plugin *node.Plugin) { - daemon.BackgroundWorker("Autopeering TCP Server", func() { - if *parameters.ADDRESS.Value == "0.0.0.0" { - plugin.LogInfo("Starting TCP Server (port " + strconv.Itoa(*parameters.PORT.Value) + ") ...") - } else { - plugin.LogInfo("Starting TCP Server (" + *parameters.ADDRESS.Value + ":" + strconv.Itoa(*parameters.PORT.Value) + ") ...") - } - - server.Listen(*parameters.PORT.Value) - }) -} - -func ShutdownServer(plugin *node.Plugin) { - plugin.LogInfo("Stopping TCP Server ...") - - server.Shutdown() -} - -func HandleConnection(conn *network.ManagedConnection) { - conn.SetTimeout(IDLE_TIMEOUT) - - var connectionState = STATE_INITIAL - var receiveBuffer []byte - var offset int - - conn.Events.ReceiveData.Attach(events.NewClosure(func(data []byte) { - ProcessIncomingPacket(&connectionState, &receiveBuffer, conn, data, &offset) - })) - - go conn.Read(make([]byte, int(math.Max(ping.MARSHALED_TOTAL_SIZE, math.Max(request.MARSHALED_TOTAL_SIZE, response.MARSHALED_TOTAL_SIZE))))) -} - -func ProcessIncomingPacket(connectionState *byte, receiveBuffer *[]byte, conn *network.ManagedConnection, data []byte, offset *int) { - if *connectionState == STATE_INITIAL { - var err error - if *connectionState, *receiveBuffer, err = parsePackageHeader(data); err != nil { - Events.Error.Trigger(conn.RemoteAddr().(*net.TCPAddr).IP, err) - - conn.Close() - - return - } - - *offset = 0 - - switch *connectionState { - case STATE_REQUEST: - *receiveBuffer = make([]byte, request.MARSHALED_TOTAL_SIZE) - case STATE_RESPONSE: - *receiveBuffer = make([]byte, response.MARSHALED_TOTAL_SIZE) - case STATE_PING: - *receiveBuffer = make([]byte, ping.MARSHALED_TOTAL_SIZE) - } - } - - switch *connectionState { - case STATE_REQUEST: - processIncomingRequestPacket(connectionState, receiveBuffer, conn, data, offset) - case STATE_RESPONSE: - processIncomingResponsePacket(connectionState, receiveBuffer, conn, data, offset) - case STATE_PING: - processIncomingPingPacket(connectionState, receiveBuffer, conn, data, offset) - } -} - -func parsePackageHeader(data []byte) (byte, []byte, error) { - var connectionState byte - var receiveBuffer []byte - - switch data[0] { - case request.MARSHALED_PACKET_HEADER: - receiveBuffer = make([]byte, request.MARSHALED_TOTAL_SIZE) - - connectionState = STATE_REQUEST - case response.MARHSALLED_PACKET_HEADER: - receiveBuffer = make([]byte, response.MARSHALED_TOTAL_SIZE) - - connectionState = STATE_RESPONSE - case ping.MARSHALED_PACKET_HEADER: - receiveBuffer = make([]byte, ping.MARSHALED_TOTAL_SIZE) - - connectionState = STATE_PING - default: - return 0, nil, errors.New("invalid package header") - } - - return connectionState, receiveBuffer, nil -} - -func processIncomingRequestPacket(connectionState *byte, receiveBuffer *[]byte, conn *network.ManagedConnection, data []byte, offset *int) { - remainingCapacity := int(math.Min(float64(request.MARSHALED_TOTAL_SIZE-*offset), float64(len(data)))) - - copy((*receiveBuffer)[*offset:], data[:remainingCapacity]) - - if *offset+len(data) < request.MARSHALED_TOTAL_SIZE { - *offset += len(data) - } else { - if req, err := request.Unmarshal(*receiveBuffer); err != nil { - Events.Error.Trigger(conn.RemoteAddr().(*net.TCPAddr).IP, err) - - conn.Close() - - return - } else { - req.Issuer.SetConn(conn) - req.Issuer.SetAddress(conn.RemoteAddr().(*net.TCPAddr).IP) - - conn.Events.Close.Attach(events.NewClosure(func() { - req.Issuer.SetConn(nil) - })) - - Events.ReceiveRequest.Trigger(req) - } - - *connectionState = STATE_INITIAL - - if *offset+len(data) > request.MARSHALED_TOTAL_SIZE { - ProcessIncomingPacket(connectionState, receiveBuffer, conn, data[remainingCapacity:], offset) - } - } -} - -func processIncomingResponsePacket(connectionState *byte, receiveBuffer *[]byte, conn *network.ManagedConnection, data []byte, offset *int) { - remainingCapacity := int(math.Min(float64(response.MARSHALED_TOTAL_SIZE-*offset), float64(len(data)))) - - copy((*receiveBuffer)[*offset:], data[:remainingCapacity]) - - if *offset+len(data) < response.MARSHALED_TOTAL_SIZE { - *offset += len(data) - } else { - if res, err := response.Unmarshal(*receiveBuffer); err != nil { - Events.Error.Trigger(conn.RemoteAddr().(*net.TCPAddr).IP, err) - - conn.Close() - - return - } else { - res.Issuer.SetConn(conn) - res.Issuer.SetAddress(conn.RemoteAddr().(*net.TCPAddr).IP) - - conn.Events.Close.Attach(events.NewClosure(func() { - res.Issuer.SetConn(nil) - })) - - Events.ReceiveResponse.Trigger(res) - } - - *connectionState = STATE_INITIAL - - if *offset+len(data) > response.MARSHALED_TOTAL_SIZE { - ProcessIncomingPacket(connectionState, receiveBuffer, conn, data[remainingCapacity:], offset) - } - } -} - -func processIncomingPingPacket(connectionState *byte, receiveBuffer *[]byte, conn *network.ManagedConnection, data []byte, offset *int) { - remainingCapacity := int(math.Min(float64(ping.MARSHALED_TOTAL_SIZE-*offset), float64(len(data)))) - - copy((*receiveBuffer)[*offset:], data[:remainingCapacity]) - - if *offset+len(data) < ping.MARSHALED_TOTAL_SIZE { - *offset += len(data) - } else { - if ping, err := ping.Unmarshal(*receiveBuffer); err != nil { - Events.Error.Trigger(conn.RemoteAddr().(*net.TCPAddr).IP, err) - - conn.Close() - - return - } else { - ping.Issuer.SetConn(conn) - ping.Issuer.SetAddress(conn.RemoteAddr().(*net.TCPAddr).IP) - - conn.Events.Close.Attach(events.NewClosure(func() { - ping.Issuer.SetConn(nil) - })) - - Events.ReceivePing.Trigger(ping) - } - - *connectionState = STATE_INITIAL - - if *offset+len(data) > ping.MARSHALED_TOTAL_SIZE { - ProcessIncomingPacket(connectionState, receiveBuffer, conn, data[remainingCapacity:], offset) - } - } -} diff --git a/plugins/autopeering/server/udp/events.go b/plugins/autopeering/server/udp/events.go deleted file mode 100644 index 6db7f3fc961c6a13d5260744a5383f77451d31e8..0000000000000000000000000000000000000000 --- a/plugins/autopeering/server/udp/events.go +++ /dev/null @@ -1,41 +0,0 @@ -package udp - -import ( - "net" - - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/drop" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/ping" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/request" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/response" -) - -var Events = struct { - ReceiveDrop *events.Event - ReceivePing *events.Event - ReceiveRequest *events.Event - ReceiveResponse *events.Event - Error *events.Event -}{ - events.NewEvent(dropCaller), - events.NewEvent(pingCaller), - events.NewEvent(requestCaller), - events.NewEvent(responseCaller), - events.NewEvent(errorCaller), -} - -func dropCaller(handler interface{}, params ...interface{}) { - handler.(func(*drop.Drop))(params[0].(*drop.Drop)) -} -func pingCaller(handler interface{}, params ...interface{}) { - handler.(func(*ping.Ping))(params[0].(*ping.Ping)) -} -func requestCaller(handler interface{}, params ...interface{}) { - handler.(func(*request.Request))(params[0].(*request.Request)) -} -func responseCaller(handler interface{}, params ...interface{}) { - handler.(func(*response.Response))(params[0].(*response.Response)) -} -func errorCaller(handler interface{}, params ...interface{}) { - handler.(func(net.IP, error))(params[0].(net.IP), params[1].(error)) -} diff --git a/plugins/autopeering/server/udp/server.go b/plugins/autopeering/server/udp/server.go deleted file mode 100644 index d79928e17d92c3beee451a7640983deb2978054f..0000000000000000000000000000000000000000 --- a/plugins/autopeering/server/udp/server.go +++ /dev/null @@ -1,98 +0,0 @@ -package udp - -import ( - "math" - "net" - "strconv" - - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/packages/network/udp" - "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/plugins/autopeering/parameters" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/drop" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/ping" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/request" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/response" - "github.com/pkg/errors" -) - -var udpServer = udp.NewServer(int(math.Max(float64(request.MARSHALED_TOTAL_SIZE), float64(response.MARSHALED_TOTAL_SIZE)))) - -func ConfigureServer(plugin *node.Plugin) { - Events.Error.Attach(events.NewClosure(func(ip net.IP, err error) { - plugin.LogFailure(err.Error()) - })) - - udpServer.Events.ReceiveData.Attach(events.NewClosure(processReceivedData)) - udpServer.Events.Error.Attach(events.NewClosure(func(err error) { - plugin.LogFailure("error in udp server: " + err.Error()) - })) - udpServer.Events.Start.Attach(events.NewClosure(func() { - if *parameters.ADDRESS.Value == "0.0.0.0" { - plugin.LogSuccess("Starting UDP Server (port " + strconv.Itoa(*parameters.PORT.Value) + ") ... done") - } else { - plugin.LogSuccess("Starting UDP Server (" + *parameters.ADDRESS.Value + ":" + strconv.Itoa(*parameters.PORT.Value) + ") ... done") - } - })) - udpServer.Events.Shutdown.Attach(events.NewClosure(func() { - plugin.LogSuccess("Stopping UDP Server ... done") - })) -} - -func RunServer(plugin *node.Plugin) { - daemon.BackgroundWorker("Autopeering UDP Server", func() { - if *parameters.ADDRESS.Value == "0.0.0.0" { - plugin.LogInfo("Starting UDP Server (port " + strconv.Itoa(*parameters.PORT.Value) + ") ...") - } else { - plugin.LogInfo("Starting UDP Server (" + *parameters.ADDRESS.Value + ":" + strconv.Itoa(*parameters.PORT.Value) + ") ...") - } - - udpServer.Listen(*parameters.ADDRESS.Value, *parameters.PORT.Value) - }) -} - -func ShutdownUDPServer(plugin *node.Plugin) { - plugin.LogInfo("Stopping UDP Server ...") - - udpServer.Shutdown() -} - -func processReceivedData(addr *net.UDPAddr, data []byte) { - switch data[0] { - case request.MARSHALED_PACKET_HEADER: - if peeringRequest, err := request.Unmarshal(data); err != nil { - Events.Error.Trigger(addr.IP, err) - } else { - peeringRequest.Issuer.SetAddress(addr.IP) - - Events.ReceiveRequest.Trigger(peeringRequest) - } - case response.MARHSALLED_PACKET_HEADER: - if peeringResponse, err := response.Unmarshal(data); err != nil { - Events.Error.Trigger(addr.IP, err) - } else { - peeringResponse.Issuer.SetAddress(addr.IP) - - Events.ReceiveResponse.Trigger(peeringResponse) - } - case ping.MARSHALED_PACKET_HEADER: - if ping, err := ping.Unmarshal(data); err != nil { - Events.Error.Trigger(addr.IP, err) - } else { - ping.Issuer.SetAddress(addr.IP) - - Events.ReceivePing.Trigger(ping) - } - case drop.MARSHALED_PACKET_HEADER: - if drop, err := drop.Unmarshal(data); err != nil { - Events.Error.Trigger(addr.IP, err) - } else { - drop.Issuer.SetAddress(addr.IP) - - Events.ReceiveDrop.Trigger(drop) - } - default: - Events.Error.Trigger(addr.IP, errors.New("invalid UDP peering packet from "+addr.IP.String())) - } -} diff --git a/plugins/autopeering/types/drop/constants.go b/plugins/autopeering/types/drop/constants.go deleted file mode 100644 index b12728d748de7ef1a1f19a3d80a8007ec1a17d7b..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/drop/constants.go +++ /dev/null @@ -1,23 +0,0 @@ -package drop - -import ( - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" -) - -const ( - MARSHALED_PACKET_HEADER = 0x05 - - PACKET_HEADER_START = 0 - MARSHALED_ISSUER_START = PACKET_HEADER_END - MARSHALED_SIGNATURE_START = MARSHALED_ISSUER_END - - PACKET_HEADER_END = PACKET_HEADER_START + PACKET_HEADER_SIZE - MARSHALED_ISSUER_END = MARSHALED_ISSUER_START + MARSHALED_ISSUER_SIZE - MARSHALED_SIGNATURE_END = MARSHALED_SIGNATURE_START + MARSHALED_SIGNATURE_SIZE - - PACKET_HEADER_SIZE = 1 - MARSHALED_ISSUER_SIZE = peer.MARSHALED_TOTAL_SIZE - MARSHALED_SIGNATURE_SIZE = 65 - - MARSHALED_TOTAL_SIZE = MARSHALED_SIGNATURE_END -) diff --git a/plugins/autopeering/types/drop/drop.go b/plugins/autopeering/types/drop/drop.go deleted file mode 100644 index 99ebf8773c2abaeebad71db80998bbc1d5a5d3ad..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/drop/drop.go +++ /dev/null @@ -1,60 +0,0 @@ -package drop - -import ( - "bytes" - - "github.com/iotaledger/goshimmer/packages/identity" - "github.com/iotaledger/goshimmer/plugins/autopeering/saltmanager" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" -) - -type Drop struct { - Issuer *peer.Peer - Signature [MARSHALED_SIGNATURE_SIZE]byte -} - -func Unmarshal(data []byte) (*Drop, error) { - if data[0] != MARSHALED_PACKET_HEADER || len(data) != MARSHALED_TOTAL_SIZE { - return nil, ErrMalformedDropMessage - } - - ping := &Drop{} - - if unmarshaledPeer, err := peer.Unmarshal(data[MARSHALED_ISSUER_START:MARSHALED_ISSUER_END]); err != nil { - return nil, err - } else { - ping.Issuer = unmarshaledPeer - } - if err := saltmanager.CheckSalt(ping.Issuer.GetSalt()); err != nil { - return nil, err - } - - if issuer, err := identity.FromSignedData(data[:MARSHALED_SIGNATURE_START], data[MARSHALED_SIGNATURE_START:]); err != nil { - return nil, err - } else { - if !bytes.Equal(issuer.Identifier, ping.Issuer.GetIdentity().Identifier) { - return nil, ErrInvalidSignature - } - } - copy(ping.Signature[:], data[MARSHALED_SIGNATURE_START:MARSHALED_SIGNATURE_END]) - - return ping, nil -} - -func (ping *Drop) Marshal() []byte { - result := make([]byte, MARSHALED_TOTAL_SIZE) - - result[PACKET_HEADER_START] = MARSHALED_PACKET_HEADER - copy(result[MARSHALED_ISSUER_START:MARSHALED_ISSUER_END], ping.Issuer.Marshal()) - copy(result[MARSHALED_SIGNATURE_START:MARSHALED_SIGNATURE_END], ping.Signature[:MARSHALED_SIGNATURE_SIZE]) - - return result -} - -func (this *Drop) Sign() { - if signature, err := this.Issuer.GetIdentity().Sign(this.Marshal()[:MARSHALED_SIGNATURE_START]); err != nil { - panic(err) - } else { - copy(this.Signature[:], signature) - } -} diff --git a/plugins/autopeering/types/drop/errors.go b/plugins/autopeering/types/drop/errors.go deleted file mode 100644 index d2878718dd96e805ef30aeb0dbbce7bf854aaadf..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/drop/errors.go +++ /dev/null @@ -1,8 +0,0 @@ -package drop - -import "github.com/pkg/errors" - -var ( - ErrInvalidSignature = errors.New("invalid signature in drop message") - ErrMalformedDropMessage = errors.New("malformed drop message") -) diff --git a/plugins/autopeering/types/peer/constants.go b/plugins/autopeering/types/peer/constants.go deleted file mode 100644 index a29c567c246f2467a7620f5b1f87e079db24a21d..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/peer/constants.go +++ /dev/null @@ -1,31 +0,0 @@ -package peer - -import ( - "github.com/iotaledger/goshimmer/packages/identity" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/salt" -) - -const ( - MARSHALED_PUBLIC_KEY_START = 0 - MARSHALED_ADDRESS_TYPE_START = MARSHALED_PUBLIC_KEY_END - MARSHALED_ADDRESS_START = MARSHALED_ADDRESS_TYPE_END - MARSHALED_PEERING_PORT_START = MARSHALED_ADDRESS_END - MARSHALED_GOSSIP_PORT_START = MARSHALED_PEERING_PORT_END - MARSHALED_SALT_START = MARSHALED_GOSSIP_PORT_END - - MARSHALED_PUBLIC_KEY_END = MARSHALED_PUBLIC_KEY_START + MARSHALED_PUBLIC_KEY_SIZE - MARSHALED_ADDRESS_TYPE_END = MARSHALED_ADDRESS_TYPE_START + MARSHALED_ADDRESS_TYPE_SIZE - MARSHALED_ADDRESS_END = MARSHALED_ADDRESS_START + MARSHALED_ADDRESS_SIZE - MARSHALED_PEERING_PORT_END = MARSHALED_PEERING_PORT_START + MARSHALED_PEERING_PORT_SIZE - MARSHALED_GOSSIP_PORT_END = MARSHALED_GOSSIP_PORT_START + MARSHALED_GOSSIP_PORT_SIZE - MARSHALED_SALT_END = MARSHALED_SALT_START + MARSHALED_SALT_SIZE - - MARSHALED_PUBLIC_KEY_SIZE = identity.PUBLIC_KEY_BYTE_LENGTH - MARSHALED_ADDRESS_TYPE_SIZE = 1 - MARSHALED_ADDRESS_SIZE = 16 - MARSHALED_PEERING_PORT_SIZE = 2 - MARSHALED_GOSSIP_PORT_SIZE = 2 - MARSHALED_SALT_SIZE = salt.SALT_MARSHALED_SIZE - - MARSHALED_TOTAL_SIZE = MARSHALED_SALT_END -) diff --git a/plugins/autopeering/types/peer/peer.go b/plugins/autopeering/types/peer/peer.go deleted file mode 100644 index eba117c743c5c2944c510259d678dd8c83611a2b..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/peer/peer.go +++ /dev/null @@ -1,246 +0,0 @@ -package peer - -import ( - "encoding/binary" - "net" - "strconv" - "sync" - "time" - - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/packages/identity" - "github.com/iotaledger/goshimmer/packages/network" - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/types" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/salt" - "github.com/pkg/errors" -) - -type Peer struct { - identity *identity.Identity - identityMutex sync.RWMutex - address net.IP - addressMutex sync.RWMutex - peeringPort uint16 - peeringPortMutex sync.RWMutex - gossipPort uint16 - gossipPortMutex sync.RWMutex - salt *salt.Salt - saltMutex sync.RWMutex - conn *network.ManagedConnection - connectMutex sync.RWMutex - firstSeen time.Time - firstSeenMutex sync.RWMutex - lastSeen time.Time - lastSeenMutex sync.RWMutex -} - -func (peer *Peer) GetIdentity() (result *identity.Identity) { - peer.identityMutex.RLock() - result = peer.identity - peer.identityMutex.RUnlock() - - return -} - -func (peer *Peer) SetIdentity(identity *identity.Identity) { - peer.identityMutex.Lock() - peer.identity = identity - peer.identityMutex.Unlock() -} - -func (peer *Peer) GetAddress() (result net.IP) { - peer.addressMutex.RLock() - result = peer.address - peer.addressMutex.RUnlock() - - return -} - -func (peer *Peer) SetAddress(address net.IP) { - peer.addressMutex.Lock() - peer.address = address - peer.addressMutex.Unlock() -} - -func (peer *Peer) GetPeeringPort() (result uint16) { - peer.peeringPortMutex.RLock() - result = peer.peeringPort - peer.peeringPortMutex.RUnlock() - - return -} - -func (peer *Peer) SetPeeringPort(port uint16) { - peer.peeringPortMutex.Lock() - peer.peeringPort = port - peer.peeringPortMutex.Unlock() -} - -func (peer *Peer) GetGossipPort() (result uint16) { - peer.gossipPortMutex.RLock() - result = peer.gossipPort - peer.gossipPortMutex.RUnlock() - - return -} - -func (peer *Peer) SetGossipPort(port uint16) { - peer.gossipPortMutex.Lock() - peer.gossipPort = port - peer.gossipPortMutex.Unlock() -} - -func (peer *Peer) GetSalt() (result *salt.Salt) { - peer.saltMutex.RLock() - result = peer.salt - peer.saltMutex.RUnlock() - - return -} - -func (peer *Peer) SetSalt(salt *salt.Salt) { - peer.saltMutex.Lock() - peer.salt = salt - peer.saltMutex.Unlock() -} - -func (peer *Peer) GetConn() (result *network.ManagedConnection) { - peer.connectMutex.RLock() - result = peer.conn - peer.connectMutex.RUnlock() - - return -} - -func (peer *Peer) SetConn(conn *network.ManagedConnection) { - peer.connectMutex.Lock() - peer.conn = conn - peer.connectMutex.Unlock() -} - -func Unmarshal(data []byte) (*Peer, error) { - if len(data) < MARSHALED_TOTAL_SIZE { - return nil, errors.New("size of marshaled peer is too small") - } - - peer := &Peer{ - identity: identity.NewIdentity(data[MARSHALED_PUBLIC_KEY_START:MARSHALED_PUBLIC_KEY_END]), - } - - switch data[MARSHALED_ADDRESS_TYPE_START] { - case types.ADDRESS_TYPE_IPV4: - peer.address = net.IP(data[MARSHALED_ADDRESS_START:MARSHALED_ADDRESS_END]).To4() - case types.ADDRESS_TYPE_IPV6: - peer.address = net.IP(data[MARSHALED_ADDRESS_START:MARSHALED_ADDRESS_END]).To16() - } - - peer.peeringPort = binary.BigEndian.Uint16(data[MARSHALED_PEERING_PORT_START:MARSHALED_PEERING_PORT_END]) - peer.gossipPort = binary.BigEndian.Uint16(data[MARSHALED_GOSSIP_PORT_START:MARSHALED_GOSSIP_PORT_END]) - - if unmarshaledSalt, err := salt.Unmarshal(data[MARSHALED_SALT_START:MARSHALED_SALT_END]); err != nil { - return nil, err - } else { - peer.salt = unmarshaledSalt - } - - return peer, nil -} - -// sends data and -func (peer *Peer) Send(data []byte, protocol types.ProtocolType, responseExpected bool) (bool, error) { - conn, dialed, err := peer.Connect(protocol) - if err != nil { - return false, err - } - - if _, err := conn.Write(data); err != nil { - return false, err - } - - if dialed && !responseExpected { - conn.Close() - } - - return dialed, nil -} - -func (peer *Peer) ConnectTCP() (*network.ManagedConnection, bool, error) { - peer.connectMutex.RLock() - - if peer.conn == nil { - peer.connectMutex.RUnlock() - peer.connectMutex.Lock() - defer peer.connectMutex.Unlock() - - if peer.conn == nil { - conn, err := net.Dial("tcp", peer.GetAddress().String()+":"+strconv.Itoa(int(peer.GetPeeringPort()))) - if err != nil { - return nil, false, errors.New("error when connecting to " + peer.String() + ": " + err.Error()) - } else { - peer.conn = network.NewManagedConnection(conn) - peer.conn.Events.Close.Attach(events.NewClosure(func() { - peer.SetConn(nil) - })) - - return peer.conn, true, nil - } - } - } else { - peer.connectMutex.RUnlock() - } - - return peer.conn, false, nil -} - -func (peer *Peer) ConnectUDP() (*network.ManagedConnection, bool, error) { - conn, err := net.Dial("udp", peer.GetAddress().String()+":"+strconv.Itoa(int(peer.GetPeeringPort()))) - if err != nil { - return nil, false, errors.New("error when connecting to " + peer.GetAddress().String() + ": " + err.Error()) - } - - return network.NewManagedConnection(conn), true, nil -} - -func (peer *Peer) Connect(protocol types.ProtocolType) (*network.ManagedConnection, bool, error) { - switch protocol { - case types.PROTOCOL_TYPE_TCP: - return peer.ConnectTCP() - case types.PROTOCOL_TYPE_UDP: - return peer.ConnectUDP() - default: - return nil, false, errors.New("unsupported peering protocol in peer " + peer.GetAddress().String()) - } -} - -func (peer *Peer) Marshal() []byte { - result := make([]byte, MARSHALED_TOTAL_SIZE) - - copy(result[MARSHALED_PUBLIC_KEY_START:MARSHALED_PUBLIC_KEY_END], - peer.GetIdentity().PublicKey[:MARSHALED_PUBLIC_KEY_SIZE]) - - switch len(peer.GetAddress()) { - case net.IPv4len: - result[MARSHALED_ADDRESS_TYPE_START] = types.ADDRESS_TYPE_IPV4 - case net.IPv6len: - result[MARSHALED_ADDRESS_TYPE_START] = types.ADDRESS_TYPE_IPV6 - default: - panic("invalid address in peer") - } - - copy(result[MARSHALED_ADDRESS_START:MARSHALED_ADDRESS_END], peer.GetAddress().To16()) - - binary.BigEndian.PutUint16(result[MARSHALED_PEERING_PORT_START:MARSHALED_PEERING_PORT_END], peer.GetPeeringPort()) - binary.BigEndian.PutUint16(result[MARSHALED_GOSSIP_PORT_START:MARSHALED_GOSSIP_PORT_END], peer.GetGossipPort()) - - copy(result[MARSHALED_SALT_START:MARSHALED_SALT_END], peer.GetSalt().Marshal()) - - return result -} - -func (peer *Peer) String() string { - if peer.GetIdentity() != nil { - return peer.GetAddress().String() + ":" + strconv.Itoa(int(peer.GetPeeringPort())) + " / " + peer.GetIdentity().StringIdentifier - } else { - return peer.GetAddress().String() + ":" + strconv.Itoa(int(peer.GetPeeringPort())) - } -} diff --git a/plugins/autopeering/types/peer/peer_test.go b/plugins/autopeering/types/peer/peer_test.go deleted file mode 100644 index be8838db94d4765966fb631cffe955e76e565d3d..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/peer/peer_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package peer - -import ( - "net" - "testing" - "time" - - "github.com/iotaledger/goshimmer/plugins/autopeering/types/salt" - - "github.com/iotaledger/goshimmer/packages/identity" - "github.com/magiconair/properties/assert" -) - -func TestPeer_MarshalUnmarshal(t *testing.T) { - peer := &Peer{ - address: net.IPv4(127, 0, 0, 1), - identity: identity.GenerateRandomIdentity(), - gossipPort: 123, - peeringPort: 456, - salt: salt.New(30 * time.Second), - } - - restoredPeer, err := Unmarshal(peer.Marshal()) - if err != nil { - t.Error(err) - } - - assert.Equal(t, peer.GetAddress(), restoredPeer.GetAddress()) - assert.Equal(t, peer.GetIdentity().StringIdentifier, restoredPeer.GetIdentity().StringIdentifier) - assert.Equal(t, peer.GetIdentity().PublicKey, restoredPeer.GetIdentity().PublicKey) - assert.Equal(t, peer.GetGossipPort(), restoredPeer.GetGossipPort()) - assert.Equal(t, peer.GetPeeringPort(), restoredPeer.GetPeeringPort()) - assert.Equal(t, peer.GetSalt().GetBytes(), restoredPeer.GetSalt().GetBytes()) - // time.time cannot be compared with reflect.DeepEqual, so we cannot use assert.Equal here - if !peer.GetSalt().GetExpirationTime().Equal(restoredPeer.GetSalt().GetExpirationTime()) { - t.Errorf("got %v want %v", restoredPeer.GetSalt().GetExpirationTime(), peer.GetSalt().GetExpirationTime()) - } -} diff --git a/plugins/autopeering/types/peerlist/peer_list.go b/plugins/autopeering/types/peerlist/peer_list.go deleted file mode 100644 index 557c14c86d097b8aea448201bd176d5d52fccf16..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/peerlist/peer_list.go +++ /dev/null @@ -1,94 +0,0 @@ -package peerlist - -import ( - "sort" - "sync" - - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" -) - -type PeerList struct { - sync.RWMutex - internal []*peer.Peer -} - -func NewPeerList(list ...[]*peer.Peer) *PeerList { - if list != nil { - return &PeerList{ - internal: list[0], - } - } - return &PeerList{ - internal: make([]*peer.Peer, 0), - } -} - -func (pl *PeerList) Len() int { - pl.RLock() - defer pl.RUnlock() - return len(pl.internal) -} - -func (pl *PeerList) AddPeer(peer *peer.Peer) { - pl.Lock() - pl.internal = append(pl.internal, peer) - pl.Unlock() -} - -func (pl *PeerList) GetPeers() (result []*peer.Peer) { - pl.RLock() - result = pl.internal - pl.RUnlock() - - return -} - -func (pl *PeerList) Update(list []*peer.Peer) { - pl.Lock() - pl.internal = list - pl.Unlock() - - return -} - -func (pl *PeerList) SwapPeers(i, j int) { - pl.Lock() - pl.internal[i], pl.internal[j] = pl.internal[j], pl.internal[i] - pl.Unlock() -} - -func (pl *PeerList) Clone() *PeerList { - list := make([]*peer.Peer, pl.Len()) - pl.RLock() - copy(list, pl.internal) - pl.RUnlock() - - return NewPeerList(list) -} - -func (pl *PeerList) Filter(predicate func(p *peer.Peer) bool) *PeerList { - peerList := make([]*peer.Peer, pl.Len()) - - counter := 0 - pl.RLock() - for _, peer := range pl.internal { - if predicate(peer) { - peerList[counter] = peer - counter++ - } - } - pl.RUnlock() - - return NewPeerList(peerList[:counter]) -} - -// Sorts the PeerRegister by their distance to an anchor. -func (pl *PeerList) Sort(distance func(p *peer.Peer) uint64) *PeerList { - pl.Lock() - defer pl.Unlock() - sort.Slice(pl.internal, func(i, j int) bool { - return distance(pl.internal[i]) < distance(pl.internal[j]) - }) - - return pl -} diff --git a/plugins/autopeering/types/peerregister/events.go b/plugins/autopeering/types/peerregister/events.go deleted file mode 100644 index ee3479673755c479c745f281e74514ffd718ae52..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/peerregister/events.go +++ /dev/null @@ -1,16 +0,0 @@ -package peerregister - -import ( - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" -) - -type peerRegisterEvents struct { - Add *events.Event - Update *events.Event - Remove *events.Event -} - -func peerCaller(handler interface{}, params ...interface{}) { - handler.(func(*peer.Peer))(params[0].(*peer.Peer)) -} diff --git a/plugins/autopeering/types/peerregister/peerMap.go b/plugins/autopeering/types/peerregister/peerMap.go deleted file mode 100644 index 2e1460bf851f169f5f1cd291c82c7a63cc11069a..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/peerregister/peerMap.go +++ /dev/null @@ -1,81 +0,0 @@ -package peerregister - -import ( - "sync" - - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" -) - -// PeerMap is the mapping of peer identifier and their peer struct -// It uses a mutex to handle concurrent access to its internal map -type PeerMap struct { - sync.RWMutex - internal map[string]*peer.Peer -} - -// NewPeerMap returns a new PeerMap -func NewPeerMap() *PeerMap { - return &PeerMap{ - internal: make(map[string]*peer.Peer), - } -} - -// Len returns the number of peers stored in a PeerMap -func (pm *PeerMap) Len() int { - pm.RLock() - defer pm.RUnlock() - return len(pm.internal) -} - -// GetMap returns the content of the entire internal map -func (pm *PeerMap) GetMap() map[string]*peer.Peer { - newMap := make(map[string]*peer.Peer) - pm.RLock() - defer pm.RUnlock() - for k, v := range pm.internal { - newMap[k] = v - } - return newMap -} - -// GetMap returns the content of the entire internal map -func (pm *PeerMap) GetSlice() []*peer.Peer { - newSlice := make([]*peer.Peer, pm.Len()) - pm.RLock() - defer pm.RUnlock() - i := 0 - for _, v := range pm.internal { - newSlice[i] = v - i++ - } - return newSlice -} - -// Load returns the peer for a given key. -// It also return a bool to communicate the presence of the given -// peer into the internal map -func (pm *PeerMap) Load(key string) (value *peer.Peer, ok bool) { - pm.RLock() - defer pm.RUnlock() - result, ok := pm.internal[key] - return result, ok -} - -// Delete removes the entire entry for a given key and return true if successful -func (pm *PeerMap) Delete(key string) (deletedPeer *peer.Peer, ok bool) { - deletedPeer, ok = pm.Load(key) - if !ok { - return nil, false - } - pm.Lock() - defer pm.Unlock() - delete(pm.internal, key) - return deletedPeer, true -} - -// Store adds a new peer to the PeerMap -func (pm *PeerMap) Store(key string, value *peer.Peer) { - pm.Lock() - defer pm.Unlock() - pm.internal[key] = value -} diff --git a/plugins/autopeering/types/peerregister/peer_register.go b/plugins/autopeering/types/peerregister/peer_register.go deleted file mode 100644 index d6dd79d6015d46ac9c912b5fce792aad8b9f6fbc..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/peerregister/peer_register.go +++ /dev/null @@ -1,87 +0,0 @@ -package peerregister - -import ( - "bytes" - "sync" - - "github.com/iotaledger/goshimmer/packages/accountability" - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/request" -) - -type PeerRegister struct { - Peers *PeerMap - Events peerRegisterEvents - lock sync.RWMutex -} - -func New() *PeerRegister { - return &PeerRegister{ - Peers: NewPeerMap(), - Events: peerRegisterEvents{ - Add: events.NewEvent(peerCaller), - Update: events.NewEvent(peerCaller), - Remove: events.NewEvent(peerCaller), - }, - } -} - -// returns true if a new entry was added -func (this *PeerRegister) AddOrUpdate(peer *peer.Peer) bool { - if peer.GetIdentity() == nil || bytes.Equal(peer.GetIdentity().Identifier, accountability.OwnId().Identifier) { - return false - } - - if existingPeer, exists := this.Peers.Load(peer.GetIdentity().StringIdentifier); exists { - existingPeer.SetAddress(peer.GetAddress()) - existingPeer.SetGossipPort(peer.GetGossipPort()) - existingPeer.SetPeeringPort(peer.GetPeeringPort()) - existingPeer.SetSalt(peer.GetSalt()) - - // also update the public key if not yet present - if existingPeer.GetIdentity().PublicKey == nil { - existingPeer.SetIdentity(peer.GetIdentity()) - } - - this.Events.Update.Trigger(existingPeer) - - return false - } else { - this.Peers.Store(peer.GetIdentity().StringIdentifier, peer) - - this.Events.Add.Trigger(peer) - - return true - } -} - -// by calling defer peerRegister.Lock()() we can auto-lock AND unlock (note: two parentheses) -func (this *PeerRegister) Lock() func() { - this.lock.Lock() - - return this.lock.Unlock -} - -func (this *PeerRegister) Remove(key string) { - if peerEntry, exists := this.Peers.Delete(key); exists { - this.Events.Remove.Trigger(peerEntry) - } -} - -func (this *PeerRegister) Contains(key string) bool { - _, exists := this.Peers.Load(key) - return exists -} - -func (this *PeerRegister) Filter(filterFn func(this *PeerRegister, req *request.Request) *PeerRegister, req *request.Request) *PeerRegister { - return filterFn(this, req) -} - -// func (this *PeerRegister) List() *peerlist.PeerList { -// return peerlist.NewPeerList(this.Peers.GetSlice()) -// } - -func (this *PeerRegister) List() []*peer.Peer { - return this.Peers.GetSlice() -} diff --git a/plugins/autopeering/types/ping/constants.go b/plugins/autopeering/types/ping/constants.go deleted file mode 100644 index 22b17d9d54a0c8cbf6d851cb7d5e39a68e8a0c17..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/ping/constants.go +++ /dev/null @@ -1,29 +0,0 @@ -package ping - -import ( - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/constants" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" -) - -const ( - MARSHALED_PACKET_HEADER = 0x04 - - PACKET_HEADER_START = 0 - MARSHALED_ISSUER_START = PACKET_HEADER_END - MARSHALED_PEERS_START = MARSHALED_ISSUER_END - MARSHALED_SIGNATURE_START = MARSHALED_PEERS_END - - PACKET_HEADER_END = PACKET_HEADER_START + PACKET_HEADER_SIZE - MARSHALED_ISSUER_END = MARSHALED_ISSUER_START + MARSHALED_ISSUER_SIZE - MARSHALED_PEERS_END = MARSHALED_PEERS_START + MARSHALED_PEERS_SIZE - MARSHALED_SIGNATURE_END = MARSHALED_SIGNATURE_START + MARSHALED_SIGNATURE_SIZE - - PACKET_HEADER_SIZE = 1 - MARSHALED_ISSUER_SIZE = peer.MARSHALED_TOTAL_SIZE - MARSHALED_PEER_ENTRY_FLAG_SIZE = 1 - MARSHALED_PEER_ENTRY_SIZE = MARSHALED_PEER_ENTRY_FLAG_SIZE + peer.MARSHALED_TOTAL_SIZE - MARSHALED_PEERS_SIZE = MARSHALED_PEER_ENTRY_SIZE * constants.NEIGHBOR_COUNT - MARSHALED_SIGNATURE_SIZE = 65 - - MARSHALED_TOTAL_SIZE = MARSHALED_SIGNATURE_END -) diff --git a/plugins/autopeering/types/ping/errors.go b/plugins/autopeering/types/ping/errors.go deleted file mode 100644 index 51825205c449771cbc0feb3222adce9305fff6ad..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/ping/errors.go +++ /dev/null @@ -1,8 +0,0 @@ -package ping - -import "github.com/pkg/errors" - -var ( - ErrInvalidSignature = errors.New("invalid signature in ping") - ErrMalformedPing = errors.New("malformed ping") -) diff --git a/plugins/autopeering/types/ping/ping.go b/plugins/autopeering/types/ping/ping.go deleted file mode 100644 index e8492c08244956427befa3fbc3914d2cd9689b30..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/ping/ping.go +++ /dev/null @@ -1,104 +0,0 @@ -package ping - -import ( - "bytes" - "sync" - - "github.com/iotaledger/goshimmer/packages/identity" - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/constants" - "github.com/iotaledger/goshimmer/plugins/autopeering/saltmanager" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peerlist" -) - -type Ping struct { - Issuer *peer.Peer - Neighbors *peerlist.PeerList - signature [MARSHALED_SIGNATURE_SIZE]byte - signatureMutex sync.RWMutex -} - -func (ping *Ping) GetSignature() (result []byte) { - ping.signatureMutex.RLock() - result = make([]byte, len(ping.signature)) - copy(result[:], ping.signature[:]) - ping.signatureMutex.RUnlock() - - return -} - -func (ping *Ping) SetSignature(signature []byte) { - ping.signatureMutex.Lock() - copy(ping.signature[:], signature[:]) - ping.signatureMutex.Unlock() -} - -func Unmarshal(data []byte) (*Ping, error) { - if data[0] != MARSHALED_PACKET_HEADER || len(data) != MARSHALED_TOTAL_SIZE { - return nil, ErrMalformedPing - } - - ping := &Ping{ - Neighbors: peerlist.NewPeerList(), - } - - if unmarshaledPeer, err := peer.Unmarshal(data[MARSHALED_ISSUER_START:MARSHALED_ISSUER_END]); err != nil { - return nil, err - } else { - ping.Issuer = unmarshaledPeer - } - if err := saltmanager.CheckSalt(ping.Issuer.GetSalt()); err != nil { - return nil, err - } - - offset := MARSHALED_PEERS_START - for i := 0; i < constants.NEIGHBOR_COUNT; i++ { - if data[offset] == 1 { - if unmarshaledPing, err := peer.Unmarshal(data[offset+1 : offset+MARSHALED_PEER_ENTRY_SIZE]); err != nil { - return nil, err - } else { - ping.Neighbors.AddPeer(unmarshaledPing) - } - } - - offset += MARSHALED_PEER_ENTRY_SIZE - } - - if issuer, err := identity.FromSignedData(data[:MARSHALED_SIGNATURE_START], data[MARSHALED_SIGNATURE_START:]); err != nil { - return nil, err - } else { - if !bytes.Equal(issuer.Identifier, ping.Issuer.GetIdentity().Identifier) { - return nil, ErrInvalidSignature - } - } - ping.SetSignature(data[MARSHALED_SIGNATURE_START:MARSHALED_SIGNATURE_END]) - - return ping, nil -} - -func (ping *Ping) Marshal() []byte { - result := make([]byte, MARSHALED_TOTAL_SIZE) - - result[PACKET_HEADER_START] = MARSHALED_PACKET_HEADER - copy(result[MARSHALED_ISSUER_START:MARSHALED_ISSUER_END], ping.Issuer.Marshal()) - if ping.Neighbors != nil { - for i, neighbor := range ping.Neighbors.GetPeers() { - entryStartOffset := MARSHALED_PEERS_START + i*MARSHALED_PEER_ENTRY_SIZE - - result[entryStartOffset] = 1 - - copy(result[entryStartOffset+1:entryStartOffset+MARSHALED_PEER_ENTRY_SIZE], neighbor.Marshal()) - } - } - copy(result[MARSHALED_SIGNATURE_START:MARSHALED_SIGNATURE_END], ping.GetSignature()) - - return result -} - -func (this *Ping) Sign() { - if signature, err := this.Issuer.GetIdentity().Sign(this.Marshal()[:MARSHALED_SIGNATURE_START]); err != nil { - panic(err) - } else { - this.SetSignature(signature) - } -} diff --git a/plugins/autopeering/types/request/constants.go b/plugins/autopeering/types/request/constants.go deleted file mode 100644 index c1e707153f828214885a945585ce98017665b8f7..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/request/constants.go +++ /dev/null @@ -1,23 +0,0 @@ -package request - -import ( - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" -) - -const ( - PACKET_HEADER_SIZE = 1 - ISSUER_SIZE = peer.MARSHALED_TOTAL_SIZE - SIGNATURE_SIZE = 65 - - PACKET_HEADER_START = 0 - ISSUER_START = PACKET_HEADER_END - SIGNATURE_START = ISSUER_END - - PACKET_HEADER_END = PACKET_HEADER_START + PACKET_HEADER_SIZE - ISSUER_END = ISSUER_START + ISSUER_SIZE - SIGNATURE_END = SIGNATURE_START + SIGNATURE_SIZE - - MARSHALED_TOTAL_SIZE = SIGNATURE_END - - MARSHALED_PACKET_HEADER = 0xBE -) diff --git a/plugins/autopeering/types/request/errors.go b/plugins/autopeering/types/request/errors.go deleted file mode 100644 index 34831a9420ca5d18f44ea58d629b8503b840af95..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/request/errors.go +++ /dev/null @@ -1,10 +0,0 @@ -package request - -import "github.com/pkg/errors" - -var ( - ErrPublicSaltExpired = errors.New("expired public salt in peering request") - ErrPublicSaltInvalidLifetime = errors.New("invalid public salt lifetime") - ErrInvalidSignature = errors.New("invalid signature in peering request") - ErrMalformedPeeringRequest = errors.New("malformed peering request") -) diff --git a/plugins/autopeering/types/request/request.go b/plugins/autopeering/types/request/request.go deleted file mode 100644 index 98d9f1d5fef4a17c496080d283859d4158c98c99..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/request/request.go +++ /dev/null @@ -1,116 +0,0 @@ -package request - -import ( - "bytes" - "sync" - "time" - - "github.com/iotaledger/goshimmer/packages/identity" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/ownpeer" - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/types" - "github.com/iotaledger/goshimmer/plugins/autopeering/saltmanager" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/response" -) - -type Request struct { - Issuer *peer.Peer - signature [SIGNATURE_SIZE]byte - signatureMutex sync.RWMutex -} - -func (r *Request) GetSignature() (result []byte) { - r.signatureMutex.RLock() - result = make([]byte, len(r.signature)) - copy(result[:], r.signature[:]) - r.signatureMutex.RUnlock() - - return -} - -func (r *Request) SetSignature(signature []byte) { - r.signatureMutex.Lock() - copy(r.signature[:], signature[:]) - r.signatureMutex.Unlock() -} - -func Unmarshal(data []byte) (*Request, error) { - if data[0] != MARSHALED_PACKET_HEADER || len(data) != MARSHALED_TOTAL_SIZE { - return nil, ErrMalformedPeeringRequest - } - - peeringRequest := &Request{} - - if unmarshaledPeer, err := peer.Unmarshal(data[ISSUER_START:ISSUER_END]); err != nil { - return nil, err - } else { - peeringRequest.Issuer = unmarshaledPeer - } - - now := time.Now() - if peeringRequest.Issuer.GetSalt().GetExpirationTime().Before(now.Add(-1 * time.Minute)) { - return nil, ErrPublicSaltExpired - } - if peeringRequest.Issuer.GetSalt().GetExpirationTime().After(now.Add(saltmanager.PUBLIC_SALT_LIFETIME + 1*time.Minute)) { - return nil, ErrPublicSaltInvalidLifetime - } - - if issuer, err := identity.FromSignedData(data[:SIGNATURE_START], data[SIGNATURE_START:]); err != nil { - return nil, err - } else { - if !bytes.Equal(issuer.Identifier, peeringRequest.Issuer.GetIdentity().Identifier) { - return nil, ErrInvalidSignature - } - } - peeringRequest.SetSignature(data[SIGNATURE_START:SIGNATURE_END]) - - return peeringRequest, nil -} - -func (this *Request) Accept(peers []*peer.Peer) error { - peeringResponse := &response.Response{ - Type: response.TYPE_ACCEPT, - Issuer: ownpeer.INSTANCE, - Peers: peers, - } - peeringResponse.Sign() - - if _, err := this.Issuer.Send(peeringResponse.Marshal(), types.PROTOCOL_TYPE_TCP, false); err != nil { - return err - } - - return nil -} - -func (this *Request) Reject(peers []*peer.Peer) error { - peeringResponse := &response.Response{ - Type: response.TYPE_REJECT, - Issuer: ownpeer.INSTANCE, - Peers: peers, - } - peeringResponse.Sign() - - if _, err := this.Issuer.Send(peeringResponse.Marshal(), types.PROTOCOL_TYPE_TCP, false); err != nil { - return err - } - - return nil -} - -func (this *Request) Sign() { - if signature, err := this.Issuer.GetIdentity().Sign(this.Marshal()[:SIGNATURE_START]); err != nil { - panic(err) - } else { - this.SetSignature(signature) - } -} - -func (this *Request) Marshal() []byte { - result := make([]byte, MARSHALED_TOTAL_SIZE) - - result[PACKET_HEADER_START] = MARSHALED_PACKET_HEADER - copy(result[ISSUER_START:ISSUER_END], this.Issuer.Marshal()) - copy(result[SIGNATURE_START:SIGNATURE_END], this.GetSignature()[:SIGNATURE_SIZE]) - - return result -} diff --git a/plugins/autopeering/types/response/constants.go b/plugins/autopeering/types/response/constants.go deleted file mode 100644 index 9ef796feee6130ba89aba3c65da081bc89736264..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/response/constants.go +++ /dev/null @@ -1,35 +0,0 @@ -package response - -import ( - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/constants" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" -) - -const ( - TYPE_REJECT = Type(0) - TYPE_ACCEPT = Type(1) - - MARSHALED_PEERS_AMOUNT = constants.NEIGHBOR_COUNT + constants.NEIGHBOR_COUNT*constants.NEIGHBOR_COUNT - MARHSALLED_PACKET_HEADER = 0xBC - - MARSHALED_PACKET_HEADER_START = 0 - MARSHALED_TYPE_START = MARSHALED_PACKET_HEADER_END - MARSHALED_ISSUER_START = MARSHALED_TYPE_END - MARSHALED_PEERS_START = MARSHALED_ISSUER_END - MARSHALED_SIGNATURE_START = MARSHALED_PEERS_END - - MARSHALED_PACKET_HEADER_END = MARSHALED_PACKET_HEADER_START + MARSHALED_PACKET_HEADER_SIZE - MARSHALED_TYPE_END = MARSHALED_TYPE_START + MARSHALED_TYPE_SIZE - MARSHALED_PEERS_END = MARSHALED_PEERS_START + MARSHALED_PEERS_SIZE - MARSHALED_ISSUER_END = MARSHALED_ISSUER_START + MARSHALED_ISSUER_SIZE - MARSHALED_SIGNATURE_END = MARSHALED_SIGNATURE_START + MARSHALED_SIGNATURE_SIZE - - MARSHALED_PACKET_HEADER_SIZE = 1 - MARSHALED_TYPE_SIZE = 1 - MARSHALED_ISSUER_SIZE = peer.MARSHALED_TOTAL_SIZE - MARSHALED_PEER_FLAG_SIZE = 1 - MARSHALED_PEER_SIZE = MARSHALED_PEER_FLAG_SIZE + peer.MARSHALED_TOTAL_SIZE - MARSHALED_PEERS_SIZE = MARSHALED_PEERS_AMOUNT * MARSHALED_PEER_SIZE - MARSHALED_SIGNATURE_SIZE = 65 - MARSHALED_TOTAL_SIZE = MARSHALED_SIGNATURE_END -) diff --git a/plugins/autopeering/types/response/errors.go b/plugins/autopeering/types/response/errors.go deleted file mode 100644 index 34d823a8666483d7bc3b0e1a7b113a581244825e..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/response/errors.go +++ /dev/null @@ -1,7 +0,0 @@ -package response - -import "github.com/pkg/errors" - -var ( - ErrInvalidSignature = errors.New("invalid signature in peering request") -) diff --git a/plugins/autopeering/types/response/response.go b/plugins/autopeering/types/response/response.go deleted file mode 100644 index 6a398c4f061e36bef23903192f0eb9d55653adb2..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/response/response.go +++ /dev/null @@ -1,110 +0,0 @@ -package response - -import ( - "bytes" - "sync" - - "github.com/iotaledger/goshimmer/packages/identity" - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/constants" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" - "github.com/pkg/errors" -) - -type Response struct { - Type Type - Issuer *peer.Peer - Peers []*peer.Peer - signature [MARSHALED_SIGNATURE_SIZE]byte - signatureMutex sync.RWMutex -} - -func (r *Response) GetSignature() (result []byte) { - r.signatureMutex.RLock() - result = make([]byte, len(r.signature)) - copy(result[:], r.signature[:]) - r.signatureMutex.RUnlock() - - return -} - -func (r *Response) SetSignature(signature []byte) { - r.signatureMutex.Lock() - copy(r.signature[:], signature[:]) - r.signatureMutex.Unlock() -} - -func Unmarshal(data []byte) (*Response, error) { - if data[0] != MARHSALLED_PACKET_HEADER || len(data) < MARSHALED_TOTAL_SIZE { - return nil, errors.New("malformed peering response") - } - - peeringResponse := &Response{ - Type: data[MARSHALED_TYPE_START], - Peers: make([]*peer.Peer, 0), - } - - if unmarshaledPeer, err := peer.Unmarshal(data[MARSHALED_ISSUER_START:MARSHALED_ISSUER_END]); err != nil { - return nil, err - } else { - peeringResponse.Issuer = unmarshaledPeer - } - - for i := 0; i < MARSHALED_PEERS_AMOUNT; i++ { - PEERING_RESPONSE_MARSHALED_PEER_START := MARSHALED_PEERS_START + (i * MARSHALED_PEER_SIZE) - PEERING_RESPONSE_MARSHALED_PEER_END := PEERING_RESPONSE_MARSHALED_PEER_START + MARSHALED_PEER_SIZE - - if data[PEERING_RESPONSE_MARSHALED_PEER_START] == 1 { - peer, err := peer.Unmarshal(data[PEERING_RESPONSE_MARSHALED_PEER_START+1 : PEERING_RESPONSE_MARSHALED_PEER_END]) - if err != nil { - return nil, err - } - - peeringResponse.Peers = append(peeringResponse.Peers, peer) - } - } - - if issuer, err := identity.FromSignedData(data[:MARSHALED_SIGNATURE_START], data[MARSHALED_SIGNATURE_START:]); err != nil { - return nil, err - } else { - if !bytes.Equal(issuer.Identifier, peeringResponse.Issuer.GetIdentity().Identifier) { - return nil, ErrInvalidSignature - } - } - peeringResponse.SetSignature(data[MARSHALED_SIGNATURE_START:MARSHALED_SIGNATURE_END]) - - return peeringResponse, nil -} - -func (this *Response) Sign() *Response { - dataToSign := this.Marshal()[:MARSHALED_SIGNATURE_START] - if signature, err := this.Issuer.GetIdentity().Sign(dataToSign); err != nil { - panic(err) - } else { - this.SetSignature(signature) - } - - return this -} - -func (this *Response) Marshal() []byte { - result := make([]byte, MARSHALED_TOTAL_SIZE) - - result[MARSHALED_PACKET_HEADER_START] = MARHSALLED_PACKET_HEADER - result[MARSHALED_TYPE_START] = this.Type - - copy(result[MARSHALED_ISSUER_START:MARSHALED_ISSUER_END], this.Issuer.Marshal()) - - for i, peer := range this.Peers { - if i < constants.NEIGHBOR_COUNT { - PEERING_RESPONSE_MARSHALED_PEER_START := MARSHALED_PEERS_START + (i * MARSHALED_PEER_SIZE) - PEERING_RESPONSE_MARSHALED_PEER_END := PEERING_RESPONSE_MARSHALED_PEER_START + MARSHALED_PEER_SIZE - - result[PEERING_RESPONSE_MARSHALED_PEER_START] = 1 - copy(result[PEERING_RESPONSE_MARSHALED_PEER_START+1:PEERING_RESPONSE_MARSHALED_PEER_END], peer.Marshal()[:MARSHALED_PEER_SIZE-1]) - } - } - - copy(result[MARSHALED_SIGNATURE_START:MARSHALED_SIGNATURE_END], this.GetSignature()[:MARSHALED_SIGNATURE_SIZE]) - - return result -} diff --git a/plugins/autopeering/types/response/response_test.go b/plugins/autopeering/types/response/response_test.go deleted file mode 100644 index 1cfc178e93327fb02d011514d8315c6595d3c2bb..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/response/response_test.go +++ /dev/null @@ -1,56 +0,0 @@ -package response - -import ( - "net" - "testing" - "time" - - "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" - - "github.com/iotaledger/goshimmer/packages/identity" - "github.com/iotaledger/goshimmer/plugins/autopeering/types/salt" -) - -func TestPeer_MarshalUnmarshal(t *testing.T) { - issuer := &peer.Peer{} - issuer.SetAddress(net.IPv4(127, 0, 0, 1)) - issuer.SetIdentity(identity.GenerateRandomIdentity()) - issuer.SetGossipPort(123) - issuer.SetPeeringPort(456) - issuer.SetSalt(salt.New(30 * time.Second)) - - peers := make([]*peer.Peer, 3) - - peers[0] = &peer.Peer{} - peers[0].SetAddress(net.IPv4(127, 0, 0, 1)) - peers[0].SetIdentity(identity.GenerateRandomIdentity()) - peers[0].SetGossipPort(124) - peers[0].SetPeeringPort(457) - peers[0].SetSalt(salt.New(30 * time.Second)) - - peers[1] = &peer.Peer{} - peers[1].SetAddress(net.IPv4(127, 0, 0, 1)) - peers[1].SetIdentity(identity.GenerateRandomIdentity()) - peers[1].SetGossipPort(125) - peers[1].SetPeeringPort(458) - peers[1].SetSalt(salt.New(30 * time.Second)) - - peers[2] = &peer.Peer{} - peers[2].SetAddress(net.IPv4(127, 0, 0, 1)) - peers[2].SetIdentity(identity.GenerateRandomIdentity()) - peers[2].SetGossipPort(126) - peers[2].SetPeeringPort(459) - peers[2].SetSalt(salt.New(30 * time.Second)) - - response := &Response{ - Issuer: issuer, - Type: TYPE_ACCEPT, - Peers: peers, - } - response.Sign() - - _, err := Unmarshal(response.Marshal()) - if err != nil { - t.Error(err) - } -} diff --git a/plugins/autopeering/types/response/types.go b/plugins/autopeering/types/response/types.go deleted file mode 100644 index 64e48e6c2dec3026fbe222ab8814a2084ab53759..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/response/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package response - -type Type = byte diff --git a/plugins/autopeering/types/salt/constants.go b/plugins/autopeering/types/salt/constants.go deleted file mode 100644 index 399d6a728321eed83f5d0eb2e72d84eb745650cb..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/salt/constants.go +++ /dev/null @@ -1,14 +0,0 @@ -package salt - -const ( - SALT_BYTES_SIZE = 20 - SALT_TIME_SIZE = 15 - - SALT_BYTES_START = 0 - SALT_TIME_START = SALT_BYTES_END - - SALT_BYTES_END = SALT_BYTES_START + SALT_BYTES_SIZE - SALT_TIME_END = SALT_TIME_START + SALT_TIME_SIZE - - SALT_MARSHALED_SIZE = SALT_TIME_END -) diff --git a/plugins/autopeering/types/salt/salt.go b/plugins/autopeering/types/salt/salt.go deleted file mode 100644 index c52a14b7d8aeb9ae4f00559fde627621b1b58fd5..0000000000000000000000000000000000000000 --- a/plugins/autopeering/types/salt/salt.go +++ /dev/null @@ -1,92 +0,0 @@ -package salt - -import ( - "crypto/rand" - "sync" - "time" - - "github.com/pkg/errors" -) - -type Salt struct { - bytes []byte - bytesMutex sync.RWMutex - expirationTime time.Time - expirationTimeMutex sync.RWMutex -} - -func (salt *Salt) GetBytes() (result []byte) { - salt.bytesMutex.RLock() - result = make([]byte, len(salt.bytes)) - copy(result[:], salt.bytes[:]) - salt.bytesMutex.RUnlock() - - return -} - -func (salt *Salt) SetBytes(b []byte) { - salt.bytesMutex.Lock() - salt.bytes = make([]byte, len(b)) - copy(salt.bytes[:], b[:]) - salt.bytesMutex.Unlock() -} - -func (salt *Salt) GetExpirationTime() (result time.Time) { - salt.expirationTimeMutex.RLock() - result = salt.expirationTime - salt.expirationTimeMutex.RUnlock() - - return -} - -func (salt *Salt) SetExpirationTime(t time.Time) { - salt.expirationTimeMutex.Lock() - salt.expirationTime = t - salt.expirationTimeMutex.Unlock() -} - -func New(lifetime time.Duration) *Salt { - salt := &Salt{ - bytes: make([]byte, SALT_BYTES_SIZE), - expirationTime: time.Now().Add(lifetime), - } - - if _, err := rand.Read(salt.bytes); err != nil { - panic(err) - } - - return salt -} - -func Unmarshal(marshaledSalt []byte) (*Salt, error) { - if len(marshaledSalt) < SALT_MARSHALED_SIZE { - return nil, errors.New("marshaled salt bytes not long enough") - } - - salt := &Salt{ - bytes: make([]byte, SALT_BYTES_SIZE), - } - salt.SetBytes(marshaledSalt[SALT_BYTES_START:SALT_BYTES_END]) - - var expTime time.Time - if err := expTime.UnmarshalBinary(marshaledSalt[SALT_TIME_START:SALT_TIME_END]); err != nil { - return nil, err - } - salt.SetExpirationTime(expTime) - - return salt, nil -} - -func (this *Salt) Marshal() []byte { - result := make([]byte, SALT_BYTES_SIZE+SALT_TIME_SIZE) - - copy(result[SALT_BYTES_START:SALT_BYTES_END], this.GetBytes()) - expTime := this.GetExpirationTime() - if bytes, err := expTime.MarshalBinary(); err != nil { - panic(err) - } else { - copy(result[SALT_TIME_START:SALT_TIME_END], bytes) - } - - return result -} diff --git a/plugins/bundleprocessor/bundleprocessor_test.go b/plugins/bundleprocessor/bundleprocessor_test.go index 14834c67c2b0ed49ef7b418cee8309c5f7e21afd..fdb22a5d9ce213421ebe6f9c06228a13c8281524 100644 --- a/plugins/bundleprocessor/bundleprocessor_test.go +++ b/plugins/bundleprocessor/bundleprocessor_test.go @@ -4,7 +4,7 @@ import ( "sync" "testing" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/model/bundle" "github.com/iotaledger/goshimmer/packages/model/value_transaction" diff --git a/plugins/bundleprocessor/events.go b/plugins/bundleprocessor/events.go index 6deb5fbb853361d764101be74f94f15ae0abdaab..fc7d52a6bfa565588f6a32940385514fc24db2ea 100644 --- a/plugins/bundleprocessor/events.go +++ b/plugins/bundleprocessor/events.go @@ -2,7 +2,7 @@ package bundleprocessor import ( "github.com/iotaledger/goshimmer/packages/errors" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/model/bundle" "github.com/iotaledger/goshimmer/packages/model/value_transaction" ) diff --git a/plugins/bundleprocessor/plugin.go b/plugins/bundleprocessor/plugin.go index db1e1c28cfac3fd8d13041466e6081c6b9e8ed8f..c4592a63624863cb59582a30ef6dfd448c51dd31 100644 --- a/plugins/bundleprocessor/plugin.go +++ b/plugins/bundleprocessor/plugin.go @@ -3,7 +3,7 @@ package bundleprocessor import ( "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/errors" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/tangle" diff --git a/plugins/cli/plugin.go b/plugins/cli/plugin.go index ae97189d4520992e2d66e16eda5569afc1533042..a8b3ea95132348246d60cc02a84d0c0302e09cc4 100644 --- a/plugins/cli/plugin.go +++ b/plugins/cli/plugin.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/parameter" ) diff --git a/plugins/dashboard/plugin.go b/plugins/dashboard/plugin.go index a292f80a9b21463a33e9afa21cecb68f7ef10ee6..5b38ebed5716cdc56ba25dfbcb25e509d386775a 100644 --- a/plugins/dashboard/plugin.go +++ b/plugins/dashboard/plugin.go @@ -7,9 +7,9 @@ import ( "golang.org/x/net/context" "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/events" "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/metrics" + "github.com/iotaledger/hive.go/events" ) var server *http.Server diff --git a/plugins/dashboard/tps.go b/plugins/dashboard/tps.go index a35d4721c4ba3b484566d51906b7880dfbb827b9..ac1f5ceb24ca83108f80ff4775925e6146836cf5 100644 --- a/plugins/dashboard/tps.go +++ b/plugins/dashboard/tps.go @@ -6,18 +6,15 @@ import ( "html/template" "math" "net/http" - "sync" "strconv" + "sync" "time" "github.com/gorilla/websocket" "github.com/iotaledger/goshimmer/packages/accountability" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/goshimmer/plugins/autopeering" "github.com/iotaledger/goshimmer/plugins/metrics" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/neighborhood" + "github.com/iotaledger/hive.go/events" ) var ( @@ -72,12 +69,12 @@ func GetStatus() *Status { } uptime += fmt.Sprintf("%02ds ", int(duration.Seconds())%60) - return &Status { - Id: accountability.OwnId().StringIdentifier, - Neighbor: "Neighbors: " + strconv.Itoa(chosenneighbors.INSTANCE.Peers.Len())+" chosen / "+strconv.Itoa(acceptedneighbors.INSTANCE.Peers.Len())+" accepted / "+strconv.Itoa(chosenneighbors.INSTANCE.Peers.Len()+acceptedneighbors.INSTANCE.Peers.Len())+" total", - KnownPeer: "Known Peers: "+ strconv.Itoa(knownpeers.INSTANCE.Peers.Len())+" total / "+strconv.Itoa(neighborhood.INSTANCE.Peers.Len())+" neighborhood", - Uptime: uptime, - } + return &Status{ + Id: accountability.OwnId().StringIdentifier, + Neighbor: "Neighbors: " + strconv.Itoa(len(autopeering.Selection.GetOutgoingNeighbors())) + " chosen / " + strconv.Itoa(len(autopeering.Selection.GetIncomingNeighbors())) + " accepted / " + strconv.Itoa(len(autopeering.Selection.GetNeighbors())) + " total", + KnownPeer: "Known Peers: " + strconv.Itoa(len(autopeering.Discovery.GetVerifiedPeers())) + " total", + Uptime: uptime, + } } // ServeWs websocket diff --git a/plugins/gossip-on-solidification/plugin.go b/plugins/gossip-on-solidification/plugin.go index bd040b9cae5b56a314cef22ab7c144b0c28d291a..fe112d806aaa681a3e1da2da17350f567022cf7f 100644 --- a/plugins/gossip-on-solidification/plugin.go +++ b/plugins/gossip-on-solidification/plugin.go @@ -1,7 +1,7 @@ package gossip_on_solidification import ( - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/gossip" diff --git a/plugins/gossip/events.go b/plugins/gossip/events.go index 6d3183820d2f8c5986751e13e20896c3cc3f1e8b..4bcb484a1bcdcfc158222e798e5e00fd3ed85223 100644 --- a/plugins/gossip/events.go +++ b/plugins/gossip/events.go @@ -2,10 +2,10 @@ package gossip import ( "github.com/iotaledger/goshimmer/packages/errors" - "github.com/iotaledger/goshimmer/packages/events" "github.com/iotaledger/goshimmer/packages/identity" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/network" + "github.com/iotaledger/hive.go/events" ) var Events = pluginEvents{ diff --git a/plugins/gossip/neighbors.go b/plugins/gossip/neighbors.go index 4e73bf27c129adbb6473662595d110c2973ff975..f4374c517bf1fb7ce7d84160e39a7cb07113977d 100644 --- a/plugins/gossip/neighbors.go +++ b/plugins/gossip/neighbors.go @@ -7,26 +7,27 @@ import ( "sync" "time" + "github.com/iotaledger/autopeering-sim/peer" "github.com/iotaledger/goshimmer/packages/accountability" "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/errors" - "github.com/iotaledger/goshimmer/packages/events" "github.com/iotaledger/goshimmer/packages/identity" "github.com/iotaledger/goshimmer/packages/network" "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/hive.go/events" ) func configureNeighbors(plugin *node.Plugin) { Events.AddNeighbor.Attach(events.NewClosure(func(neighbor *Neighbor) { - plugin.LogSuccess("new neighbor added " + neighbor.GetIdentity().StringIdentifier + "@" + neighbor.GetAddress().String() + ":" + strconv.Itoa(int(neighbor.GetPort()))) + plugin.LogSuccess("new neighbor added " + neighbor.GetIdentity().StringIdentifier + "@" + neighbor.GetAddress().String() + ":" + neighbor.GetPort()) })) Events.UpdateNeighbor.Attach(events.NewClosure(func(neighbor *Neighbor) { - plugin.LogSuccess("existing neighbor updated " + neighbor.GetIdentity().StringIdentifier + "@" + neighbor.GetAddress().String() + ":" + strconv.Itoa(int(neighbor.GetPort()))) + plugin.LogSuccess("existing neighbor updated " + neighbor.GetIdentity().StringIdentifier + "@" + neighbor.GetAddress().String() + ":" + neighbor.GetPort()) })) Events.RemoveNeighbor.Attach(events.NewClosure(func(neighbor *Neighbor) { - plugin.LogSuccess("existing neighbor removed " + neighbor.GetIdentity().StringIdentifier + "@" + neighbor.GetAddress().String() + ":" + strconv.Itoa(int(neighbor.GetPort()))) + plugin.LogSuccess("existing neighbor removed " + neighbor.GetIdentity().StringIdentifier + "@" + neighbor.GetAddress().String() + ":" + neighbor.GetPort()) })) } @@ -98,20 +99,22 @@ type Neighbor struct { identityMutex sync.RWMutex address net.IP addressMutex sync.RWMutex - port uint16 + port string portMutex sync.RWMutex initiatedProtocol *protocol initiatedProtocolMutex sync.RWMutex acceptedProtocol *protocol Events neighborEvents acceptedProtocolMutex sync.RWMutex + Peer *peer.Peer } -func NewNeighbor(identity *identity.Identity, address net.IP, port uint16) *Neighbor { +func NewNeighbor(peer *peer.Peer, address, port string) *Neighbor { return &Neighbor{ - identity: identity, - address: address, + identity: identity.NewPublicIdentity(peer.ToProto().GetPublicKey()), + address: net.ParseIP(address), port: port, + Peer: peer, Events: neighborEvents{ ProtocolConnectionEstablished: events.NewEvent(protocolCaller), }, @@ -146,7 +149,7 @@ func (neighbor *Neighbor) SetAddress(address net.IP) { neighbor.addressMutex.Unlock() } -func (neighbor *Neighbor) GetPort() (result uint16) { +func (neighbor *Neighbor) GetPort() (result string) { neighbor.portMutex.RLock() result = neighbor.port neighbor.portMutex.RUnlock() @@ -154,7 +157,7 @@ func (neighbor *Neighbor) GetPort() (result uint16) { return result } -func (neighbor *Neighbor) SetPort(port uint16) { +func (neighbor *Neighbor) SetPort(port string) { neighbor.portMutex.Lock() neighbor.port = port neighbor.portMutex.Unlock() @@ -204,10 +207,10 @@ func (neighbor *Neighbor) Connect() (*protocol, bool, errors.IdentifiableError) } // otherwise try to dial - conn, err := net.Dial("tcp", neighbor.GetAddress().String()+":"+strconv.Itoa(int(neighbor.GetPort()))) + conn, err := net.Dial("tcp", neighbor.GetAddress().String()+":"+neighbor.GetPort()) if err != nil { return nil, false, ErrConnectionFailed.Derive(err, "error when connecting to neighbor "+ - neighbor.GetIdentity().StringIdentifier+"@"+neighbor.GetAddress().String()+":"+strconv.Itoa(int(neighbor.GetPort()))) + neighbor.GetIdentity().StringIdentifier+"@"+neighbor.GetAddress().String()+":"+neighbor.GetPort()) } neighbor.SetInitiatedProtocol(newProtocol(network.NewManagedConnection(conn))) diff --git a/plugins/gossip/protocol.go b/plugins/gossip/protocol.go index f51d11b718911beeb6bec9a7bae22247d9bc715b..5cda6f99882248aafbb9af719911182a918097db 100644 --- a/plugins/gossip/protocol.go +++ b/plugins/gossip/protocol.go @@ -5,7 +5,7 @@ import ( "sync" "github.com/iotaledger/goshimmer/packages/errors" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/network" ) diff --git a/plugins/gossip/protocol_v1.go b/plugins/gossip/protocol_v1.go index 196bc2c63e8c9e083c4ef6040c37e3163b740c58..ee6681dc86870a3530ff4d77a9c17ed7959e8ae5 100644 --- a/plugins/gossip/protocol_v1.go +++ b/plugins/gossip/protocol_v1.go @@ -1,13 +1,12 @@ package gossip import ( - "bytes" "strconv" "github.com/iotaledger/goshimmer/packages/accountability" "github.com/iotaledger/goshimmer/packages/byteutils" "github.com/iotaledger/goshimmer/packages/errors" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/identity" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/iota.go/consts" @@ -82,60 +81,46 @@ func (state *indentificationStateV1) Receive(data []byte, offset int, length int state.offset += bytesRead if state.offset == MARSHALED_IDENTITY_TOTAL_SIZE { - if receivedIdentity, err := unmarshalIdentity(state.buffer); err != nil { + receivedIdentity, err := identity.FromSignedData(state.buffer) + if err != nil { return bytesRead, ErrInvalidAuthenticationMessage.Derive(err, "invalid authentication message") - } else { - protocol := state.protocol + } + protocol := state.protocol - if neighbor, exists := neighbors.Load(receivedIdentity.StringIdentifier); exists { - protocol.Neighbor = neighbor - } else { - protocol.Neighbor = nil - } + if neighbor, exists := GetNeighbor(receivedIdentity.StringIdentifier); exists { + protocol.Neighbor = neighbor + } else { + protocol.Neighbor = nil + } - protocol.Events.ReceiveIdentification.Trigger(receivedIdentity) + protocol.Events.ReceiveIdentification.Trigger(receivedIdentity) - protocol.ReceivingState = newacceptanceStateV1(protocol) - state.offset = 0 - } + // switch to new state + protocol.ReceivingState = newacceptanceStateV1(protocol) + state.offset = 0 } return bytesRead, nil } func (state *indentificationStateV1) Send(param interface{}) errors.IdentifiableError { - if id, ok := param.(*identity.Identity); ok { - if signature, err := id.Sign(id.Identifier); err == nil { - protocol := state.protocol - - if _, err := protocol.Conn.Write(id.Identifier); err != nil { - return ErrSendFailed.Derive(err, "failed to send identifier") - } - if _, err := protocol.Conn.Write(signature); err != nil { - return ErrSendFailed.Derive(err, "failed to send signature") - } + id, ok := param.(*identity.Identity) + if !ok { + return ErrInvalidSendParam.Derive("parameter is not a valid identity") + } - protocol.SendState = newacceptanceStateV1(protocol) + msg := id.Identifier.Bytes() + data := id.AddSignature(msg) - return nil - } + protocol := state.protocol + if _, err := protocol.Conn.Write(data); err != nil { + return ErrSendFailed.Derive(err, "failed to send identification") } - return ErrInvalidSendParam.Derive("passed in parameter is not a valid identity") -} + // switch to new state + protocol.SendState = newacceptanceStateV1(protocol) -func unmarshalIdentity(data []byte) (*identity.Identity, error) { - identifier := data[MARSHALED_IDENTITY_START:MARSHALED_IDENTITY_END] - - if restoredIdentity, err := identity.FromSignedData(identifier, data[MARSHALED_IDENTITY_SIGNATURE_START:MARSHALED_IDENTITY_SIGNATURE_END]); err != nil { - return nil, err - } else { - if bytes.Equal(identifier, restoredIdentity.Identifier) { - return restoredIdentity, nil - } else { - return nil, errors.New("signature does not match claimed identity") - } - } + return nil } // endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -383,14 +368,14 @@ const ( DISPATCH_TRANSACTION = byte(1) DISPATCH_REQUEST = byte(2) - MARSHALED_IDENTITY_START = 0 - MARSHALED_IDENTITY_SIGNATURE_START = MARSHALED_IDENTITY_END + MARSHALED_IDENTITY_IDENTIFIER_START = 0 + MARSHALED_IDENTITY_SIGNATURE_START = MARSHALED_IDENTITY_IDENTIFIER_END - MARSHALED_IDENTITY_SIZE = 20 - MARSHALED_IDENTITY_SIGNATURE_SIZE = 65 + MARSHALED_IDENTITY_IDENTIFIER_SIZE = identity.IDENTIFIER_BYTE_LENGTH + MARSHALED_IDENTITY_SIGNATURE_SIZE = identity.SIGNATURE_BYTE_LENGTH - MARSHALED_IDENTITY_END = MARSHALED_IDENTITY_START + MARSHALED_IDENTITY_SIZE - MARSHALED_IDENTITY_SIGNATURE_END = MARSHALED_IDENTITY_SIGNATURE_START + MARSHALED_IDENTITY_SIGNATURE_SIZE + MARSHALED_IDENTITY_IDENTIFIER_END = MARSHALED_IDENTITY_IDENTIFIER_START + MARSHALED_IDENTITY_IDENTIFIER_SIZE + MARSHALED_IDENTITY_SIGNATURE_END = MARSHALED_IDENTITY_SIGNATURE_START + MARSHALED_IDENTITY_SIGNATURE_SIZE MARSHALED_IDENTITY_TOTAL_SIZE = MARSHALED_IDENTITY_SIGNATURE_END ) diff --git a/plugins/gossip/send_queue.go b/plugins/gossip/send_queue.go index 7edc3dd2e62de70649a6d363baf309991b682ec1..02ba9415644dca046b8e9580a814ee54f9055502 100644 --- a/plugins/gossip/send_queue.go +++ b/plugins/gossip/send_queue.go @@ -4,7 +4,7 @@ import ( "sync" "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/node" ) diff --git a/plugins/gossip/server.go b/plugins/gossip/server.go index 7dc7cd67c7212b501546664bafb3b588ba4bb116..cee62e7d5e0fa085a9be2996b4a1d6e5d2b5b2fe 100644 --- a/plugins/gossip/server.go +++ b/plugins/gossip/server.go @@ -6,7 +6,7 @@ import ( "github.com/iotaledger/goshimmer/packages/accountability" "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/errors" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/identity" "github.com/iotaledger/goshimmer/packages/network" "github.com/iotaledger/goshimmer/packages/network/tcp" diff --git a/plugins/metrics/events.go b/plugins/metrics/events.go index 18189674612c6c09e396d3d539f79621a9a95645..03a51d819cbb0e6e09bbeea5798779bbc9e04cbc 100644 --- a/plugins/metrics/events.go +++ b/plugins/metrics/events.go @@ -1,7 +1,7 @@ package metrics import ( - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" ) var Events = pluginEvents{ diff --git a/plugins/metrics/plugin.go b/plugins/metrics/plugin.go index 290b548fee32bb014b3bcd80e8b03a7f03f8ef7c..3a2b3b23be9ded6f85b6acbfdf7ff1952262467d 100644 --- a/plugins/metrics/plugin.go +++ b/plugins/metrics/plugin.go @@ -4,7 +4,7 @@ import ( "time" "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/timeutil" diff --git a/plugins/statusscreen-tps/plugin.go b/plugins/statusscreen-tps/plugin.go index e91121a15859989755e4e35667e166d3acc498ef..8981ad47d42a8fe0bcc68c37b7ad00970b522744 100644 --- a/plugins/statusscreen-tps/plugin.go +++ b/plugins/statusscreen-tps/plugin.go @@ -6,7 +6,7 @@ import ( "time" "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/node" diff --git a/plugins/statusscreen/statusscreen.go b/plugins/statusscreen/statusscreen.go index 7f13dc4ad4c0e3c9e216465f19a87aa786a9b91d..f76e097e13b79aa848c08d12799dd5a29f3ec83f 100644 --- a/plugins/statusscreen/statusscreen.go +++ b/plugins/statusscreen/statusscreen.go @@ -7,8 +7,8 @@ import ( "github.com/gdamore/tcell" "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/events" "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/hive.go/events" "github.com/rivo/tview" "golang.org/x/crypto/ssh/terminal" ) diff --git a/plugins/statusscreen/ui_header_bar.go b/plugins/statusscreen/ui_header_bar.go index db3dfc6470d273b34be3db548b87b0f422c9444a..e1a1d17b88739c64aa8ea3bcfff7227666aec6c4 100644 --- a/plugins/statusscreen/ui_header_bar.go +++ b/plugins/statusscreen/ui_header_bar.go @@ -4,14 +4,13 @@ import ( "fmt" "math" "strconv" + + //"strconv" "time" "github.com/gdamore/tcell" "github.com/iotaledger/goshimmer/packages/accountability" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/neighborhood" + "github.com/iotaledger/goshimmer/plugins/autopeering" "github.com/rivo/tview" ) @@ -78,11 +77,24 @@ func (headerBar *UIHeaderBar) Update() { fmt.Fprintln(headerBar.InfoContainer) } + outgoing := "0" + incoming := "0" + neighbors := "0" + total := "0" + if autopeering.Selection != nil { + outgoing = strconv.Itoa(len(autopeering.Selection.GetOutgoingNeighbors())) + incoming = strconv.Itoa(len(autopeering.Selection.GetIncomingNeighbors())) + neighbors = strconv.Itoa(len(autopeering.Selection.GetNeighbors())) + } + if autopeering.Discovery != nil { + total = strconv.Itoa(len(autopeering.Discovery.GetVerifiedPeers())) + } + fmt.Fprintf(headerBar.InfoContainer, "[::b]Node ID: [::d]%40v ", accountability.OwnId().StringIdentifier) fmt.Fprintln(headerBar.InfoContainer) - fmt.Fprintf(headerBar.InfoContainer, "[::b]Neighbors: [::d]%40v ", strconv.Itoa(chosenneighbors.INSTANCE.Peers.Len())+" chosen / "+strconv.Itoa(acceptedneighbors.INSTANCE.Peers.Len())+" accepted / "+strconv.Itoa(chosenneighbors.INSTANCE.Peers.Len()+acceptedneighbors.INSTANCE.Peers.Len())+" total") + fmt.Fprintf(headerBar.InfoContainer, "[::b]Neighbors: [::d]%40v ", outgoing+" chosen / "+incoming+" accepted / "+neighbors+" total") fmt.Fprintln(headerBar.InfoContainer) - fmt.Fprintf(headerBar.InfoContainer, "[::b]Known Peers: [::d]%40v ", strconv.Itoa(knownpeers.INSTANCE.Peers.Len())+" total / "+strconv.Itoa(neighborhood.INSTANCE.Peers.Len())+" neighborhood") + fmt.Fprintf(headerBar.InfoContainer, "[::b]Known Peers: [::d]%40v ", total+" total") fmt.Fprintln(headerBar.InfoContainer) fmt.Fprintf(headerBar.InfoContainer, "[::b]Uptime: [::d]") diff --git a/plugins/tangle/events.go b/plugins/tangle/events.go index e29ecd20c31dc13dbf3638cf5e880ae328411d37..106e43d40acaddd11c4d6f233be49402de2a6ffe 100644 --- a/plugins/tangle/events.go +++ b/plugins/tangle/events.go @@ -1,7 +1,7 @@ package tangle import ( - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/model/value_transaction" ) diff --git a/plugins/tangle/solidifier.go b/plugins/tangle/solidifier.go index e0408a957a40a2b346f4796a56ed7a07a1c55924..0efba3f754279dc6f7de7874754a4c68c157df89 100644 --- a/plugins/tangle/solidifier.go +++ b/plugins/tangle/solidifier.go @@ -5,7 +5,7 @@ import ( "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/errors" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/model/approvers" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/model/transactionmetadata" diff --git a/plugins/tangle/solidifier_test.go b/plugins/tangle/solidifier_test.go index 9db5e7c89e5b91659264d7907ac02acdd6cdc435..cfb74d5feeaa239b6059d443a963757bde154194 100644 --- a/plugins/tangle/solidifier_test.go +++ b/plugins/tangle/solidifier_test.go @@ -4,7 +4,7 @@ import ( "sync" "testing" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/gossip" diff --git a/plugins/tipselection/plugin.go b/plugins/tipselection/plugin.go index 745c1dad4c8e2ecb8178fd2fc84c405a22357989..b74ab6458a4daedfc41fde36ff9a05a755f754ba 100644 --- a/plugins/tipselection/plugin.go +++ b/plugins/tipselection/plugin.go @@ -1,7 +1,7 @@ package tipselection import ( - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/tangle" diff --git a/plugins/ui/nodeInfo.go b/plugins/ui/nodeInfo.go index f643e9f5dee819534c6b6af136fd3dff68a7bcb1..a97ab5a19b33a98ff1af3e1bf4e1ee49a6d19035 100644 --- a/plugins/ui/nodeInfo.go +++ b/plugins/ui/nodeInfo.go @@ -5,10 +5,7 @@ import ( "time" "github.com/iotaledger/goshimmer/packages/accountability" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/neighborhood" + "github.com/iotaledger/goshimmer/plugins/autopeering" ) var start = time.Now() @@ -42,10 +39,10 @@ func gatherInfo() nodeInfo { // update neighbors chosenNeighbors := []string{} acceptedNeighbors := []string{} - for _, peer := range chosenneighbors.INSTANCE.Peers.GetMap() { + for _, peer := range autopeering.Selection.GetOutgoingNeighbors() { chosenNeighbors = append(chosenNeighbors, peer.String()) } - for _, peer := range acceptedneighbors.INSTANCE.Peers.GetMap() { + for _, peer := range autopeering.Selection.GetIncomingNeighbors() { acceptedNeighbors = append(acceptedNeighbors, peer.String()) } @@ -55,8 +52,8 @@ func gatherInfo() nodeInfo { ID: accountability.OwnId().StringIdentifier, ChosenNeighbors: chosenNeighbors, AcceptedNeighbors: acceptedNeighbors, - KnownPeersSize: knownpeers.INSTANCE.Peers.Len(), - NeighborhoodSize: neighborhood.INSTANCE.Peers.Len(), + KnownPeersSize: len(autopeering.Discovery.GetVerifiedPeers()), //knownpeers.INSTANCE.Peers.Len(), + NeighborhoodSize: len(autopeering.Selection.GetNeighbors()), //neighborhood.INSTANCE.Peers.Len(), Uptime: uint64(duration), ReceivedTps: receivedTps, SolidTps: solidTps, diff --git a/plugins/ui/ui.go b/plugins/ui/ui.go index 17d0c3d03e2132beb434c19fbdf2682b87dafedb..383d3606877f5e27bb6e91e49f9e2891a5114a57 100644 --- a/plugins/ui/ui.go +++ b/plugins/ui/ui.go @@ -7,7 +7,7 @@ import ( "time" "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/node" diff --git a/plugins/validator/plugin.go b/plugins/validator/plugin.go index f5785b9869d3c26d0d097c4a6ede8f5142858622..410de706f7b23f15d3e2127a1e489d7b94104930 100644 --- a/plugins/validator/plugin.go +++ b/plugins/validator/plugin.go @@ -1,7 +1,7 @@ package validator import ( - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/model/bundle" "github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/node" diff --git a/plugins/webapi/plugin.go b/plugins/webapi/plugin.go index f9de1de526423c6871d8ad02a3be310f485ecee6..bc43cb7877e810cfbb340f920c1be4e946f0ddfe 100644 --- a/plugins/webapi/plugin.go +++ b/plugins/webapi/plugin.go @@ -5,7 +5,7 @@ import ( "time" "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/node" "github.com/labstack/echo" ) diff --git a/plugins/zeromq/plugin.go b/plugins/zeromq/plugin.go index a94a0ce9311853756f8be07b07ac7b221eec9215..77149fe1656bea8a074db58910798f1e7e470a36 100644 --- a/plugins/zeromq/plugin.go +++ b/plugins/zeromq/plugin.go @@ -6,7 +6,7 @@ import ( "time" "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/events" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/tangle"