Browse Source

Updating Connect Interface

progress v0.1.6
Sarah Jamie Lewis 3 years ago
parent
commit
5d6514a3de
  1. 10
      networks/tor/BaseOnionService.go
  2. 4
      service.go

10
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 {

4
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]
}

Loading…
Cancel
Save