forked from cwtch.im/cwtch
1
0
Fork 0

Split Peer and Server Connection Launching

This commit is contained in:
Sarah Jamie Lewis 2020-10-29 14:22:33 -07:00
parent 21c41f24ee
commit 80c6bcead7
2 changed files with 15 additions and 7 deletions

View File

@ -93,6 +93,7 @@ type CwtchPeer interface {
Listen()
StartPeersConnections()
StartServerConnections()
Shutdown()
}
@ -480,13 +481,20 @@ func (cp *cwtchPeer) Listen() {
cp.eventBus.Publish(event.NewEvent(event.ProtocolEngineStartListen, map[event.Field]string{event.Onion: cp.Profile.Onion}))
}
// StartGroupConnections attempts to connect to all group servers (thus initiating reconnect attempts in the conectionsmanager)
// StartPeersConnections attempts to connect to peer connections
func (cp *cwtchPeer) StartPeersConnections() {
for _, contact := range cp.GetContacts() {
if cp.GetContact(contact).IsServer() == false {
cp.PeerWithOnion(contact)
}
}
}
// StartServerConnections attempts to connect to all server connections
func (cp *cwtchPeer) StartServerConnections() {
for _, contact := range cp.GetContacts() {
if cp.GetContact(contact).IsServer() {
cp.JoinServer(contact)
} else {
cp.PeerWithOnion(contact)
}
}
}

View File

@ -118,14 +118,14 @@ func TestCwtchPeerIntegration(t *testing.T) {
log.ExcludeFromPattern("event/eventmanager")
log.ExcludeFromPattern("pipeBridge")
log.ExcludeFromPattern("tapir")
os.Mkdir("tordir",0700)
os.Mkdir("tordir", 0700)
dataDir := path.Join("tordir", "tor")
os.MkdirAll(dataDir, 0700)
// we don't need real randomness for the port, just to avoid a possible conflict...
mrand.Seed(int64(time.Now().Nanosecond()))
socksPort := mrand.Intn(1000)+9051
controlPort := mrand.Intn(1000)+9052
socksPort := mrand.Intn(1000) + 9051
controlPort := mrand.Intn(1000) + 9052
// generate a random password
key := make([]byte, 64)
@ -139,7 +139,7 @@ func TestCwtchPeerIntegration(t *testing.T) {
if err != nil {
t.Fatalf("Could not start Tor: %v", err)
}
pid,err := acn.GetPID()
pid, err := acn.GetPID()
t.Logf("Tor pid: %v", pid)
// ***** Cwtch Server management *****