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
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
Stefane Fermigier
neo
Commits
e1a3677f
Commit
e1a3677f
authored
Aug 31, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
91be5cdd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
43 deletions
+12
-43
go/neo/connection.go
go/neo/connection.go
+12
-43
No files found.
go/neo/connection.go
View file @
e1a3677f
...
...
@@ -62,7 +62,6 @@ type NodeLink struct {
serveWg
sync
.
WaitGroup
// for serve{Send,Recv}
acceptq
chan
*
Conn
// queue of incoming connections for Accept
// = nil if NodeLink is not accepting connections <- XXX no
txq
chan
txReq
// tx requests from Conns go via here
// (rx packets are routed to Conn.rxq)
...
...
@@ -88,7 +87,7 @@ type NodeLink struct {
//
// It is safe to use Conn from multiple goroutines simultaneously.
type
Conn
struct
{
nodeLink
*
NodeLink
link
*
NodeLink
connId
uint32
rxq
chan
*
PktBuf
// received packets for this Conn go here
txerr
chan
error
// transmit results for this Conn go back here
...
...
@@ -187,7 +186,7 @@ func newNodeLink(conn net.Conn, role LinkRole) *NodeLink {
// newConn creates new Conn with id=connId and registers it into connTab.
// Must be called with connMu held.
func
(
nl
*
NodeLink
)
newConn
(
connId
uint32
)
*
Conn
{
c
:=
&
Conn
{
nodeL
ink
:
nl
,
c
:=
&
Conn
{
l
ink
:
nl
,
connId
:
connId
,
rxq
:
make
(
chan
*
PktBuf
,
1
),
// NOTE non-blocking - see serveRecv XXX +buf
txerr
:
make
(
chan
error
,
1
),
// NOTE non-blocking - see Conn.Send
...
...
@@ -382,37 +381,7 @@ func (c *Conn) CloseRecv() {
//
// It is safe to call Close several times.
func
(
c
*
Conn
)
Close
()
error
{
nl
:=
c
.
nodeLink
/*
// adjust nodeLink.connTab
nl.connMu.Lock()
if nl.connTab != nil {
// connection was initiated by us - simply delete - we always
// know if a packet comes to such connection it is closed.
if c.connId == nl.nextConnId % 2 {
delete(nl.connTab, c.connId)
// connection was initiated by peer which we accepted - put special
// "closed" connection into connTab entry for some time to reply
// "connection closed" if another packet comes to it.
} else {
// XXX we do not need to create new connection - enough to put our
// connection into proper state and delete it after some time - right?
cc := nl.newConn(c.connId)
cc.shutdownRX(errConnClosed)
time.AfterFunc(connKeepClosed, func() {
nl.connMu.Lock()
delete(nl.connTab, cc.connId)
nl.connMu.Unlock()
cc.shutdown()
})
}
}
nl.connMu.Unlock()
*/
nl
:=
c
.
link
c
.
closeOnce
.
Do
(
func
()
{
atomic
.
StoreInt32
(
&
c
.
rxclosed
,
1
)
atomic
.
StoreInt32
(
&
c
.
txclosed
,
1
)
...
...
@@ -500,7 +469,7 @@ func (c *Conn) errRecvShutdown() error {
case
atomic
.
LoadInt32
(
&
c
.
rxclosed
)
!=
0
:
return
ErrClosedConn
case
atomic
.
LoadInt32
(
&
c
.
nodeL
ink
.
closed
)
!=
0
:
case
atomic
.
LoadInt32
(
&
c
.
l
ink
.
closed
)
!=
0
:
return
ErrLinkClosed
default
:
...
...
@@ -509,9 +478,9 @@ func (c *Conn) errRecvShutdown() error {
// tell client the node link is no longer operational.
var
err
error
c
.
rxerrOnce
.
Do
(
func
()
{
c
.
nodeL
ink
.
errMu
.
Lock
()
err
=
c
.
nodeL
ink
.
errRecv
c
.
nodeL
ink
.
errMu
.
Unlock
()
c
.
l
ink
.
errMu
.
Lock
()
err
=
c
.
l
ink
.
errRecv
c
.
l
ink
.
errMu
.
Unlock
()
})
if
err
==
nil
{
err
=
ErrLinkDown
...
...
@@ -727,7 +696,7 @@ func (c *Conn) errSendShutdown() error {
// NodeLink was closed/shutdowned itself - on actual IO problems corresponding
// error is delivered to particular Send that caused it.
case
atomic
.
LoadInt32
(
&
c
.
nodeL
ink
.
closed
)
!=
0
:
case
atomic
.
LoadInt32
(
&
c
.
l
ink
.
closed
)
!=
0
:
return
ErrLinkClosed
default
:
...
...
@@ -750,12 +719,12 @@ func (c *Conn) sendPkt2(pkt *PktBuf) error {
case
<-
c
.
txdown
:
return
c
.
errSendShutdown
()
case
c
.
nodeL
ink
.
txq
<-
txReq
{
pkt
,
c
.
txerr
}
:
case
c
.
l
ink
.
txq
<-
txReq
{
pkt
,
c
.
txerr
}
:
select
{
// tx request was sent to serveSend and is being transmitted on the wire.
// the transmission may block for indefinitely long though and
// we cannot interrupt it as the only way to interrupt is
// .
nodeL
ink.Close() which will close all other Conns.
// .
l
ink.Close() which will close all other Conns.
//
// That's why we are also checking for c.txdown while waiting
// for reply from serveSend (and leave pkt to finish transmitting).
...
...
@@ -1140,7 +1109,7 @@ func (nl *NodeLink) RemoteAddr() net.Addr {
// Link returns underlying NodeLink of this connection.
func
(
c
*
Conn
)
Link
()
*
NodeLink
{
return
c
.
nodeL
ink
return
c
.
l
ink
}
// ConnID returns connection identifier used for the connection.
...
...
@@ -1157,7 +1126,7 @@ func (nl *NodeLink) String() string {
}
func
(
c
*
Conn
)
String
()
string
{
s
:=
fmt
.
Sprintf
(
"%s .%d"
,
c
.
nodeL
ink
,
c
.
connId
)
s
:=
fmt
.
Sprintf
(
"%s .%d"
,
c
.
l
ink
,
c
.
connId
)
return
s
// XXX add "(closed)" if c is closed ?
}
...
...
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