summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitaly Minko <vitaly.minko@gmail.com>2019-02-02 14:27:02 +0300
committerVitaly Minko <vitaly.minko@gmail.com>2019-02-02 14:27:02 +0300
commit4c7673d589d0bd199f36d9579b180de6b9fc4438 (patch)
tree7d22dff2db83dcad25e7deae68a3aa5fe1b14dfa
parentee5cada1b69920724dcd4ad4bb50dacb2de0d6d6 (diff)
Implemented simultaneous support of multiple address providers.
-rw-r--r--dscuss.go46
-rw-r--r--p2p/connection_provider.go16
-rw-r--r--testbed/data/1/config.json1
-rw-r--r--testbed/data/2/config.json1
-rw-r--r--testbed/data/3/config.json1
-rw-r--r--testbed/data/dht1/adam/entity.dbbin0 -> 57344 bytes
-rw-r--r--testbed/data/dht1/adam/privkey.pem5
-rw-r--r--testbed/data/dht1/adam/profile.dbbin0 -> 36864 bytes
-rw-r--r--testbed/data/dht1/addresses.txt2
-rw-r--r--testbed/data/dht1/config.json9
-rw-r--r--testbed/data/dht2/addresses.txt2
-rw-r--r--testbed/data/dht2/config.json10
-rw-r--r--testbed/data/dht2/eve/entity.dbbin0 -> 57344 bytes
-rw-r--r--testbed/data/dht2/eve/privkey.pem5
-rw-r--r--testbed/data/dht2/eve/profile.dbbin0 -> 36864 bytes
-rw-r--r--testbed/data/dht3/addresses.txt2
-rw-r--r--testbed/data/dht3/cain/entity.dbbin0 -> 57344 bytes
-rw-r--r--testbed/data/dht3/cain/privkey.pem5
-rw-r--r--testbed/data/dht3/cain/profile.dbbin0 -> 36864 bytes
-rw-r--r--testbed/data/dht3/config.json10
-rw-r--r--testbed/data/multi2/addresses.txt1
-rw-r--r--testbed/data/multi2/config.json11
-rw-r--r--testbed/data/multi2/eve/entity.dbbin0 -> 57344 bytes
-rw-r--r--testbed/data/multi2/eve/privkey.pem5
-rw-r--r--testbed/data/multi2/eve/profile.dbbin0 -> 36864 bytes
-rw-r--r--testbed/data/none3/addresses.txt0
-rw-r--r--testbed/data/none3/cain/entity.dbbin0 -> 57344 bytes
-rw-r--r--testbed/data/none3/cain/privkey.pem5
-rw-r--r--testbed/data/none3/cain/profile.dbbin0 -> 36864 bytes
-rw-r--r--testbed/data/none3/config.json9
-rwxr-xr-xtestbed/multiple_address_providers.exp69
-rw-r--r--testbed/testbed.exp2
32 files changed, 188 insertions, 29 deletions
diff --git a/dscuss.go b/dscuss.go
index d51fc16..5e3ad13 100644
--- a/dscuss.go
+++ b/dscuss.go
@@ -29,6 +29,7 @@ import (
"path/filepath"
"runtime"
"strconv"
+ "strings"
"vminko.org/dscuss/entity"
"vminko.org/dscuss/errors"
"vminko.org/dscuss/log"
@@ -163,28 +164,35 @@ func Login(nickname string) (*LoginHandle, error) {
}
log.Debugf("Trying to login as peer %s", ownr.User.ID().String())
- var ap p2p.AddressProvider
- switch cfg.Network.AddressProvider {
- case "addrlist":
- addrFilePath := filepath.Join(
- dir,
- AddressListFileName,
- )
- ap = p2p.NewAddressList(addrFilePath)
- case "dht":
- ap = p2p.NewDHTCrawler(
- cfg.Network.Address,
- cfg.Network.DHTPort,
- cfg.Network.DHTBootstrap,
- cfg.Network.Port,
- ownr.Profile.GetSubscriptions(),
- )
- default:
- log.Fatal("Unknown address provider is configured: " + cfg.Network.AddressProvider)
+ var aps []p2p.AddressProvider
+ for _, name := range strings.Split(cfg.Network.AddressProvider, ",") {
+ switch name {
+ case "addrlist":
+ addrFilePath := filepath.Join(
+ dir,
+ AddressListFileName,
+ )
+ ap := p2p.NewAddressList(addrFilePath)
+ aps = append(aps, ap)
+ case "dht":
+ ap := p2p.NewDHTCrawler(
+ cfg.Network.Address,
+ cfg.Network.DHTPort,
+ cfg.Network.DHTBootstrap,
+ cfg.Network.Port,
+ ownr.Profile.GetSubscriptions(),
+ )
+ aps = append(aps, ap)
+ default:
+ log.Error("Unknown address provider is configured: " + name)
+ }
+ }
+ if len(aps) == 0 {
+ log.Fatal("Could not found any valid address provider in " + cfg.Network.AddressProvider)
}
hp := net.JoinHostPort(cfg.Network.Address, strconv.Itoa(cfg.Network.Port))
- cp := p2p.NewConnectionProvider(ap, hp, cfg.Network.MaxInConnCount, cfg.Network.MaxOutConnCount)
+ cp := p2p.NewConnectionProvider(aps, hp, cfg.Network.MaxInConnCount, cfg.Network.MaxOutConnCount)
pp := p2p.NewPeerPool(cp, ownr)
pp.Start()
diff --git a/p2p/connection_provider.go b/p2p/connection_provider.go
index 55d59cf..c2de617 100644
--- a/p2p/connection_provider.go
+++ b/p2p/connection_provider.go
@@ -85,7 +85,7 @@ type ConnectionProvider struct {
wg sync.WaitGroup
stopChan chan struct{}
outChan chan *connection.Connection
- ap AddressProvider
+ aps []AddressProvider
outAddrs *addressMap
maxInConnCount uint32
maxOutConnCount uint32
@@ -94,13 +94,13 @@ type ConnectionProvider struct {
}
func NewConnectionProvider(
- ap AddressProvider,
+ aps []AddressProvider,
hostport string,
maxInConnCount uint32,
maxOutConnCount uint32,
) *ConnectionProvider {
cp := &ConnectionProvider{
- ap: ap,
+ aps: aps,
maxInConnCount: maxInConnCount,
maxOutConnCount: maxOutConnCount,
hostport: hostport,
@@ -120,16 +120,20 @@ func setDefaultBootstrapAddresses(outAddrs *addressMap) {
func (cp *ConnectionProvider) Start() {
log.Debugf("Starting ConnectionProvider")
- cp.ap.RegisterAddressConsumer(cp)
cp.wg.Add(2)
go cp.listenIncomingConnections()
go cp.establishOutgoingConnections()
- cp.ap.Start()
+ for _, ap := range cp.aps {
+ ap.RegisterAddressConsumer(cp)
+ ap.Start()
+ }
}
func (cp *ConnectionProvider) Stop() {
log.Debugf("Stopping ConnectionProvider")
- cp.ap.Stop()
+ for _, ap := range cp.aps {
+ ap.Stop()
+ }
close(cp.stopChan)
if cp.listener != nil {
cp.listener.Close()
diff --git a/testbed/data/1/config.json b/testbed/data/1/config.json
index 40b9f50..afa60c9 100644
--- a/testbed/data/1/config.json
+++ b/testbed/data/1/config.json
@@ -1,7 +1,6 @@
{
"Network": {
"Port": 8004,
- "DHTPort": 9115,
"AddressProvider": "addrlist",
"MaxInConnCount": 10,
"MaxOutConnCount": 10
diff --git a/testbed/data/2/config.json b/testbed/data/2/config.json
index d051817..fb1835f 100644
--- a/testbed/data/2/config.json
+++ b/testbed/data/2/config.json
@@ -1,7 +1,6 @@
{
"Network": {
"Port": 8005,
- "DHTPort": 9116,
"AddressProvider": "addrlist",
"MaxInConnCount": 10,
"MaxOutConnCount": 10
diff --git a/testbed/data/3/config.json b/testbed/data/3/config.json
index 79378ff..43c08b1 100644
--- a/testbed/data/3/config.json
+++ b/testbed/data/3/config.json
@@ -1,7 +1,6 @@
{
"Network": {
"Port": 8006,
- "DHTPort": 9117,
"AddressProvider": "addrlist",
"MaxInConnCount": 10,
"MaxOutConnCount": 10
diff --git a/testbed/data/dht1/adam/entity.db b/testbed/data/dht1/adam/entity.db
new file mode 100644
index 0000000..55cbc9e
--- /dev/null
+++ b/testbed/data/dht1/adam/entity.db
Binary files differ
diff --git a/testbed/data/dht1/adam/privkey.pem b/testbed/data/dht1/adam/privkey.pem
new file mode 100644
index 0000000..243961e
--- /dev/null
+++ b/testbed/data/dht1/adam/privkey.pem
@@ -0,0 +1,5 @@
+-----BEGIN EC PRIVATE KEY-----
+MGgCAQEEHNGqSKerqJfxyrSMJq8zMN0sap95J6gtx7mIaqagBwYFK4EEACGhPAM6
+AARJ6PP+nsXIiLWCY2B89IwfrhJI/GyOD2oBRgH9HsuX0EUg3qdisOTVPWAtrAQ/
+ouYa/D4SP5FMpA==
+-----END EC PRIVATE KEY-----
diff --git a/testbed/data/dht1/adam/profile.db b/testbed/data/dht1/adam/profile.db
new file mode 100644
index 0000000..fabbc83
--- /dev/null
+++ b/testbed/data/dht1/adam/profile.db
Binary files differ
diff --git a/testbed/data/dht1/addresses.txt b/testbed/data/dht1/addresses.txt
new file mode 100644
index 0000000..bc7f0bb
--- /dev/null
+++ b/testbed/data/dht1/addresses.txt
@@ -0,0 +1,2 @@
+127.0.0.1:8005
+127.0.0.1:8006
diff --git a/testbed/data/dht1/config.json b/testbed/data/dht1/config.json
new file mode 100644
index 0000000..78c21ea
--- /dev/null
+++ b/testbed/data/dht1/config.json
@@ -0,0 +1,9 @@
+{
+ "Network": {
+ "Port": 8004,
+ "DHTPort": 6881,
+ "AddressProvider": "dht",
+ "MaxInConnCount": 10,
+ "MaxOutConnCount": 10
+ }
+}
diff --git a/testbed/data/dht2/addresses.txt b/testbed/data/dht2/addresses.txt
new file mode 100644
index 0000000..c714c2d
--- /dev/null
+++ b/testbed/data/dht2/addresses.txt
@@ -0,0 +1,2 @@
+127.0.0.1:8004
+127.0.0.1:8006
diff --git a/testbed/data/dht2/config.json b/testbed/data/dht2/config.json
new file mode 100644
index 0000000..031bbb0
--- /dev/null
+++ b/testbed/data/dht2/config.json
@@ -0,0 +1,10 @@
+{
+ "Network": {
+ "Port": 8005,
+ "DHTPort": 6882,
+ "DHTBootstrap": "localhost:6881",
+ "AddressProvider": "dht",
+ "MaxInConnCount": 10,
+ "MaxOutConnCount": 10
+ }
+}
diff --git a/testbed/data/dht2/eve/entity.db b/testbed/data/dht2/eve/entity.db
new file mode 100644
index 0000000..155d52a
--- /dev/null
+++ b/testbed/data/dht2/eve/entity.db
Binary files differ
diff --git a/testbed/data/dht2/eve/privkey.pem b/testbed/data/dht2/eve/privkey.pem
new file mode 100644
index 0000000..b596eae
--- /dev/null
+++ b/testbed/data/dht2/eve/privkey.pem
@@ -0,0 +1,5 @@
+-----BEGIN EC PRIVATE KEY-----
+MGgCAQEEHPi7SGbk25+3XV4Wl4D1SexIG3LKI15hhGmSKwSgBwYFK4EEACGhPAM6
+AATIuShe8mz2ZzSRzM4NMJXurDxIYcZS7qZvLfI5dWNG9vB0iGKyXMpohvR00L8h
+obp9ZiTArvfG8A==
+-----END EC PRIVATE KEY-----
diff --git a/testbed/data/dht2/eve/profile.db b/testbed/data/dht2/eve/profile.db
new file mode 100644
index 0000000..1fe32de
--- /dev/null
+++ b/testbed/data/dht2/eve/profile.db
Binary files differ
diff --git a/testbed/data/dht3/addresses.txt b/testbed/data/dht3/addresses.txt
new file mode 100644
index 0000000..d9d8466
--- /dev/null
+++ b/testbed/data/dht3/addresses.txt
@@ -0,0 +1,2 @@
+127.0.0.1:8004
+127.0.0.1:8005
diff --git a/testbed/data/dht3/cain/entity.db b/testbed/data/dht3/cain/entity.db
new file mode 100644
index 0000000..9d59dfb
--- /dev/null
+++ b/testbed/data/dht3/cain/entity.db
Binary files differ
diff --git a/testbed/data/dht3/cain/privkey.pem b/testbed/data/dht3/cain/privkey.pem
new file mode 100644
index 0000000..ab31221
--- /dev/null
+++ b/testbed/data/dht3/cain/privkey.pem
@@ -0,0 +1,5 @@
+-----BEGIN EC PRIVATE KEY-----
+MGgCAQEEHHGNKvCn8F+h3NIIfBUK7Wp8l3nl3Nohy3jRjxagBwYFK4EEACGhPAM6
+AASYNsEoyHS83KCiwdkcEOk1eFtCQdJs4K7c0euqJgw5eflhXc64t7ycjY88pnuk
+urC8HKd15r2VRw==
+-----END EC PRIVATE KEY-----
diff --git a/testbed/data/dht3/cain/profile.db b/testbed/data/dht3/cain/profile.db
new file mode 100644
index 0000000..5c1c4a5
--- /dev/null
+++ b/testbed/data/dht3/cain/profile.db
Binary files differ
diff --git a/testbed/data/dht3/config.json b/testbed/data/dht3/config.json
new file mode 100644
index 0000000..aba307a
--- /dev/null
+++ b/testbed/data/dht3/config.json
@@ -0,0 +1,10 @@
+{
+ "Network": {
+ "Port": 8006,
+ "DHTPort": 6883,
+ "DHTBootstrap": "localhost:6881",
+ "AddressProvider": "dht",
+ "MaxInConnCount": 10,
+ "MaxOutConnCount": 10
+ }
+}
diff --git a/testbed/data/multi2/addresses.txt b/testbed/data/multi2/addresses.txt
new file mode 100644
index 0000000..822f48a
--- /dev/null
+++ b/testbed/data/multi2/addresses.txt
@@ -0,0 +1 @@
+127.0.0.1:8006
diff --git a/testbed/data/multi2/config.json b/testbed/data/multi2/config.json
new file mode 100644
index 0000000..6dd00d3
--- /dev/null
+++ b/testbed/data/multi2/config.json
@@ -0,0 +1,11 @@
+{
+ "Network": {
+ "Port": 8005,
+ "DHTPort": 9116,
+ "AddressProvider": "addrlist,dht",
+ "DHTPort": 6882,
+ "DHTBootstrap": "localhost:6881",
+ "MaxInConnCount": 10,
+ "MaxOutConnCount": 10
+ }
+}
diff --git a/testbed/data/multi2/eve/entity.db b/testbed/data/multi2/eve/entity.db
new file mode 100644
index 0000000..155d52a
--- /dev/null
+++ b/testbed/data/multi2/eve/entity.db
Binary files differ
diff --git a/testbed/data/multi2/eve/privkey.pem b/testbed/data/multi2/eve/privkey.pem
new file mode 100644
index 0000000..b596eae
--- /dev/null
+++ b/testbed/data/multi2/eve/privkey.pem
@@ -0,0 +1,5 @@
+-----BEGIN EC PRIVATE KEY-----
+MGgCAQEEHPi7SGbk25+3XV4Wl4D1SexIG3LKI15hhGmSKwSgBwYFK4EEACGhPAM6
+AATIuShe8mz2ZzSRzM4NMJXurDxIYcZS7qZvLfI5dWNG9vB0iGKyXMpohvR00L8h
+obp9ZiTArvfG8A==
+-----END EC PRIVATE KEY-----
diff --git a/testbed/data/multi2/eve/profile.db b/testbed/data/multi2/eve/profile.db
new file mode 100644
index 0000000..1fe32de
--- /dev/null
+++ b/testbed/data/multi2/eve/profile.db
Binary files differ
diff --git a/testbed/data/none3/addresses.txt b/testbed/data/none3/addresses.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/testbed/data/none3/addresses.txt
diff --git a/testbed/data/none3/cain/entity.db b/testbed/data/none3/cain/entity.db
new file mode 100644
index 0000000..9d59dfb
--- /dev/null
+++ b/testbed/data/none3/cain/entity.db
Binary files differ
diff --git a/testbed/data/none3/cain/privkey.pem b/testbed/data/none3/cain/privkey.pem
new file mode 100644
index 0000000..ab31221
--- /dev/null
+++ b/testbed/data/none3/cain/privkey.pem
@@ -0,0 +1,5 @@
+-----BEGIN EC PRIVATE KEY-----
+MGgCAQEEHHGNKvCn8F+h3NIIfBUK7Wp8l3nl3Nohy3jRjxagBwYFK4EEACGhPAM6
+AASYNsEoyHS83KCiwdkcEOk1eFtCQdJs4K7c0euqJgw5eflhXc64t7ycjY88pnuk
+urC8HKd15r2VRw==
+-----END EC PRIVATE KEY-----
diff --git a/testbed/data/none3/cain/profile.db b/testbed/data/none3/cain/profile.db
new file mode 100644
index 0000000..5c1c4a5
--- /dev/null
+++ b/testbed/data/none3/cain/profile.db
Binary files differ
diff --git a/testbed/data/none3/config.json b/testbed/data/none3/config.json
new file mode 100644
index 0000000..79378ff
--- /dev/null
+++ b/testbed/data/none3/config.json
@@ -0,0 +1,9 @@
+{
+ "Network": {
+ "Port": 8006,
+ "DHTPort": 9117,
+ "AddressProvider": "addrlist",
+ "MaxInConnCount": 10,
+ "MaxOutConnCount": 10
+ }
+}
diff --git a/testbed/multiple_address_providers.exp b/testbed/multiple_address_providers.exp
new file mode 100755
index 0000000..a3cb3ff
--- /dev/null
+++ b/testbed/multiple_address_providers.exp
@@ -0,0 +1,69 @@
+#!/usr/bin/expect -f
+#
+# Test assertion: peers A can use multiple address providers at the same time.
+#
+# This file is part of Dscuss.
+# Copyright (C) 2019 Vitaly Minko
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>.
+
+source testbed.exp
+
+say "Starting Adam's peer"
+spawn ../main -config "$tmp_dir/dht1"
+set adam_id $spawn_id
+expect "Welcome to Dscuss.\r\n"
+send "login adam\r"
+send "whoami\r"
+expect -re "adam (.*)\r\n"
+
+say "Starting Eve's peer"
+spawn ../main -config "$tmp_dir/multi2"
+set eve_id $spawn_id
+expect "Welcome to Dscuss.\r\n"
+send "login eve\r"
+send "whoami\r"
+expect -re "eve (.*)\r\n"
+
+say "Starting Cain's peer"
+spawn ../main -config "$tmp_dir/none3"
+set cain_id $spawn_id
+expect "Welcome to Dscuss.\r\n"
+send "login cain\r"
+send "whoami\r"
+expect -re "cain (.*)\r\n"
+
+say "Giving peers some time to perform handshaking"
+sleep 20
+
+say "Checking whether Eve has discovered Adam and Cain"
+set spawn_id $eve_id
+send "lspeers\r"
+expect "There are 2 connected peers:\r\n"
+expect -re "adam-.*? is Idle\r\n"
+expect -re "cain-.*? is Idle\r\n"
+
+say "Stopping all peers"
+set spawn_id $adam_id
+send "exit\r"
+expect eof
+wait
+set spawn_id $eve_id
+send "exit\r"
+expect eof
+wait
+set spawn_id $cain_id
+send "exit\r"
+expect eof
+wait
+pass
diff --git a/testbed/testbed.exp b/testbed/testbed.exp
index 06e3062..bedb2da 100644
--- a/testbed/testbed.exp
+++ b/testbed/testbed.exp
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
-set timeout 5
+set timeout 10
set data_dir "data"
set tmp_dir "/tmp/dscuss.testdata"