Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
3c0e3c38
Commit
3c0e3c38
authored
Feb 12, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
f62fba7e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
18 deletions
+23
-18
go/neo/storage.go
go/neo/storage.go
+23
-18
No files found.
go/neo/storage.go
View file @
3c0e3c38
...
@@ -305,22 +305,28 @@ func (stor *Storage) m1serve1(ctx context.Context, req neonet.Request) error {
...
@@ -305,22 +305,28 @@ func (stor *Storage) m1serve1(ctx context.Context, req neonet.Request) error {
// --- serve incoming connections from other nodes ---
// --- serve incoming connections from other nodes ---
// identify processes identification request from connected peer.
// identify processes identification request from connected peer.
func
(
stor
*
Storage
)
identify
(
ctx
context
.
Context
,
idReq
*
proto
.
RequestIdentification
)
(
proto
.
Msg
,
bool
)
{
func
(
stor
*
Storage
)
identify
(
ctx
context
.
Context
,
idReq
*
proto
.
RequestIdentification
)
(
idResp
proto
.
Msg
,
err
error
)
{
idResp
,
ok
:=
stor
.
identify_
(
idReq
)
accept
,
reject
:=
stor
.
identify_
(
idReq
)
if
ok
{
if
accept
!=
nil
{
log
.
Info
(
ctx
,
"accepting identification"
)
log
.
Info
(
ctx
,
"accepting identification"
)
idResp
=
accept
}
else
{
}
else
{
log
.
Info
(
ctx
,
"rejecting identification (%s)"
,
idResp
.
(
*
proto
.
Error
)
.
Message
)
log
.
Info
(
ctx
,
"rejecting identification (%s)"
,
reject
.
Message
)
idResp
=
reject
}
}
return
idResp
,
ok
var
ereject
error
if
reject
!=
nil
{
ereject
=
reject
}
return
idResp
,
ereject
}
}
func
(
stor
*
Storage
)
identify_
(
idReq
*
proto
.
RequestIdentification
)
(
proto
.
Msg
,
bool
)
{
func
(
stor
*
Storage
)
identify_
(
idReq
*
proto
.
RequestIdentification
)
(
proto
.
Msg
,
*
proto
.
Error
)
{
// XXX stub: we accept clients and don't care about their NID
// XXX stub: we accept clients and don't care about their NID
if
idReq
.
NodeType
!=
proto
.
CLIENT
{
if
idReq
.
NodeType
!=
proto
.
CLIENT
{
return
&
proto
.
Error
{
proto
.
PROTOCOL_ERROR
,
"only clients are accepted"
},
false
return
nil
,
&
proto
.
Error
{
proto
.
PROTOCOL_ERROR
,
"only clients are accepted"
}
}
}
if
idReq
.
ClusterName
!=
stor
.
node
.
ClusterName
{
if
idReq
.
ClusterName
!=
stor
.
node
.
ClusterName
{
return
&
proto
.
Error
{
proto
.
PROTOCOL_ERROR
,
"cluster name mismatch"
},
false
return
nil
,
&
proto
.
Error
{
proto
.
PROTOCOL_ERROR
,
"cluster name mismatch"
}
}
}
// check operational
// check operational
...
@@ -329,14 +335,14 @@ func (stor *Storage) identify_(idReq *proto.RequestIdentification) (proto.Msg, b
...
@@ -329,14 +335,14 @@ func (stor *Storage) identify_(idReq *proto.RequestIdentification) (proto.Msg, b
stor
.
opMu
.
Unlock
()
stor
.
opMu
.
Unlock
()
if
!
operational
{
if
!
operational
{
return
&
proto
.
Error
{
proto
.
NOT_READY
,
"cluster not operational"
},
false
return
nil
,
&
proto
.
Error
{
proto
.
NOT_READY
,
"cluster not operational"
}
}
}
return
&
proto
.
AcceptIdentification
{
return
&
proto
.
AcceptIdentification
{
NodeType
:
stor
.
node
.
MyInfo
.
Type
,
NodeType
:
stor
.
node
.
MyInfo
.
Type
,
MyNID
:
stor
.
node
.
MyInfo
.
NID
,
// XXX lock wrt update
MyNID
:
stor
.
node
.
MyInfo
.
NID
,
// XXX lock wrt update
YourNID
:
idReq
.
NID
,
YourNID
:
idReq
.
NID
,
},
true
},
nil
}
}
...
@@ -355,18 +361,17 @@ func (stor *Storage) withWhileOperational(ctx context.Context) (context.Context,
...
@@ -355,18 +361,17 @@ func (stor *Storage) withWhileOperational(ctx context.Context) (context.Context,
// serveLink serves incoming node-node link connection.
// serveLink serves incoming node-node link connection.
func
(
stor
*
Storage
)
serveLink
(
ctx
context
.
Context
,
req
*
neonet
.
Request
,
idReq
*
proto
.
RequestIdentification
)
(
err
error
)
{
func
(
stor
*
Storage
)
serveLink
(
ctx
context
.
Context
,
req
*
neonet
.
Request
,
idReq
*
proto
.
RequestIdentification
)
(
err
error
)
{
link
:=
req
.
Link
()
link
:=
req
.
Link
()
defer
task
.
Runningf
(
&
ctx
,
"serve %s"
,
link
)(
&
err
)
defer
task
.
Runningf
(
&
ctx
,
"serve %s"
,
idReq
.
NID
)(
&
err
)
defer
xio
.
CloseWhenDone
(
ctx
,
link
)()
defer
xio
.
CloseWhenDone
(
ctx
,
link
)()
// first process identification
// first process identification
// XXX just req.Reply(idResp) + return if !ok
// TODO -> .Accept() that would listen, handshake and identify a node
idResp
,
ok
:=
stor
.
identify
(
ctx
,
idReq
)
// -> and only then return it to serve loop if identified ok.
if
!
ok
{
idResp
,
err
:=
stor
.
identify
(
ctx
,
idReq
)
reject
(
ctx
,
req
,
idResp
)
err2
:=
req
.
Reply
(
idResp
)
return
nil
if
err
==
nil
{
err
=
err2
}
}
err
=
accept
(
ctx
,
req
,
idResp
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
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