Commit 2321a430 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 41d5c439
...@@ -106,11 +106,16 @@ type SubNetwork struct { ...@@ -106,11 +106,16 @@ type SubNetwork struct {
// registry of whole lonet network // registry of whole lonet network
registry registry registry registry
// OS-level listener of this subnetwork.
// whenever connection to subnet's host is tried to be established it goes here.
oslistener net.Listener
// big network lock for everything dynamic under SubNetwork // 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 // XXX lonet: not needed (registry instead)
// XXX track all hosts so SubNetwork.Shutdown shuts them down?
} }
// Host represents named access point on Network XXX // Host represents named access point on Network XXX
...@@ -197,32 +202,38 @@ func Join(ctx context.Context, network string) (_ *SubNetwork, err error) { ...@@ -197,32 +202,38 @@ func Join(ctx context.Context, network string) (_ *SubNetwork, err error) {
return nil, err return nil, err
} }
// start OS listener
oslistener, err := net.Listen("tcp4", "127.0.0.1:")
if err != nil {
registry.Close() // XXX lclose?
return nil, err
}
// joined ok // joined ok
return &SubNetwork{ return &SubNetwork{
network: network, network: network,
registry: registry, registry: registry,
hostMap: make(map[string]*Host), oslistener: oslistener,
// hostMap: make(map[string]*Host),
}, nil }, nil
} }
// NewHost creates new lonet network access point with given name. // NewHost creates new lonet Host with given name.
// //
// Serving of created host will be done though SubNetwork via which it was // Serving of created host will be done though SubNetwork via which it was
// created. XXX // created. XXX
// //
// XXX errors // XXX errors
func (n *SubNetwork) NewHost(name string) (*Host, error) { // errHostDup if host name was already registered.
// XXX redo for lonet func (n *SubNetwork) NewHost(ctx context.Context, name string) (*Host, error) {
n.mu.Lock() // announce host name to registry
defer n.mu.Unlock() err := n.registry.Announce(ctx, name, n.oslistener.Addr().String())
if err != nil {
host := n.hostMap[name] return nil, err // registry error has enough context
if host == nil {
host = &Host{subnet: n, name: name}
n.hostMap[name] = host
} }
return host, nil // announced ok -> host can be created
return &Host{subnet: n, name: name}, nil
} }
// XXX Host.resolveAddr // XXX Host.resolveAddr
......
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