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
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
4b41deaa
Commit
4b41deaa
authored
May 11, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X error context for IdentifyMe & Identify
parent
6fd0c9be
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
11 deletions
+24
-11
go/neo/client.go
go/neo/client.go
+3
-2
go/neo/connection.go
go/neo/connection.go
+1
-1
go/neo/server.go
go/neo/server.go
+19
-6
go/neo/storage.go
go/neo/storage.go
+1
-2
No files found.
go/neo/client.go
View file @
4b41deaa
...
...
@@ -125,9 +125,10 @@ func NewClient(storLink *NodeLink) (*Client, error) {
// first identify ourselves to peer
storType
,
err
:=
IdentifyMe
(
storLink
,
CLIENT
)
if
err
!=
nil
{
return
nil
,
err
// XXX err ctx
return
nil
,
err
}
if
storType
!=
STORAGE
{
// XXX + "newclient" to err ctx ?
return
nil
,
fmt
.
Errorf
(
"%v: peer is not storage (identifies as %v)"
,
storLink
,
storType
)
}
...
...
@@ -139,7 +140,7 @@ func NewClient(storLink *NodeLink) (*Client, error) {
// XXX -> server could reuse goroutines -> so not so bad ?
storConn
,
err
:=
storLink
.
NewConn
()
if
err
!=
nil
{
return
nil
,
err
// XXX err ctx
?
return
nil
,
err
// XXX err ctx
}
return
&
Client
{
storLink
,
storConn
},
nil
...
...
go/neo/connection.go
View file @
4b41deaa
...
...
@@ -612,7 +612,7 @@ func handshake(ctx context.Context, conn net.Conn, version uint32) (err error) {
txWg
.
Add
(
1
)
go
func
()
{
var
b
[
4
]
byte
binary
.
BigEndian
.
PutUint32
(
b
[
:
],
version
/*+ 33*/
)
// XXX -> hton32 ?
binary
.
BigEndian
.
PutUint32
(
b
[
:
],
version
)
// XXX -> hton32 ?
_
,
err
:=
conn
.
Write
(
b
[
:
])
// XXX EOF -> ErrUnexpectedEOF ?
errch
<-
err
...
...
go/neo/server.go
View file @
4b41deaa
...
...
@@ -93,27 +93,33 @@ func ListenAndServe(ctx context.Context, net_, laddr string, srv Server) error {
// it expects peer to send RequestIdentification packet and replies with AcceptIdentification if identification passes.
// returns information about identified node or error.
func
IdentifyPeer
(
link
*
NodeLink
,
myNodeType
NodeType
)
(
nodeInfo
RequestIdentification
/*TODO -> NodeInfo*/
,
err
error
)
{
defer
func
()
{
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"%s: identify: %s"
,
link
,
err
)
}
}()
// the first conn must come with RequestIdentification packet
conn
,
err
:=
link
.
Accept
()
if
err
!=
nil
{
return
nodeInfo
,
err
// XXX err ctx
return
nodeInfo
,
err
}
defer
func
()
{
err2
:=
conn
.
Close
()
if
err
==
nil
{
err
=
err2
// XXX err ctx
err
=
err2
// XXX also clear nodeInfo ?
}
}()
pkt
,
err
:=
RecvAndDecode
(
conn
)
if
err
!=
nil
{
return
nodeInfo
,
err
// XXX err ctx
return
nodeInfo
,
err
}
switch
pkt
:=
pkt
.
(
type
)
{
default
:
return
nodeInfo
,
fmt
.
Errorf
(
"
expected RequestIdentification ; got
%T"
,
pkt
)
return
nodeInfo
,
fmt
.
Errorf
(
"
unexpected request:
%T"
,
pkt
)
// XXX also handle Error
...
...
@@ -140,6 +146,12 @@ func IdentifyPeer(link *NodeLink, myNodeType NodeType) (nodeInfo RequestIdentifi
// IdentifyMe identifies local node to remote peer
func
IdentifyMe
(
link
*
NodeLink
,
nodeType
NodeType
/*XXX*/
)
(
peerType
NodeType
,
err
error
)
{
defer
func
()
{
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"%s: request identification: %s"
,
link
,
err
)
}
}()
conn
,
err
:=
link
.
NewConn
()
if
err
!=
nil
{
return
peerType
,
err
...
...
@@ -147,7 +159,7 @@ func IdentifyMe(link *NodeLink, nodeType NodeType /*XXX*/) (peerType NodeType, e
defer
func
()
{
err2
:=
conn
.
Close
()
if
err
==
nil
&&
err2
!=
nil
{
err
=
err2
// XXX err ctx
err
=
err2
// XXX also reset peerType
}
}()
...
...
@@ -161,6 +173,7 @@ func IdentifyMe(link *NodeLink, nodeType NodeType /*XXX*/) (peerType NodeType, e
})
if
err
!=
nil
{
fmt
.
Printf
(
"eee -> %v
\n
"
,
err
)
return
peerType
,
err
}
...
...
@@ -171,7 +184,7 @@ func IdentifyMe(link *NodeLink, nodeType NodeType /*XXX*/) (peerType NodeType, e
switch
pkt
:=
pkt
.
(
type
)
{
default
:
return
peerType
,
fmt
.
Errorf
(
"
expected AcceptIdentification ; got
%T"
,
pkt
)
return
peerType
,
fmt
.
Errorf
(
"
unexpected answer:
%T"
,
pkt
)
// XXX also handle Error
...
...
go/neo/storage.go
View file @
4b41deaa
...
...
@@ -87,8 +87,7 @@ func (stor *Storage) ServeLink(ctx context.Context, link *NodeLink) {
for
{
conn
,
err
:=
link
.
Accept
()
if
err
!=
nil
{
// XXX both link and accept op should be generated in link.Accept
fmt
.
Printf
(
"stor: %v: accept: %v
\n
"
,
link
,
err
)
// XXX err ctx
fmt
.
Printf
(
"stor: %v
\n
"
,
err
)
// XXX err ctx
break
}
...
...
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