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
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) {
...
@@ -125,9 +125,10 @@ func NewClient(storLink *NodeLink) (*Client, error) {
// first identify ourselves to peer
// first identify ourselves to peer
storType
,
err
:=
IdentifyMe
(
storLink
,
CLIENT
)
storType
,
err
:=
IdentifyMe
(
storLink
,
CLIENT
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
// XXX err ctx
return
nil
,
err
}
}
if
storType
!=
STORAGE
{
if
storType
!=
STORAGE
{
// XXX + "newclient" to err ctx ?
return
nil
,
fmt
.
Errorf
(
"%v: peer is not storage (identifies as %v)"
,
storLink
,
storType
)
return
nil
,
fmt
.
Errorf
(
"%v: peer is not storage (identifies as %v)"
,
storLink
,
storType
)
}
}
...
@@ -139,7 +140,7 @@ func NewClient(storLink *NodeLink) (*Client, error) {
...
@@ -139,7 +140,7 @@ func NewClient(storLink *NodeLink) (*Client, error) {
// XXX -> server could reuse goroutines -> so not so bad ?
// XXX -> server could reuse goroutines -> so not so bad ?
storConn
,
err
:=
storLink
.
NewConn
()
storConn
,
err
:=
storLink
.
NewConn
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
// XXX err ctx
?
return
nil
,
err
// XXX err ctx
}
}
return
&
Client
{
storLink
,
storConn
},
nil
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) {
...
@@ -612,7 +612,7 @@ func handshake(ctx context.Context, conn net.Conn, version uint32) (err error) {
txWg
.
Add
(
1
)
txWg
.
Add
(
1
)
go
func
()
{
go
func
()
{
var
b
[
4
]
byte
var
b
[
4
]
byte
binary
.
BigEndian
.
PutUint32
(
b
[
:
],
version
/*+ 33*/
)
// XXX -> hton32 ?
binary
.
BigEndian
.
PutUint32
(
b
[
:
],
version
)
// XXX -> hton32 ?
_
,
err
:=
conn
.
Write
(
b
[
:
])
_
,
err
:=
conn
.
Write
(
b
[
:
])
// XXX EOF -> ErrUnexpectedEOF ?
// XXX EOF -> ErrUnexpectedEOF ?
errch
<-
err
errch
<-
err
...
...
go/neo/server.go
View file @
4b41deaa
...
@@ -93,27 +93,33 @@ func ListenAndServe(ctx context.Context, net_, laddr string, srv Server) error {
...
@@ -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.
// it expects peer to send RequestIdentification packet and replies with AcceptIdentification if identification passes.
// returns information about identified node or error.
// returns information about identified node or error.
func
IdentifyPeer
(
link
*
NodeLink
,
myNodeType
NodeType
)
(
nodeInfo
RequestIdentification
/*TODO -> NodeInfo*/
,
err
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
// the first conn must come with RequestIdentification packet
conn
,
err
:=
link
.
Accept
()
conn
,
err
:=
link
.
Accept
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nodeInfo
,
err
// XXX err ctx
return
nodeInfo
,
err
}
}
defer
func
()
{
defer
func
()
{
err2
:=
conn
.
Close
()
err2
:=
conn
.
Close
()
if
err
==
nil
{
if
err
==
nil
{
err
=
err2
// XXX err ctx
err
=
err2
// XXX also clear nodeInfo ?
// XXX also clear nodeInfo ?
}
}
}()
}()
pkt
,
err
:=
RecvAndDecode
(
conn
)
pkt
,
err
:=
RecvAndDecode
(
conn
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nodeInfo
,
err
// XXX err ctx
return
nodeInfo
,
err
}
}
switch
pkt
:=
pkt
.
(
type
)
{
switch
pkt
:=
pkt
.
(
type
)
{
default
:
default
:
return
nodeInfo
,
fmt
.
Errorf
(
"
expected RequestIdentification ; got
%T"
,
pkt
)
return
nodeInfo
,
fmt
.
Errorf
(
"
unexpected request:
%T"
,
pkt
)
// XXX also handle Error
// XXX also handle Error
...
@@ -140,6 +146,12 @@ func IdentifyPeer(link *NodeLink, myNodeType NodeType) (nodeInfo RequestIdentifi
...
@@ -140,6 +146,12 @@ func IdentifyPeer(link *NodeLink, myNodeType NodeType) (nodeInfo RequestIdentifi
// IdentifyMe identifies local node to remote peer
// IdentifyMe identifies local node to remote peer
func
IdentifyMe
(
link
*
NodeLink
,
nodeType
NodeType
/*XXX*/
)
(
peerType
NodeType
,
err
error
)
{
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
()
conn
,
err
:=
link
.
NewConn
()
if
err
!=
nil
{
if
err
!=
nil
{
return
peerType
,
err
return
peerType
,
err
...
@@ -147,7 +159,7 @@ func IdentifyMe(link *NodeLink, nodeType NodeType /*XXX*/) (peerType NodeType, e
...
@@ -147,7 +159,7 @@ func IdentifyMe(link *NodeLink, nodeType NodeType /*XXX*/) (peerType NodeType, e
defer
func
()
{
defer
func
()
{
err2
:=
conn
.
Close
()
err2
:=
conn
.
Close
()
if
err
==
nil
&&
err2
!=
nil
{
if
err
==
nil
&&
err2
!=
nil
{
err
=
err2
// XXX err ctx
err
=
err2
// XXX also reset peerType
// XXX also reset peerType
}
}
}()
}()
...
@@ -161,6 +173,7 @@ func IdentifyMe(link *NodeLink, nodeType NodeType /*XXX*/) (peerType NodeType, e
...
@@ -161,6 +173,7 @@ func IdentifyMe(link *NodeLink, nodeType NodeType /*XXX*/) (peerType NodeType, e
})
})
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Printf
(
"eee -> %v
\n
"
,
err
)
return
peerType
,
err
return
peerType
,
err
}
}
...
@@ -171,7 +184,7 @@ func IdentifyMe(link *NodeLink, nodeType NodeType /*XXX*/) (peerType NodeType, e
...
@@ -171,7 +184,7 @@ func IdentifyMe(link *NodeLink, nodeType NodeType /*XXX*/) (peerType NodeType, e
switch
pkt
:=
pkt
.
(
type
)
{
switch
pkt
:=
pkt
.
(
type
)
{
default
:
default
:
return
peerType
,
fmt
.
Errorf
(
"
expected AcceptIdentification ; got
%T"
,
pkt
)
return
peerType
,
fmt
.
Errorf
(
"
unexpected answer:
%T"
,
pkt
)
// XXX also handle Error
// XXX also handle Error
...
...
go/neo/storage.go
View file @
4b41deaa
...
@@ -87,8 +87,7 @@ func (stor *Storage) ServeLink(ctx context.Context, link *NodeLink) {
...
@@ -87,8 +87,7 @@ func (stor *Storage) ServeLink(ctx context.Context, link *NodeLink) {
for
{
for
{
conn
,
err
:=
link
.
Accept
()
conn
,
err
:=
link
.
Accept
()
if
err
!=
nil
{
if
err
!=
nil
{
// XXX both link and accept op should be generated in link.Accept
fmt
.
Printf
(
"stor: %v
\n
"
,
err
)
// XXX err ctx
fmt
.
Printf
(
"stor: %v: accept: %v
\n
"
,
link
,
err
)
// XXX err ctx
break
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