Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
c5775014
Commit
c5775014
authored
Feb 03, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
3ef9b607
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
48 deletions
+50
-48
go/neo/mastered.go
go/neo/mastered.go
+1
-48
go/neo/xneo/connect.go
go/neo/xneo/connect.go
+49
-0
No files found.
go/neo/mastered.go
View file @
c5775014
...
...
@@ -28,7 +28,6 @@ import (
"sync"
"time"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/go123/xnet"
"lab.nexedi.com/kirr/go123/xsync"
...
...
@@ -187,7 +186,7 @@ func (node *_MasteredNode) talkMaster1(ctx, ctxPreTalkM context.Context, f func(
DevPath
:
nil
,
// XXX stub
NewNID
:
nil
,
// XXX stub
}
mlink
,
accept
,
err
:=
dialNode
(
ctx
,
proto
.
MASTER
,
node
.
Net
,
node
.
MasterAddr
,
reqID
)
mlink
,
accept
,
err
:=
xneo
.
Dial
(
ctx
,
proto
.
MASTER
,
node
.
Net
,
node
.
MasterAddr
,
reqID
)
if
err
!=
nil
{
return
err
}
...
...
@@ -462,51 +461,5 @@ func (node *_MasteredNode) updateNodeTab(ctx context.Context, msg *proto.NotifyN
}
// XXX Dial + request identification + verify peer type
func
dialNode
(
ctx
context
.
Context
,
typ
proto
.
NodeType
,
net
xnet
.
Networker
,
addr
string
,
reqID
*
proto
.
RequestIdentification
)
(
_
*
neonet
.
NodeLink
,
_
*
proto
.
AcceptIdentification
,
err
error
)
{
defer
task
.
Runningf
(
&
ctx
,
"dial %s (%s)"
,
addr
,
typ
)(
&
err
)
link
,
err
:=
neonet
.
DialLink
(
ctx
,
net
,
addr
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
log
.
Info
(
ctx
,
"dialed ok; requesting identification..."
)
defer
xerr
.
Contextf
(
&
err
,
"%s: request identification"
,
link
)
accept
:=
&
proto
.
AcceptIdentification
{}
err
=
xcontext
.
WithCloseOnErrCancel
(
ctx
,
link
,
func
()
error
{
// FIXME error if peer sends us something with another connID
// (currently we ignore and serveRecv will deadlock)
//
// XXX solution could be:
// link.CloseAccept()
// link.Ask1(reqID, accept)
// link.Listen()
// XXX but there is a race window in between recv in ask and listen
// start, and if peer sends new connection in that window it will be rejected.
//
// TODO thinking.
err
=
link
.
Ask1
(
reqID
,
accept
)
if
err
!=
nil
{
return
err
}
if
accept
.
NodeType
!=
typ
{
// XXX send Error to peer?
return
fmt
.
Errorf
(
"accepted, but peer is not %v (identifies as %v)"
,
typ
,
accept
.
NodeType
)
}
return
nil
})
if
err
!=
nil
{
return
nil
,
nil
,
err
}
log
.
Info
(
ctx
,
"identification accepted"
)
return
link
,
accept
,
nil
}
// XXX = Dial node by NID, verify it accepts with "MyNID" == NID, YourNID == NID we sent
// func dialNID
go/neo/xneo/connect.go
View file @
c5775014
...
...
@@ -26,6 +26,10 @@ import (
"net"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/go123/xnet"
"lab.nexedi.com/kirr/neo/go/internal/log"
"lab.nexedi.com/kirr/neo/go/internal/task"
"lab.nexedi.com/kirr/neo/go/internal/xcontext"
"lab.nexedi.com/kirr/neo/go/neo/neonet"
"lab.nexedi.com/kirr/neo/go/neo/proto"
...
...
@@ -97,3 +101,48 @@ func (l *listener) Accept(ctx context.Context) (_ *neonet.Request, msgID *proto.
func
(
l
*
listener
)
Close
()
error
{
return
l
.
l
.
Close
()
}
func
(
l
*
listener
)
Addr
()
net
.
Addr
{
return
l
.
l
.
Addr
()
}
// XXX Dial + request identification + verify peer type
func
Dial
(
ctx
context
.
Context
,
typ
proto
.
NodeType
,
net
xnet
.
Networker
,
addr
string
,
reqID
*
proto
.
RequestIdentification
)
(
_
*
neonet
.
NodeLink
,
_
*
proto
.
AcceptIdentification
,
err
error
)
{
defer
task
.
Runningf
(
&
ctx
,
"dial %s (%s)"
,
addr
,
typ
)(
&
err
)
link
,
err
:=
neonet
.
DialLink
(
ctx
,
net
,
addr
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
log
.
Info
(
ctx
,
"dialed ok; requesting identification..."
)
defer
xerr
.
Contextf
(
&
err
,
"%s: request identification"
,
link
)
accept
:=
&
proto
.
AcceptIdentification
{}
err
=
xcontext
.
WithCloseOnErrCancel
(
ctx
,
link
,
func
()
error
{
// FIXME error if peer sends us something with another connID
// (currently we ignore and serveRecv will deadlock)
//
// XXX solution could be:
// link.CloseAccept()
// link.Ask1(reqID, accept)
// link.Listen()
// XXX but there is a race window in between recv in ask and listen
// start, and if peer sends new connection in that window it will be rejected.
//
// TODO thinking.
err
=
link
.
Ask1
(
reqID
,
accept
)
if
err
!=
nil
{
return
err
}
if
accept
.
NodeType
!=
typ
{
// XXX send Error to peer?
return
fmt
.
Errorf
(
"accepted, but peer is not %v (identifies as %v)"
,
typ
,
accept
.
NodeType
)
}
return
nil
})
if
err
!=
nil
{
return
nil
,
nil
,
err
}
log
.
Info
(
ctx
,
"identification accepted"
)
return
link
,
accept
,
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment