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
3ef9b607
Commit
3ef9b607
authored
Feb 03, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
baf20c7d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
68 deletions
+99
-68
go/neo/xneo/connect.go
go/neo/xneo/connect.go
+99
-0
go/neo/xneo/xneo.go
go/neo/xneo/xneo.go
+0
-68
No files found.
go/neo/xneo/connect.go
0 → 100644
View file @
3ef9b607
// Copyright (C) 2016-2021 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
package
xneo
// dial/listen with request/accept identification
import
(
"context"
"fmt"
"net"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/neo/go/internal/xcontext"
"lab.nexedi.com/kirr/neo/go/neo/neonet"
"lab.nexedi.com/kirr/neo/go/neo/proto"
)
// Listener is LinkListener adapted to return NodeLink with requested identification on Accept.
type
Listener
interface
{
// from LinkListener:
Close
()
error
Addr
()
net
.
Addr
// Accept accepts incoming client connection.
//
// On success the link was handshaked and peer sent us RequestIdentification
// packet which we did not yet answer.
//
// On success returned are:
// - original peer request that carried identification
// - requested identification packet
//
// After successful accept it is the caller responsibility to reply the request.
//
// NOTE established link is Request.Link().
Accept
(
ctx
context
.
Context
)
(
*
neonet
.
Request
,
*
proto
.
RequestIdentification
,
error
)
}
// NewListener wraps inner LinkListener into Listener.
func
NewListener
(
inner
neonet
.
LinkListener
)
Listener
{
return
&
listener
{
l
:
inner
}
}
type
listener
struct
{
l
neonet
.
LinkListener
}
func
(
l
*
listener
)
Accept
(
ctx
context
.
Context
)
(
_
*
neonet
.
Request
,
msgID
*
proto
.
RequestIdentification
,
err
error
)
{
link
,
err
:=
l
.
l
.
Accept
(
ctx
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
// identify peer
// the first conn must come with RequestIdentification packet
defer
xerr
.
Context
(
&
err
,
"identify"
)
var
req
neonet
.
Request
err
=
xcontext
.
WithCloseOnErrCancel
(
ctx
,
link
,
func
()
error
{
var
err
error
req
,
err
=
link
.
Recv1
(
/*XXX ctx*/
)
if
err
!=
nil
{
return
err
}
switch
msg
:=
req
.
Msg
.
(
type
)
{
case
*
proto
.
RequestIdentification
:
msgID
=
msg
return
nil
}
emsg
:=
&
proto
.
Error
{
proto
.
PROTOCOL_ERROR
,
fmt
.
Sprintf
(
"unexpected message %T"
,
req
.
Msg
)}
req
.
Reply
(
emsg
)
// ignore err
return
emsg
})
if
err
!=
nil
{
return
nil
,
nil
,
err
}
return
&
req
,
msgID
,
err
}
func
(
l
*
listener
)
Close
()
error
{
return
l
.
l
.
Close
()
}
func
(
l
*
listener
)
Addr
()
net
.
Addr
{
return
l
.
l
.
Addr
()
}
go/neo/xneo/xneo.go
View file @
3ef9b607
...
@@ -25,7 +25,6 @@ package xneo
...
@@ -25,7 +25,6 @@ package xneo
import
(
import
(
"context"
"context"
"fmt"
"fmt"
"net"
"sync"
"sync"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/go123/xerr"
...
@@ -33,7 +32,6 @@ import (
...
@@ -33,7 +32,6 @@ import (
"lab.nexedi.com/kirr/neo/go/internal/log"
"lab.nexedi.com/kirr/neo/go/internal/log"
"lab.nexedi.com/kirr/neo/go/internal/task"
"lab.nexedi.com/kirr/neo/go/internal/task"
"lab.nexedi.com/kirr/neo/go/internal/xcontext"
"lab.nexedi.com/kirr/neo/go/internal/xio"
"lab.nexedi.com/kirr/neo/go/internal/xio"
"lab.nexedi.com/kirr/neo/go/neo/neonet"
"lab.nexedi.com/kirr/neo/go/neo/neonet"
...
@@ -168,72 +166,6 @@ func (node *Node) Dial(ctx context.Context, peerType proto.NodeType, addr string
...
@@ -168,72 +166,6 @@ func (node *Node) Dial(ctx context.Context, peerType proto.NodeType, addr string
}
}
// Listener is LinkListener adapted to return NodeLink with requested identification on Accept.
type
Listener
interface
{
// from LinkListener:
Close
()
error
Addr
()
net
.
Addr
// Accept accepts incoming client connection.
//
// On success the link was handshaked and peer sent us RequestIdentification
// packet which we did not yet answer.
//
// On success returned are:
// - original peer request that carried identification
// - requested identification packet
//
// After successful accept it is the caller responsibility to reply the request.
//
// NOTE established link is Request.Link().
Accept
(
ctx
context
.
Context
)
(
*
neonet
.
Request
,
*
proto
.
RequestIdentification
,
error
)
}
// NewListener wraps inner LinkListener into Listener.
func
NewListener
(
inner
neonet
.
LinkListener
)
Listener
{
return
&
listener
{
l
:
inner
}
}
type
listener
struct
{
l
neonet
.
LinkListener
}
func
(
l
*
listener
)
Accept
(
ctx
context
.
Context
)
(
_
*
neonet
.
Request
,
msgID
*
proto
.
RequestIdentification
,
err
error
)
{
link
,
err
:=
l
.
l
.
Accept
(
ctx
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
// identify peer
// the first conn must come with RequestIdentification packet
defer
xerr
.
Context
(
&
err
,
"identify"
)
var
req
neonet
.
Request
err
=
xcontext
.
WithCloseOnErrCancel
(
ctx
,
link
,
func
()
error
{
var
err
error
req
,
err
=
link
.
Recv1
(
/*XXX ctx*/
)
if
err
!=
nil
{
return
err
}
switch
msg
:=
req
.
Msg
.
(
type
)
{
case
*
proto
.
RequestIdentification
:
msgID
=
msg
return
nil
}
emsg
:=
&
proto
.
Error
{
proto
.
PROTOCOL_ERROR
,
fmt
.
Sprintf
(
"unexpected message %T"
,
req
.
Msg
)}
req
.
Reply
(
emsg
)
// ignore err
return
emsg
})
if
err
!=
nil
{
return
nil
,
nil
,
err
}
return
&
req
,
msgID
,
err
}
func
(
l
*
listener
)
Close
()
error
{
return
l
.
l
.
Close
()
}
func
(
l
*
listener
)
Addr
()
net
.
Addr
{
return
l
.
l
.
Addr
()
}
// ----------------------------------------
// ----------------------------------------
// UpdateNodeTab applies updates to .NodeTab from message and logs changes appropriately.
// UpdateNodeTab applies updates to .NodeTab from message and logs changes appropriately.
...
...
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