-
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
MYST-41 Session generation and exchange #47
Changes from 4 commits
924118c
61c9855
629f922
a6bbde6
bd694d7
0b6a835
534c4f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ package communication | |
|
||
const ( | ||
// Client is trying to establish new dialog with Node | ||
DIALOG_CREATE = RequestType("dialog-create") | ||
GET_CONNECTION_CONFIG = RequestType("get-connection-config") | ||
DIALOG_CREATE = RequestType("dialog-create") | ||
SESSION_CREATE = RequestType("session-create") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest defining structs for message types type SessionCreate struct {
proposalId, serviceStartParams
} we also need response types defined here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Message types do have their own structs:) These constants are basically topics for the communication channel, so we still need them. |
||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package session | ||
|
||
import ( | ||
node_session "github.com/mysterium/node/session" | ||
) | ||
|
||
var manager node_session.Manager | ||
|
||
func NewVpnSession(config string) (session VpnSession) { | ||
id := manager.Create() | ||
|
||
session = VpnSession{ | ||
Id: id, | ||
Config: config, | ||
} | ||
|
||
return | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package session | ||
|
||
import "github.com/mysterium/node/session" | ||
|
||
type VpnSession struct { | ||
Id session.SessionId `json:"id"` | ||
Config string `json:"config"` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package session | ||
|
||
import ( | ||
"github.com/satori/go.uuid" | ||
) | ||
|
||
type SessionId string | ||
|
||
func GenerateSessionId() (sid SessionId) { | ||
sid = SessionId(uuid.NewV4().String()) | ||
|
||
return | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package session | ||
|
||
import ( | ||
"testing" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSessionIdLength(t *testing.T) { | ||
sid := GenerateSessionId() | ||
|
||
assert.Len(t, sid, 36) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package session | ||
|
||
type Manager struct { | ||
Sessions []SessionId | ||
} | ||
|
||
func (manager *Manager) Create() (sid SessionId) { | ||
sid = GenerateSessionId() | ||
|
||
manager.Sessions = append(manager.Sessions, sid) | ||
|
||
return sid | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package session | ||
|
||
import ( | ||
"testing" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestManagerHasSessionsStored(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does not look like unit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, testing the manager is kind of pointless in this case.. the only use case for unit tests would be to freeze the interface methods, does that make sense though? |
||
manager := Manager{} | ||
length := 10 | ||
|
||
for i := 0; i < length; i++ { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like loop with overhead.
|
||
manager.Create() | ||
} | ||
|
||
assert.Len(t, manager.Sessions, length) | ||
} |
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.
Missing acceptance:
Node responds “session_rejected” with “reasonType”, “reasonMessage” (when Client's proposalId mismatches with Node's current proposal)