Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
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
Levin Zimmermann
neoppod
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 @@
...
@@ -67,9 +67,14 @@
package
lonet
package
lonet
import
(
import
(
"context"
"io/ioutil"
"net"
"net"
"os"
"path/filepath"
"sync"
"sync"
"lab.nexedi.com/kirr/go123/xerr"
//"lab.nexedi.com/kirr/go123/xnet"
//"lab.nexedi.com/kirr/go123/xnet"
)
)
...
@@ -92,8 +97,8 @@ type Addr struct {
...
@@ -92,8 +97,8 @@ type Addr struct {
// XXX text
// XXX text
type
SubNetwork
struct
{
type
SubNetwork
struct
{
// name of full network under "lonet" namespace -> e.g. ""
// name of full network under "lonet" namespace -> e.g. ""
// full network name will be reported as "lonet"+n
ame
.
// full network name will be reported as "lonet"+n
etwork
.
n
ame
string
n
etwork
string
// registry of whole lonet network
// registry of whole lonet network
registry
registry
registry
registry
...
@@ -145,20 +150,46 @@ type conn struct {
...
@@ -145,20 +150,46 @@ type conn struct {
// Join joins or creates new lonet network with given name.
// Join joins or creates new lonet network with given name.
//
//
// N
ame is name of this network under "lonet" namespace, e.g. "α" will give
// N
etwork is the name of this network under "lonet" namespace, e.g. "α" will
// full network name "lonetα".
//
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.
// Join returns new subnetwork on the joined network.
//
func
Join
(
ctx
context
.
Context
,
network
string
)
(
_
*
SubNetwork
,
err
error
)
{
// XXX
defer
xerr
.
Contextf
(
&
err
,
"lonet: join %q"
,
network
)
func
Join
(
name
string
)
(
*
SubNetwork
,
error
)
{
// TODO create/join registry under /tmp/lonet/XXX/registry.db
// create/join registry under /tmp/lonet/<network>/registry.db
var
registry
registry
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.
// joined ok
return
&
SubNetwork
{
name
:
name
,
registry
:
registry
,
hostMap
:
make
(
map
[
string
]
*
Host
)},
nil
return
&
SubNetwork
{
network
:
network
,
registry
:
registry
,
hostMap
:
make
(
map
[
string
]
*
Host
),
},
nil
}
}
// NewHost creates new lonet network access point with given name.
// 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) {
...
@@ -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.
// Network returns full network name this s
ubnetwork
is part of.
func
(
n
*
SubNetwork
)
Network
()
string
{
return
NetPrefix
+
n
.
n
ame
}
func
(
n
*
SubNetwork
)
Network
()
string
{
return
NetPrefix
+
n
.
n
etwork
}
// Network returns full network name of underlying network.
// Network returns full network name of underlying network.
func
(
h
*
Host
)
Network
()
string
{
return
h
.
subnet
.
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