From 5d6514a3de55db7d1ea4a336db05a67e71de3619 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 30 Jul 2019 16:43:07 -0700 Subject: [PATCH] Updating Connect Interface --- networks/tor/BaseOnionService.go | 10 +++++----- service.go | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/networks/tor/BaseOnionService.go b/networks/tor/BaseOnionService.go index 0e34442..52ce6c0 100644 --- a/networks/tor/BaseOnionService.go +++ b/networks/tor/BaseOnionService.go @@ -70,7 +70,7 @@ func (s *BaseOnionService) GetConnection(hostname string) (*tapir.Connection, er } // Connect initializes a new outbound connection to the given peer, using the defined Application -func (s *BaseOnionService) Connect(hostname string, app tapir.Application) (string, error) { +func (s *BaseOnionService) Connect(hostname string, app tapir.Application) (bool, error) { _, err := s.GetConnection(hostname) if err == nil { // Note: This check is not 100% reliable. And we may end up with two connections between peers @@ -78,7 +78,7 @@ func (s *BaseOnionService) Connect(hostname string, app tapir.Application) (stri // Because at the start of the connection the server cannot derive the true hostname of the client until it // has auth'd // We mitigate this by performing multiple checks when Connect'ing - return "", errors.New("already connected to " + hostname) + return true, errors.New("already connected to " + hostname) } // connects to a remote server // spins off to a connection struct @@ -93,15 +93,15 @@ func (s *BaseOnionService) Connect(hostname string, app tapir.Application) (stri _, err := s.GetConnection(hostname) if err == nil { conn.Close() - return "", errors.New("already connected to " + hostname) + return true, errors.New("already connected to " + hostname) } log.Debugf("Connected to %v [%v]", hostname, connectionID) s.connections.Store(connectionID, tapir.NewConnection(s.id, hostname, true, conn, app.NewInstance())) - return connectionID, nil + return true, nil } log.Debugf("Error connecting to %v %v", hostname, err) - return "", err + return false, err } func (s *BaseOnionService) getNewConnectionID() string { diff --git a/service.go b/service.go index 3443f0a..7a8cfa6 100644 --- a/service.go +++ b/service.go @@ -16,7 +16,7 @@ import ( // Service defines the interface for a Tapir Service type Service interface { Init(acn connectivity.ACN, privateKey ed25519.PrivateKey, identity identity.Identity) - Connect(hostname string, application Application) (string, error) + Connect(hostname string, application Application) (bool, error) Listen(application Application) error GetConnection(connectionID string) (*Connection, error) WaitForCapabilityOrClose(connectionID string, capability string) (*Connection, error) @@ -99,7 +99,7 @@ func (c *Connection) Expect() []byte { } } len, _ := binary.Uvarint(buffer[0:2]) - //log.Debugf("[%v -> %v] Wire Receive: (%d) %x", c.hostname, c.ID.Hostname(), len, buffer) + //cplog.Debugf("[%v -> %v] Wire Receive: (%d) %x", c.hostname, c.ID.Hostname(), len, buffer) return buffer[2 : len+2] }