-
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
Move towards a more modular connection manager #385
Move towards a more modular connection manager #385
Conversation
core/connection/manager.go
Outdated
@@ -89,14 +88,14 @@ func (manager *connectionManager) Connect(consumerID, providerID identity.Identi | |||
} | |||
}() | |||
|
|||
err = manager.startConnection(consumerID, providerID, options) | |||
err = manager.start(consumerID, providerID, options) |
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.
Start what? because manager is already running.
manager.start()
-> manager.startConnection()
or manager.createConnection()
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 wo dont need 2 manager functions for start
and startConnection
and we can merge them?
core/connection/connect_options.go
Outdated
// ConnectOptions holds connect options | ||
type ConnectOptions struct { | ||
// kill switch option restricting communication only through VPN | ||
DisableKillSwitch bool | ||
} | ||
|
||
// Params represents the params we need to ensure a successful connection | ||
type Params struct { |
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.
Struct looks like a duplicate of ConnectOptions.
A. Suggest to merge to ConnectOptions
B. Maybe:
Params
->ConnectOptions
ConnectOptions
->ConnectionParams
-> represents plugin specific params
core/connection/connect_options.go
Outdated
|
||
// Params represents the params we need to ensure a successful connection | ||
type Params struct { | ||
DisableKillSwitch bool |
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.
Same param
type VpnClientCreator func(session.SessionDto, identity.Identity, identity.Identity, state.Callback, ConnectOptions) (openvpn.Process, error) | ||
// Connection represents a connection | ||
type Connection interface { | ||
Start() 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.
Extra line
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.
not sure what you mean by that, what extra line?
core/connection/manager_test.go
Outdated
} | ||
|
||
//this is the last state - close channel (according to best practices of go - channel writer controls channel) | ||
if openvpnState == openvpn.ProcessExited { |
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.
tests should not know about openvpn also
core/connection/openvpn.go
Outdated
close(channel) | ||
} | ||
// OpenVpnStateCallbackToConnectionState maps openvpn.State to connection.State. Returns a pointer to connection.state, or nil | ||
func OpenVpnStateCallbackToConnectionState(input openvpn.State) *State { |
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 we really return a pointer here? Returning value can make the code more readable:
switch input {
case openvpn.ConnectedState:
return Connected
case openvpn.ExitingState:
return Disconnecting
case openvpn.ReconnectingState:
return Reconnecting
default:
return Unknown
}
And we can introduce Unknown
state to avoid nil
core/connection/manager.go
Outdated
// ErrOpenvpnProcessDied indicates that Connect method didn't reach "Connected" phase due to openvpn error | ||
ErrOpenvpnProcessDied = errors.New("openvpn process died") | ||
// ErrConnectionDied indicates that Connect method didn't reach "Connected" phase due to connection error | ||
ErrConnectionDied = errors.New("connection has died") |
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.
Would use ConnectionFailed, since Died would imply that it was alive in the first place.
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.
ConnectionFailed
better ConnectingFailed
f0fd72f
to
9db3def
Compare
core/connection/interface.go
Outdated
|
||
// VpnConnectionCreator creates new vpn client by given session, | ||
// consumer identity, provider identity and uses state channel to report state changes | ||
type VpnConnectionCreator func(ConnectOptions, StateChannel) (Connection, 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.
Where should be no VPN work in core/connection
package
598ad67
to
69899eb
Compare
69899eb
to
6a1cfa2
Compare
} | ||
|
||
// NewOpenvpnProcessBasedConnectionFactory creates a new OpenvpnProcessBasedConnectionFactory | ||
func NewOpenvpnProcessBasedConnectionFactory( |
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 try to get rid of New..Factory() methods, we should proceed this this at this point.
core/connection/manager.go
Outdated
manager.mutex.Lock() | ||
defer manager.mutex.Unlock() | ||
|
||
switch state { | ||
case openvpn.ConnectedState: | ||
manager.statsKeeper.MarkSessionStart() |
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 am a bit concerned with a move of manager.statsKeeper.MarkSessionStart() to openvpn package, since it should be as a general contract to implement. Specific transport should always implement statistics collection. Most basic assumption is that each connection will have a start and a finish. Any implementation details should be hidden behind those.
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.
need discussion with move of stats keeper to specific transport. How those stats should relate with statistics sender? Statistics sender should always expect statistics to be available.
232e8bf
to
6c10259
Compare
6c10259
to
0421b08
Compare
369aa37
to
287f010
Compare
287f010
to
0439ff3
Compare
Looking for feedback for this one.
updates #382