-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple services #541
Multiple services #541
Conversation
d1f3899
to
cf53bc8
Compare
closes #483 |
} | ||
|
||
// Manager represents entrypoint for Noop service | ||
type Manager struct { | ||
fakeProcess sync.WaitGroup | ||
fakeProcess sync.WaitGroup | ||
locationResolver location.Resolver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need locationResolver
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess to lookup country in which service is provided. But country is hardcoded below :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct, somehow forgot it - implemented.
} | ||
|
||
// Manager represents entrypoint for Noop service | ||
type Manager struct { | ||
fakeProcess sync.WaitGroup | ||
fakeProcess sync.WaitGroup | ||
locationResolver location.Resolver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess to lookup country in which service is provided. But country is hardcoded below :(
4dd1ca6
to
b0dac46
Compare
os.Exit(2) | ||
} | ||
|
||
errorChannel := make(chan error, 2+len(serviceTypes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need 2+len here? Short comment would be good here.
core/service/manager.go
Outdated
@@ -46,10 +46,11 @@ type Service interface { | |||
Start(providerID identity.Identity) (dto_discovery.ServiceProposal, session.ConfigProvider, error) | |||
Wait() error | |||
Stop() error | |||
GetType() string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks artificial. Maybe its better to get type from serviceProposal returned by manager.service.Start(providerID) if needed? We should know what we are running.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like this manager to manage multiple services instead of one. This way it can have method Register(Service, serviceType), Start(list of services), or maybe I don't get the purpose of this component. It can also hide a map from di, which is leaky details
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way I see it, we'll still need the manager(maybe the naming needs a change, but naming is hard). I like that it's responsible for
- Registering/pinging the proposal
- Starting the service it's given
- Starting to listen for the relevant dialogs
We'll need these for every service, so in my head the component makes perfect sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case yes - better naming is needed. I didn't expect to see multiple managers :)
core/service/runner.go
Outdated
return nil | ||
} | ||
|
||
// KillAll kills all the service managers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// KillAll kills all the service managers | |
// KillAll kills all service managers |
server/mysterium_api_fake.go
Outdated
if filterMatched { | ||
var serviceMatched = true | ||
if serviceType != "" { | ||
serviceMatched = serviceMatched && (serviceType == proposal.ServiceType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serviceMatched = serviceMatched && (serviceType == proposal.ServiceType) | |
serviceMatched = (serviceType == proposal.ServiceType) |
services/noop/service.go
Outdated
} | ||
|
||
if manager.isStarted { | ||
return dto_discovery.ServiceProposal{}, sessionConfigProvider, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be "ErrAlreadyStarted" or return the same instance?
services/noop/service.go
Outdated
if manager.isStarted { | ||
return dto_discovery.ServiceProposal{}, sessionConfigProvider, nil | ||
} | ||
|
||
manager.fakeProcess.Add(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prob should not use 'fake' wording anymore here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed
// service type | ||
// required: false | ||
// default: openvpn | ||
// example: openvpn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should see somewhere what available options there are: openvpn, noop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small issues
cmd/commands/service/command.go
Outdated
if err != nil { | ||
return err | ||
} | ||
err = di.ServiceRunner.StartServiceByType(serviceType, options, errorChannel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of error channel here? method it self returns error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the error here tells us if the startup of services was successful. The channel is then used to report runtime errors that occur in the underlying service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Do we really need to report those errors upstairs? Startup errors are pretty much ok, but runtime errors - well I am not sure, what happens in case of that error - we shutdown whole node? What if other services run perfectly? Maybe some kind of retry mechanism is needed? Don't forget that service will be managed through api in the future - not only by args on startup.
cmd/di.go
Outdated
if err := di.ServiceManager.Kill(); err != nil { | ||
errs = append(errs, err) | ||
if di.ServiceRunner != nil { | ||
if runnerErrs := di.ServiceRunner.KillAll(); len(runnerErrs) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really need a len > 0 here ? Append of empty slice elements shouldn't append anything
cmd/di.go
Outdated
discoveryService, | ||
) | ||
if len(nodeOptions.ServiceTypes) > 0 { | ||
serviceManagerMap := make(map[string]service.RunnableService, len(nodeOptions.ServiceTypes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interface should be defined by caller or user. Anyway this block looks very complicated and hard to understand. I guess we can maintain a map of self registered services provides always ready, and runner only picks which ones to start according to options.
core/connection/interface.go
Outdated
@@ -49,7 +49,7 @@ type PromiseIssuerCreator func(issuerID identity.Identity, dialog communication. | |||
// Manager interface provides methods to manage connection | |||
type Manager interface { | |||
// Connect creates new connection from given consumer to provider, reports error if connection already exists | |||
Connect(consumerID identity.Identity, providerID identity.Identity, params ConnectParams) error | |||
Connect(consumerID identity.Identity, providerID identity.Identity, serviceType string, params ConnectParams) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's time to gather proposal related information in it's own params structure. In the long term connection manager shouldn't do a proposal lookup but get one as a parameter from outside.
core/connection/manager.go
Outdated
@@ -141,7 +141,7 @@ func (manager *connectionManager) startConnection(consumerID, providerID identit | |||
} | |||
}() | |||
|
|||
proposal, err := manager.findProposalByProviderID(providerID) | |||
proposal, err := manager.findProposalByProviderID(providerID, serviceType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parameter leaks from Connect only to be passed as a filter to discovery
core/service/manager.go
Outdated
@@ -46,10 +46,11 @@ type Service interface { | |||
Start(providerID identity.Identity) (dto_discovery.ServiceProposal, session.ConfigProvider, error) | |||
Wait() error | |||
Stop() error | |||
GetType() string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like this manager to manage multiple services instead of one. This way it can have method Register(Service, serviceType), Start(list of services), or maybe I don't get the purpose of this component. It can also hide a map from di, which is leaky details
Did a rework where a proposal is now passed to the connect method, and the manager no longer fetches it. Fixed most of the comments. |
@@ -114,7 +114,7 @@ func consumerConnectFlow(t *testing.T, tequilapi *tequilapi_client.Client, consu | |||
}) | |||
assert.NoError(t, err) | |||
|
|||
connectionStatus, err = tequilapi.Connect(consumerID, proposal.ProviderID, endpoints.ConnectOptions{true}) | |||
connectionStatus, err = tequilapi.Connect(consumerID, proposal.ProviderID, "openvpn", endpoints.ConnectOptions{true}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we pass here a proposal too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of scope, we'll need to fix the api part though, to avoid having to query for the service type in general. I've created #549 for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome 👍
The runners "startServiceByType" now blocks. |
@@ -28,7 +28,7 @@ import ( | |||
type Client interface { | |||
RegisterIdentity(id identity.Identity, signer identity.Signer) (err error) | |||
|
|||
FindProposals(providerID string) (proposals []dto_discovery.ServiceProposal, err error) | |||
FindProposals(providerID string, serviceType string) (proposals []dto_discovery.ServiceProposal, err error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's time to add method for single proposal fetch by it's identification
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK. Lets move on
myst service
now runs all the supported services(openvpn, noop). Adjusted the cli accordingly, we're now able to connect to a provider by specifying the service type as well. It's also possible to start a single service viamyst service openvpn
ormyst service noop