Skip to content

Commit

Permalink
Move service interfaces into api file
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Jan 5, 2024
1 parent b60dddc commit b1ad959
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 93 deletions.
100 changes: 100 additions & 0 deletions service/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package service

import "net"

/* EEBUSService */

//go:generate mockgen -destination=mock_service_test.go -package=service github.com/enbility/eebus-go/service EEBUSServiceHandler

// interface for receiving data for specific events
type EEBUSServiceHandler interface {
// report all currently visible EEBUS services
VisibleRemoteServicesUpdated(service *EEBUSService, entries []RemoteService)

// report a connection to a SKI
RemoteSKIConnected(service *EEBUSService, ski string)

// report a disconnection to a SKI
RemoteSKIDisconnected(service *EEBUSService, ski string)

// Provides the SHIP ID the remote service reported during the handshake process
// This needs to be persisted and passed on for future remote service connections
// when using `PairRemoteService`
ServiceShipIDUpdate(ski string, shipdID string)

// Provides the current pairing state for the remote service
// This is called whenever the state changes and can be used to
// provide user information for the pairing/connection process
ServicePairingDetailUpdate(ski string, detail *ConnectionStateDetail)

// return if the user is still able to trust the connection
AllowWaitingForTrust(ski string) bool
}

/* Hub */

//go:generate mockgen -destination=mock_hub_test.go -package=service github.com/enbility/eebus-go/service ServiceProvider,ConnectionsHub

// interface for reporting data from connectionsHub to the EEBUSService
type ServiceProvider interface {
// report a newly discovered remote EEBUS service
VisibleMDNSRecordsUpdated(entries []*MdnsEntry)

// report a connection to a SKI
RemoteSKIConnected(ski string)

// report a disconnection to a SKI
RemoteSKIDisconnected(ski string)

// provide the SHIP ID received during SHIP handshake process
// the ID needs to be stored and then provided for remote services so it can be compared and verified
ServiceShipIDUpdate(ski string, shipID string)

// provides the current handshake state for a given SKI
ServicePairingDetailUpdate(ski string, detail *ConnectionStateDetail)

// return if the user is still able to trust the connection
AllowWaitingForTrust(ski string) bool
}

type ConnectionsHub interface {
PairingDetailForSki(ski string) *ConnectionStateDetail
StartBrowseMdnsSearch()
StopBrowseMdnsSearch()
Start()
Shutdown()
ServiceForSKI(ski string) *ServiceDetails
RegisterRemoteSKI(ski string, enable bool)
InitiatePairingWithSKI(ski string)
CancelPairingWithSKI(ski string)
DisconnectSKI(ski string, reason string)
}

/* Mdns */

//go:generate mockgen -destination=mock_mdns_test.go -package=service github.com/enbility/eebus-go/service MdnsSearch,MdnsService

// implemented by hubConnection, used by mdns
type MdnsSearch interface {
ReportMdnsEntries(entries map[string]*MdnsEntry)
}

// implemented by mdns, used by hubConnection
type MdnsService interface {
SetupMdnsService() error
ShutdownMdnsService()
AnnounceMdnsEntry() error
UnannounceMdnsEntry()
RegisterMdnsSearch(cb MdnsSearch)
UnregisterMdnsSearch(cb MdnsSearch)
}

//go:generate mockery --name=MdnsProvider

type MdnsProvider interface {
CheckAvailability() bool
Shutdown()
Announce(serviceName string, port int, txt []string) error
Unannounce()
ResolveEntries(cancelChan chan bool, callback func(elements map[string]string, name, host string, addresses []net.IP, port int, remove bool))
}
37 changes: 0 additions & 37 deletions service/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,43 +40,6 @@ var connectionInitiationDelayTimeRanges = []connectionInitiationDelayTimeRange{
{min: 10, max: 20},
}

//go:generate mockgen -destination=mock_hub_test.go -package=service github.com/enbility/eebus-go/service ServiceProvider,ConnectionsHub

// interface for reporting data from connectionsHub to the EEBUSService
type ServiceProvider interface {
// report a newly discovered remote EEBUS service
VisibleMDNSRecordsUpdated(entries []*MdnsEntry)

// report a connection to a SKI
RemoteSKIConnected(ski string)

// report a disconnection to a SKI
RemoteSKIDisconnected(ski string)

// provide the SHIP ID received during SHIP handshake process
// the ID needs to be stored and then provided for remote services so it can be compared and verified
ServiceShipIDUpdate(ski string, shipID string)

// provides the current handshake state for a given SKI
ServicePairingDetailUpdate(ski string, detail *ConnectionStateDetail)

// return if the user is still able to trust the connection
AllowWaitingForTrust(ski string) bool
}

type ConnectionsHub interface {
PairingDetailForSki(ski string) *ConnectionStateDetail
StartBrowseMdnsSearch()
StopBrowseMdnsSearch()
Start()
Shutdown()
ServiceForSKI(ski string) *ServiceDetails
RegisterRemoteSKI(ski string, enable bool)
InitiatePairingWithSKI(ski string)
CancelPairingWithSKI(ski string)
DisconnectSKI(ski string, reason string)
}

// handling all connections to remote services
type connectionsHubImpl struct {
connections map[string]ship.ShipConnection
Expand Down
17 changes: 0 additions & 17 deletions service/mdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,6 @@ type MdnsEntry struct {
Addresses []net.IP // mandatory
}

//go:generate mockgen -destination=mock_mdns_test.go -package=service github.com/enbility/eebus-go/service MdnsSearch,MdnsService

// implemented by hubConnection, used by mdns
type MdnsSearch interface {
ReportMdnsEntries(entries map[string]*MdnsEntry)
}

// implemented by mdns, used by hubConnection
type MdnsService interface {
SetupMdnsService() error
ShutdownMdnsService()
AnnounceMdnsEntry() error
UnannounceMdnsEntry()
RegisterMdnsSearch(cb MdnsSearch)
UnregisterMdnsSearch(cb MdnsSearch)
}

type mdnsManager struct {
configuration *Configuration
ski string
Expand Down
12 changes: 0 additions & 12 deletions service/mdns/types.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
package mdns

import "net"

const shipZeroConfServiceType = "_ship._tcp"
const shipZeroConfDomain = "local."

//go:generate mockery --name=MdnsProvider

type MdnsProvider interface {
CheckAvailability() bool
Shutdown()
Announce(serviceName string, port int, txt []string) error
Unannounce()
ResolveEntries(cancelChan chan bool, callback func(elements map[string]string, name, host string, addresses []net.IP, port int, remove bool))
}
27 changes: 0 additions & 27 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,6 @@ type RemoteService struct {
Model string `json:"model"`
}

//go:generate mockgen -destination=mock_service_test.go -package=service github.com/enbility/eebus-go/service EEBUSServiceHandler

// interface for receiving data for specific events
type EEBUSServiceHandler interface {
// report all currently visible EEBUS services
VisibleRemoteServicesUpdated(service *EEBUSService, entries []RemoteService)

// report a connection to a SKI
RemoteSKIConnected(service *EEBUSService, ski string)

// report a disconnection to a SKI
RemoteSKIDisconnected(service *EEBUSService, ski string)

// Provides the SHIP ID the remote service reported during the handshake process
// This needs to be persisted and passed on for future remote service connections
// when using `PairRemoteService`
ServiceShipIDUpdate(ski string, shipdID string)

// Provides the current pairing state for the remote service
// This is called whenever the state changes and can be used to
// provide user information for the pairing/connection process
ServicePairingDetailUpdate(ski string, detail *ConnectionStateDetail)

// return if the user is still able to trust the connection
AllowWaitingForTrust(ski string) bool
}

// A service is the central element of an EEBUS service
// including its websocket server and a zeroconf service.
type EEBUSService struct {
Expand Down

0 comments on commit b1ad959

Please sign in to comment.