Commit 610ac0f7 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 1f8e5840
...@@ -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"+name. // full network name will be reported as "lonet"+network.
name string network 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.
// //
// Name is name of this network under "lonet" namespace, e.g. "α" will give // Network is the name of this network under "lonet" namespace, e.g. "α" will
// full network name "lonetα". // give full network name "lonetα".
// //
// If name is "" new network with random unique name will be created. // If network 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 segment is part of. // Network returns full network name this subnetwork is part of.
func (n *SubNetwork) Network() string { return NetPrefix + n.name } func (n *SubNetwork) Network() string { return NetPrefix + n.network }
// 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() }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment