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
57a86cd5
Commit
57a86cd5
authored
Jul 17, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
547a6fa9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
29 deletions
+33
-29
go/neo/connection.go
go/neo/connection.go
+26
-26
go/neo/proto-str.go
go/neo/proto-str.go
+1
-1
go/neo/proto.go
go/neo/proto.go
+1
-1
go/neo/protogen.go
go/neo/protogen.go
+2
-0
go/neo/zproto-marshal.go
go/neo/zproto-marshal.go
+2
-0
go/neo/zproto-str.go
go/neo/zproto-str.go
+1
-1
No files found.
go/neo/connection.go
View file @
57a86cd5
...
...
@@ -53,11 +53,11 @@ import (
//
// It is safe to use NodeLink from multiple goroutines simultaneously.
type
NodeLink
struct
{
peerLink
net
.
Conn
// raw conn to peer
peerLink
net
.
Conn
// raw conn to peer
connMu
sync
.
Mutex
connTab
map
[
uint32
]
*
Conn
// connId -> Conn associated with connId
nextConnId
uint32
// next connId to use for Conn initiated by us
connTab
map
[
uint32
]
*
Conn
// connId -> Conn associated with connId
nextConnId
uint32
// next connId to use for Conn initiated by us
serveWg
sync
.
WaitGroup
// for serve{Send,Recv}
acceptq
chan
*
Conn
// queue of incoming connections for Accept
...
...
@@ -65,10 +65,10 @@ type NodeLink struct {
txq
chan
txReq
// tx requests from Conns go via here
// (rx packets are routed to Conn.rxq)
down
chan
struct
{}
// ready when NodeLink is marked as no longer operational
downOnce
sync
.
Once
// shutdown may be due to both Close and IO error
downWg
sync
.
WaitGroup
// for activities at shutdown
errClose
error
// error got from peerLink.Close
down
chan
struct
{}
// ready when NodeLink is marked as no longer operational
downOnce
sync
.
Once
// shutdown may be due to both Close and IO error
downWg
sync
.
WaitGroup
// for activities at shutdown
errClose
error
// error got from peerLink.Close
errMu
sync
.
Mutex
errRecv
error
// error got from recvPkt on shutdown
...
...
@@ -118,11 +118,11 @@ type ConnError struct {
// LinkRole is a role an end of NodeLink is intended to play
type
LinkRole
int
const
(
LinkServer
LinkRole
=
iota
// link created as server
LinkClient
// link created as client
LinkServer
LinkRole
=
iota
// link created as server
LinkClient
// link created as client
// for testing:
linkNoRecvSend
LinkRole
=
1
<<
16
// do not spawn serveRecv & serveSend
linkNoRecvSend
LinkRole
=
1
<<
16
// do not spawn serveRecv & serveSend
linkFlagsMask
LinkRole
=
(
1
<<
32
-
1
)
<<
16
)
...
...
@@ -148,13 +148,13 @@ const (
func
newNodeLink
(
conn
net
.
Conn
,
role
LinkRole
)
*
NodeLink
{
var
nextConnId
uint32
var
acceptq
chan
*
Conn
switch
role
&^
linkFlagsMask
{
switch
role
&^
linkFlagsMask
{
case
LinkServer
:
nextConnId
=
0
// all initiated by us connId will be even
acceptq
=
make
(
chan
*
Conn
)
// accept queue; TODO use backlog
nextConnId
=
0
// all initiated by us connId will be even
acceptq
=
make
(
chan
*
Conn
)
// accept queue; TODO use backlog
case
LinkClient
:
nextConnId
=
1
// ----//---- odd
acceptq
=
nil
// not accepting incoming connections
nextConnId
=
1
// ----//---- odd
acceptq
=
nil
// not accepting incoming connections
default
:
panic
(
"invalid conn role"
)
}
...
...
@@ -180,9 +180,9 @@ func newNodeLink(conn net.Conn, role LinkRole) *NodeLink {
func
(
nl
*
NodeLink
)
newConn
(
connId
uint32
)
*
Conn
{
c
:=
&
Conn
{
nodeLink
:
nl
,
connId
:
connId
,
rxq
:
make
(
chan
*
PktBuf
,
1
),
// NOTE non-blocking - see serveRecv
txerr
:
make
(
chan
error
,
1
),
// NOTE non-blocking - see Conn.Send
down
:
make
(
chan
struct
{}),
rxq
:
make
(
chan
*
PktBuf
,
1
),
// NOTE non-blocking - see serveRecv
txerr
:
make
(
chan
error
,
1
),
// NOTE non-blocking - see Conn.Send
down
:
make
(
chan
struct
{}),
}
nl
.
connTab
[
connId
]
=
c
return
c
...
...
@@ -229,7 +229,7 @@ func (nl *NodeLink) shutdown() {
// connMu - else it will deadlock.
conn
.
shutdown
()
}
nl
.
connTab
=
nil
// clear + mark down
nl
.
connTab
=
nil
// clear + mark down
nl
.
connMu
.
Unlock
()
}()
})
...
...
@@ -535,7 +535,7 @@ func (nl *NodeLink) sendPkt(pkt *PktBuf) error {
return
err
}
var
ErrPktTooBig
=
errors
.
New
(
"packet too big"
)
var
ErrPktTooBig
=
errors
.
New
(
"packet too big"
)
// recvPkt receives raw packet from peer
// rx error, if any, is returned as is and is analyzed in serveRecv
...
...
@@ -604,9 +604,9 @@ func Handshake(ctx context.Context, conn net.Conn, role LinkRole) (nl *NodeLink,
// HandshakeError is returned when there is an error while performing handshake
type
HandshakeError
struct
{
// XXX just keep .Conn? (but .Conn can be closed)
LocalAddr
net
.
Addr
RemoteAddr
net
.
Addr
Err
error
LocalAddr
net
.
Addr
RemoteAddr
net
.
Addr
Err
error
}
func
(
e
*
HandshakeError
)
Error
()
string
{
...
...
@@ -666,7 +666,7 @@ func handshake(ctx context.Context, conn net.Conn, version uint32) (err error) {
for
i
:=
0
;
i
<
2
;
i
++
{
select
{
case
<-
ctx
.
Done
()
:
conn
.
Close
()
// interrupt IO
conn
.
Close
()
// interrupt IO
connClosed
=
true
return
ctx
.
Err
()
...
...
@@ -776,12 +776,12 @@ func (c *Conn) Send(msg Msg) error {
traceConnSendPre
(
c
,
msg
)
l
:=
msg
.
NEOMsgEncodedLen
()
buf
:=
PktBuf
{
make
([]
byte
,
PktHeadLen
+
l
)}
// TODO -> freelist
buf
:=
PktBuf
{
make
([]
byte
,
PktHeadLen
+
l
)}
// TODO -> freelist
h
:=
buf
.
Header
()
// h.ConnId will be set by conn.Send
h
.
MsgCode
=
hton16
(
msg
.
NEOMsgCode
())
h
.
MsgLen
=
hton32
(
uint32
(
l
))
// XXX casting: think again
h
.
MsgLen
=
hton32
(
uint32
(
l
))
// XXX casting: think again
msg
.
NEOMsgEncode
(
buf
.
Payload
())
...
...
go/neo/proto-str.go
View file @
57a86cd5
//go:generate stringer -output
proto-str2
.go -type ErrorCode,NodeType proto.go
//go:generate stringer -output
zproto-str
.go -type ErrorCode,NodeType proto.go
package
neo
...
...
go/neo/proto.go
View file @
57a86cd5
//go:generate sh -c "go run protogen.go >proto-marshal.go"
//go:generate sh -c "go run protogen.go >
z
proto-marshal.go"
package
neo
// protocol definition
...
...
go/neo/protogen.go
View file @
57a86cd5
...
...
@@ -180,6 +180,8 @@ func main() {
buf
.
emit
(
`// Code generated by protogen.go; DO NOT EDIT.
package neo
// protocol messages to/from wire marshalling.
import (
"encoding/binary"
"reflect"
...
...
go/neo/proto-marshal.go
→
go/neo/
z
proto-marshal.go
View file @
57a86cd5
...
...
@@ -2,6 +2,8 @@
package
neo
// protocol messages to/from wire marshalling.
import
(
"encoding/binary"
"reflect"
...
...
go/neo/
proto-str2
.go
→
go/neo/
zproto-str
.go
View file @
57a86cd5
// Code generated by "stringer -output
proto-str2
.go -type ErrorCode,NodeType proto.go"; DO NOT EDIT.
// Code generated by "stringer -output
zproto-str
.go -type ErrorCode,NodeType proto.go"; DO NOT EDIT.
package
neo
...
...
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