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
ba788667
Commit
ba788667
authored
May 15, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
bbad4198
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
23 deletions
+56
-23
go/xcommon/xnet/lonet/lonet.go
go/xcommon/xnet/lonet/lonet.go
+48
-21
go/xcommon/xnet/lonet/lonet_test.go
go/xcommon/xnet/lonet/lonet_test.go
+6
-0
go/xcommon/xnet/lonet/registry.go
go/xcommon/xnet/lonet/registry.go
+2
-2
No files found.
go/xcommon/xnet/lonet/lonet.go
View file @
ba788667
...
...
@@ -41,21 +41,18 @@
// to 127.0.0.1:4567 and 127.0.0.1:8765, and once lonet connection is
// established it becomes served by OS-level TCP connection over loopback.
//
// XXX several networks = possible. (or document in New?)
//
// Example: TODO adjust
// Example:
//
// net, err := lonet.Join(ctx, "mynet")
// h
1, err := net.NewHost("abc
")
// h
2, err := net.NewHost("def") // ...
// h
α, err := net.NewHost(ctx, "α
")
// h
β, err := net.NewHost(ctx, "β")
//
// // XXX inject 127.0.0.1 to example...
// // starts listening on address "abc:10" (which gets mapped to "127.0.0.1:xxx")
// l, err := h1.Listen(":10")
// // starts listening on address "α:10"
// l, err := hα.Listen(":10")
// go func() {
// csrv, err := l.Accept()
// csrv will have LocalAddr "abc:10
"
// csrv, err := l.Accept()
// csrv will have LocalAddr "α:11
"
// }()
// ccli, err := h
2.Dial("abc:10") // ccli will have RemoteAddr "def:10
"
// ccli, err := h
β.Dial(ctx, "α:10") // ccli will be connection between "β:1" - "α:11
"
//
// Once again lonet is similar to pipenet, but since it works via OS TCP stack
// it could be handy for testing networked application when there are several
...
...
@@ -64,17 +61,47 @@
// See also shipped lonet.py for accessing lonet networks from Python.
package
lonet
// XXX document lonet organization, protocol
// > lonet "network" dial <src> <dst>
// < lonet "network" connected <dst'>
// E connrefused
// lonet organization
//
// For every lonet network there is a registry with information about hosts
// available on the network, and for each host its OS-level listening address.
// The registry is kept as SQLite database under
//
// /<tmp>/lonet/<network>/registry.db
//
// Whenever host α needs to establish connection to address on host β, it
// queries the registry for β and further talks to β on that address.
// Correspondingly when a host joins the network, it announces itself to the
// registry so that other hosts could see it.
//
//
// handshake protocol
//
// After α establishes OS-level connection to β via main β port, it sends
// request to further establish lonet connection on top of that:
//
// > lonet "<network>" dial <α:portα> <β:portβ> \n
//
// β checks whether portβ is listening, and if yes, accepts the connection on
// corresponding on-β listener with giving feedback to α that connection was
// accepted:
//
// < lonet "<network>" connected <β:portβ'> \n
//
// After that connection is considered to be lonet-established and all further
// exchange on it is directly controlled by corresponding lonet-level
// Read/Write on α and β.
//
// If, on the other hand, lonet-level connection cannot be established, β replies:
//
// < lonet "<networkβ>" E "<error>" \n
//
//
E wrong network|op|...
//
where <error> could be:
//
// - protocol error
// - wrong network
// - wrong op
// - connrefused if <β:portβ> is not listening
// - network mismatch if β thinks it works on different lonet network than α
// - protocol error if β thinks that α send incorrect dial request
// - ...
import
(
"context"
...
...
@@ -298,7 +325,7 @@ func (n *SubNetwork) serve() { // XXX error?
// loaccept handles incoming OS-level connection.
//
// it performs lonet protocol handshake and if successful
l
further conveys
// it performs lonet protocol handshake and if successful further conveys
// accepted connection to lonet-level Accept.
func
(
n
*
SubNetwork
)
loaccept
(
osconn
net
.
Conn
)
(
err
error
)
{
defer
xerr
.
Contextf
(
&
err
,
"lonet %q: handshake"
,
n
.
network
)
...
...
@@ -311,7 +338,7 @@ func (n *SubNetwork) loaccept(osconn net.Conn) (err error) {
}
var
network
,
src
,
dst
string
_
,
err
=
fmt
.
Sscanf
(
line
,
"lonet %q dial %s %s
\n
"
,
&
network
,
&
src
,
&
dst
)
_
,
err
=
fmt
.
Sscanf
(
line
,
"
>
lonet %q dial %s %s
\n
"
,
&
network
,
&
src
,
&
dst
)
if
err
!=
nil
{
ereply
(
"protocol error"
)
return
err
...
...
go/xcommon/xnet/lonet/lonet_test.go
View file @
ba788667
...
...
@@ -21,3 +21,9 @@ package lonet
// TODO test go-go
// TODO test go-py
// XXX handshake:
// - ok,
// - econnrefused (no such host, port not listening)
// - network mismatch
// - invalid request
go/xcommon/xnet/lonet/registry.go
View file @
ba788667
...
...
@@ -28,8 +28,8 @@ import (
// registry represents access to lonet network registry.
//
// The registry holds information about hosts available on the network and
// for each host its OS listening address. Whenever host α needs to establish
// The registry holds information about hosts available on the network
,
and
// for each host its OS listening address. Whenever host α needs to establish
XXX dup with lonet.go
// connection to address on host β, it queries the registry for β and further
// talks to β on that address. Correspondingly when a host joins the network,
// it announces itself to the registry so that other hosts could see it.
...
...
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