Updating Connect Interface

This commit is contained in:
Sarah Jamie Lewis 2019-07-30 16:43:07 -07:00
parent 368e2ba61b
commit 5d6514a3de
2 changed files with 7 additions and 7 deletions

View File

@ -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 // 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) _, err := s.GetConnection(hostname)
if err == nil { if err == nil {
// Note: This check is not 100% reliable. And we may end up with two connections between peers // 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 // Because at the start of the connection the server cannot derive the true hostname of the client until it
// has auth'd // has auth'd
// We mitigate this by performing multiple checks when Connect'ing // 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 // connects to a remote server
// spins off to a connection struct // spins off to a connection struct
@ -93,15 +93,15 @@ func (s *BaseOnionService) Connect(hostname string, app tapir.Application) (stri
_, err := s.GetConnection(hostname) _, err := s.GetConnection(hostname)
if err == nil { if err == nil {
conn.Close() 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) log.Debugf("Connected to %v [%v]", hostname, connectionID)
s.connections.Store(connectionID, tapir.NewConnection(s.id, hostname, true, conn, app.NewInstance())) 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) log.Debugf("Error connecting to %v %v", hostname, err)
return "", err return false, err
} }
func (s *BaseOnionService) getNewConnectionID() string { func (s *BaseOnionService) getNewConnectionID() string {

View File

@ -16,7 +16,7 @@ import (
// Service defines the interface for a Tapir Service // Service defines the interface for a Tapir Service
type Service interface { type Service interface {
Init(acn connectivity.ACN, privateKey ed25519.PrivateKey, identity identity.Identity) 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 Listen(application Application) error
GetConnection(connectionID string) (*Connection, error) GetConnection(connectionID string) (*Connection, error)
WaitForCapabilityOrClose(connectionID string, capability 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]) 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] return buffer[2 : len+2]
} }