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
610ac0f7
Commit
610ac0f7
authored
May 11, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
1f8e5840
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
14 deletions
+45
-14
go/xcommon/xnet/lonet/lonet.go
go/xcommon/xnet/lonet/lonet.go
+45
-14
No files found.
go/xcommon/xnet/lonet/lonet.go
View file @
610ac0f7
...
...
@@ -67,9 +67,14 @@
package
lonet
import
(
"context"
"io/ioutil"
"net"
"os"
"path/filepath"
"sync"
"lab.nexedi.com/kirr/go123/xerr"
//"lab.nexedi.com/kirr/go123/xnet"
)
...
...
@@ -92,8 +97,8 @@ type Addr struct {
// XXX text
type
SubNetwork
struct
{
// name of full network under "lonet" namespace -> e.g. ""
// full network name will be reported as "lonet"+n
ame
.
n
ame
string
// full network name will be reported as "lonet"+n
etwork
.
n
etwork
string
// registry of whole lonet network
registry
registry
...
...
@@ -145,20 +150,46 @@ type conn struct {
// Join joins or creates new lonet network with given name.
//
// N
ame is name of this network under "lonet" namespace, e.g. "α" will give
// full network name "lonetα".
// N
etwork is the name of this network under "lonet" namespace, e.g. "α" will
//
give
full network name "lonetα".
//
// If n
ame
is "" new network with random unique name will be created.
// If n
etwork
is "" new network with random unique name will be created.
//
// Join returns new subnetwork on the joined network.
//
// XXX
func
Join
(
name
string
)
(
*
SubNetwork
,
error
)
{
// TODO create/join registry under /tmp/lonet/XXX/registry.db
var
registry
registry
func
Join
(
ctx
context
.
Context
,
network
string
)
(
_
*
SubNetwork
,
err
error
)
{
defer
xerr
.
Contextf
(
&
err
,
"lonet: join %q"
,
network
)
// create/join registry under /tmp/lonet/<network>/registry.db
lonet
:=
os
.
TempDir
()
+
"/lonet"
err
=
os
.
MkdirAll
(
lonet
,
0777
|
os
.
ModeSticky
)
if
err
!=
nil
{
return
nil
,
err
}
var
netdir
string
if
network
!=
""
{
netdir
=
lonet
+
"/"
+
network
err
=
os
.
MkdirAll
(
netdir
,
0700
)
}
else
{
// new with random name
netdir
,
err
=
ioutil
.
TempDir
(
lonet
,
""
)
network
=
filepath
.
Base
(
netdir
)
}
if
err
!=
nil
{
return
nil
,
err
}
registry
,
err
:=
openRegistrySQLite
(
ctx
,
netdir
+
"/registry.db"
,
network
)
if
err
!=
nil
{
return
nil
,
err
}
// XXX "" -> create new with temp name.
return
&
SubNetwork
{
name
:
name
,
registry
:
registry
,
hostMap
:
make
(
map
[
string
]
*
Host
)},
nil
// joined ok
return
&
SubNetwork
{
network
:
network
,
registry
:
registry
,
hostMap
:
make
(
map
[
string
]
*
Host
),
},
nil
}
// NewHost creates new lonet network access point with given name.
...
...
@@ -206,8 +237,8 @@ func (h *Host) resolveAddr(addr string) (host *Host, port int, err error) {
}
// Network returns full network name this s
egment
is part of.
func
(
n
*
SubNetwork
)
Network
()
string
{
return
NetPrefix
+
n
.
n
ame
}
// Network returns full network name this s
ubnetwork
is part of.
func
(
n
*
SubNetwork
)
Network
()
string
{
return
NetPrefix
+
n
.
n
etwork
}
// Network returns full network name of underlying network.
func
(
h
*
Host
)
Network
()
string
{
return
h
.
subnet
.
Network
()
}
...
...
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