custom handlers for arbitrary channel types in cwtch peer-peer connections #149

Merged
dan merged 1 commits from handlers into master 2018-10-29 19:32:02 +00:00
4 changed files with 7 additions and 5 deletions

View File

@ -3,10 +3,10 @@ package connections
import ( import (
"cwtch.im/cwtch/model" "cwtch.im/cwtch/model"
"cwtch.im/cwtch/protocol" "cwtch.im/cwtch/protocol"
"git.openprivacy.ca/openprivacy/libricochet-go/application"
"sync" "sync"
"time" "time"
"git.openprivacy.ca/openprivacy/libricochet-go/application" )
)
// Manager encapsulates all the logic necessary to manage outgoing peer and server connections. // Manager encapsulates all the logic necessary to manage outgoing peer and server connections.
type Manager struct { type Manager struct {

View File

@ -5,12 +5,12 @@ import (
"cwtch.im/cwtch/peer/peer" "cwtch.im/cwtch/peer/peer"
"cwtch.im/cwtch/protocol" "cwtch.im/cwtch/protocol"
"git.openprivacy.ca/openprivacy/libricochet-go" "git.openprivacy.ca/openprivacy/libricochet-go"
"git.openprivacy.ca/openprivacy/libricochet-go/application"
"git.openprivacy.ca/openprivacy/libricochet-go/channels" "git.openprivacy.ca/openprivacy/libricochet-go/channels"
"git.openprivacy.ca/openprivacy/libricochet-go/connection" "git.openprivacy.ca/openprivacy/libricochet-go/connection"
"git.openprivacy.ca/openprivacy/libricochet-go/identity" "git.openprivacy.ca/openprivacy/libricochet-go/identity"
"log" "log"
"time" "time"
"git.openprivacy.ca/openprivacy/libricochet-go/application"
) )
// PeerPeerConnection encapsulates a single outgoing Peer->Peer connection // PeerPeerConnection encapsulates a single outgoing Peer->Peer connection
@ -76,6 +76,7 @@ func (ppc *PeerPeerConnection) SendPacket(data []byte) {
}) })
} }
// DoOnChannel performs an operation on the requested channel
func (ppc *PeerPeerConnection) DoOnChannel(ctype string, direction channels.Direction, doSomethingWith func(channel *channels.Channel)) { func (ppc *PeerPeerConnection) DoOnChannel(ctype string, direction channels.Direction, doSomethingWith func(channel *channels.Channel)) {
ppc.WaitTilAuthenticated() ppc.WaitTilAuthenticated()
ppc.connection.Do(func() error { ppc.connection.Do(func() error {

View File

@ -6,6 +6,7 @@ import (
"cwtch.im/cwtch/peer/peer" "cwtch.im/cwtch/peer/peer"
"cwtch.im/cwtch/protocol" "cwtch.im/cwtch/protocol"
"git.openprivacy.ca/openprivacy/libricochet-go" "git.openprivacy.ca/openprivacy/libricochet-go"
"git.openprivacy.ca/openprivacy/libricochet-go/application"
"git.openprivacy.ca/openprivacy/libricochet-go/channels" "git.openprivacy.ca/openprivacy/libricochet-go/channels"
"git.openprivacy.ca/openprivacy/libricochet-go/connection" "git.openprivacy.ca/openprivacy/libricochet-go/connection"
"git.openprivacy.ca/openprivacy/libricochet-go/identity" "git.openprivacy.ca/openprivacy/libricochet-go/identity"
@ -81,7 +82,7 @@ func TestPeerPeerConnection(t *testing.T) {
profile := model.GenerateNewProfile("alice") profile := model.GenerateNewProfile("alice")
hostname := identity.Hostname() hostname := identity.Hostname()
ppc := NewPeerPeerConnection("127.0.0.1:5452|"+hostname, profile, nil) ppc := NewPeerPeerConnection("127.0.0.1:5452|"+hostname, profile, nil, application.ApplicationInstanceFactory{})
tp := new(TestPeer) tp := new(TestPeer)
tp.Init() tp.Init()

View File

@ -42,7 +42,7 @@ type cwtchPeer struct {
salt [128]byte salt [128]byte
dataHandler func(string, []byte) []byte dataHandler func(string, []byte) []byte
//handlers map[string]func(*application.ApplicationInstance) func() channels.Handler //handlers map[string]func(*application.ApplicationInstance) func() channels.Handler
aif application.ApplicationInstanceFactory aif application.ApplicationInstanceFactory
} }
// CwtchPeer provides us with a way of testing systems built on top of cwtch without having to // CwtchPeer provides us with a way of testing systems built on top of cwtch without having to