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
1f8e5840
Commit
1f8e5840
authored
May 11, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
1f33a2f0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
25 deletions
+77
-25
go/xcommon/xnet/lonet/lonet.go
go/xcommon/xnet/lonet/lonet.go
+67
-25
go/xcommon/xnet/lonet/lonet.py
go/xcommon/xnet/lonet/lonet.py
+10
-0
No files found.
go/xcommon/xnet/lonet/lonet.go
View file @
1f8e5840
...
@@ -66,7 +66,13 @@
...
@@ -66,7 +66,13 @@
// See also shipped lonet.py for accessing lonet networks from Python.
// See also shipped lonet.py for accessing lonet networks from Python.
package
lonet
package
lonet
/*
import
(
"net"
"sync"
//"lab.nexedi.com/kirr/go123/xnet"
)
const
NetPrefix
=
"lonet"
// lonet package creates only "lonet*" networks
const
NetPrefix
=
"lonet"
// lonet package creates only "lonet*" networks
// Addr represents address of a lonet endpoint.
// Addr represents address of a lonet endpoint.
...
@@ -76,41 +82,52 @@ type Addr struct {
...
@@ -76,41 +82,52 @@ type Addr struct {
Port
int
// port on host
Port
int
// port on host
}
}
// Network implements ... XXX
// SubNetwork represents one segment of a lonet network.
type Network struct {
//
// name of this network under "lonet" namespace -> e.g. ""
// Multiple Hosts could be created on one segment.
// full network name will be reported as "lonet"+name
// There can be other network segments in the same process or in another OS-level processes.
//
// Host names are unique through whole lonet network.
//
// XXX text
type
SubNetwork
struct
{
// name of full network under "lonet" namespace -> e.g. ""
// full network name will be reported as "lonet"+name.
name
string
name
string
// big network lock for everything dynamic under Network
// registry of whole lonet network
registry
registry
// big network lock for everything dynamic under SubNetwork
// (e.g. Host.socketv too) XXX
// (e.g. Host.socketv too) XXX
mu
sync
.
Mutex
mu
sync
.
Mutex
hostMap
map
[
string
]
*
Host
hostMap
map
[
string
]
*
Host
}
}
// Host represents named access point on Network
// Host represents named access point on Network
XXX
type
Host
struct
{
type
Host
struct
{
network *
Network
subnet
*
Sub
Network
name
string
name
string
// NOTE protected by
Network.mu
// NOTE protected by
subnet.mu XXX
socketv
[]
*
socket
// port -> listener | conn ; [0] is always nil
socketv
[]
*
socket
// port -> listener | conn ; [0] is always nil
}
}
var _ xnet.Networker = (*Host)(nil)
// XXX reenable
//var _ xnet.Networker = (*Host)(nil)
// socket represents one endpoint entry on Network
// socket represents one endpoint entry on Network
XXX
// it can be either already connected or listening
// it can be either already connected or listening
type
socket
struct
{
type
socket
struct
{
host
*
Host
// host/port this socket is bound to
host
*
Host
// host/port this socket is bound to
port
int
port
int
conn
*
conn
// connection endpoint is here if != nil
conn
*
conn
// connection endpoint is here if != nil
listener *listener // listener is waiting here if != nil
//
listener *listener // listener is waiting here if != nil
}
}
// conn represents one endpoint of connection created under Network
// conn represents one endpoint of connection created under Network
XXX
type
conn
struct
{
type
conn
struct
{
socket
*
socket
socket
*
socket
peersk
*
socket
// the other side of this connection
peersk
*
socket
// the other side of this connection
...
@@ -126,34 +143,49 @@ type conn struct {
...
@@ -126,34 +143,49 @@ type conn struct {
// ----------------------------------------
// ----------------------------------------
// New creates new lonet Network.
// Join joins or creates new lonet network with given name.
//
// Name is name of this network under "lonet" namespace, e.g. "α" will give
// full network name "lonetα".
//
// If name is "" new network with random unique name will be created.
//
//
//
name is name of this network under "lonet" namespace, e.g. "α" will give full network name "lonetα"
.
//
Join returns new subnetwork on the joined network
.
//
//
// New does not check whether network name provided is unique.
// XXX
func New(name string) *Network {
func
Join
(
name
string
)
(
*
SubNetwork
,
error
)
{
return &Network{name: name, hostMap: make(map[string]*Host)}
// TODO create/join registry under /tmp/lonet/XXX/registry.db
var
registry
registry
// XXX "" -> create new with temp name.
return
&
SubNetwork
{
name
:
name
,
registry
:
registry
,
hostMap
:
make
(
map
[
string
]
*
Host
)},
nil
}
}
// Host returns network access point by name.
// NewHost creates new lonet network access point with given name.
//
// Serving of created host will be done though SubNetwork via which it was
// created. XXX
//
//
// If there was no such host before it creates new one.
// XXX errors
func (n *Network) Host(name string) *Host {
func
(
n
*
SubNetwork
)
NewHost
(
name
string
)
(
*
Host
,
error
)
{
// XXX redo for lonet
n
.
mu
.
Lock
()
n
.
mu
.
Lock
()
defer
n
.
mu
.
Unlock
()
defer
n
.
mu
.
Unlock
()
host
:=
n
.
hostMap
[
name
]
host
:=
n
.
hostMap
[
name
]
if
host
==
nil
{
if
host
==
nil
{
host = &Host{
network
: n, name: name}
host
=
&
Host
{
subnet
:
n
,
name
:
name
}
n
.
hostMap
[
name
]
=
host
n
.
hostMap
[
name
]
=
host
}
}
return host
return
host
,
nil
}
}
// resolveAddr resolves addr on the network from the host point of view
// resolveAddr resolves addr on the network from the host point of view
// must be called with Network.mu held
// must be called with Network.mu held
XXX
func
(
h
*
Host
)
resolveAddr
(
addr
string
)
(
host
*
Host
,
port
int
,
err
error
)
{
func
(
h
*
Host
)
resolveAddr
(
addr
string
)
(
host
*
Host
,
port
int
,
err
error
)
{
panic
(
"TODO"
)
/*
a, err := h.network.ParseAddr(addr)
a, err := h.network.ParseAddr(addr)
if err != nil {
if err != nil {
return nil, 0, err
return nil, 0, err
...
@@ -170,5 +202,15 @@ func (h *Host) resolveAddr(addr string) (host *Host, port int, err error) {
...
@@ -170,5 +202,15 @@ func (h *Host) resolveAddr(addr string) (host *Host, port int, err error) {
}
}
return host, a.Port, nil
return host, a.Port, nil
}
*/
*/
}
// Network returns full network name this segment is part of.
func
(
n
*
SubNetwork
)
Network
()
string
{
return
NetPrefix
+
n
.
name
}
// Network returns full network name of underlying network.
func
(
h
*
Host
)
Network
()
string
{
return
h
.
subnet
.
Network
()
}
// Name returns host name.
func
(
h
*
Host
)
Name
()
string
{
return
h
.
name
}
go/xcommon/xnet/lonet/lonet.py
View file @
1f8e5840
...
@@ -18,3 +18,13 @@
...
@@ -18,3 +18,13 @@
# See https://www.nexedi.com/licensing for rationale and options.
# See https://www.nexedi.com/licensing for rationale and options.
# TODO doc, code
# TODO doc, code
class
SQLiteRegistry
(
object
):
def
__init__
(
self
,
dburi
,
network
):
# XXX open
self
.
setup
(
network
)
# TODO
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