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
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
41d5c439
Commit
41d5c439
authored
May 14, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
610ac0f7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
28 deletions
+87
-28
go/xcommon/xnet/lonet/lonet.go
go/xcommon/xnet/lonet/lonet.go
+87
-28
No files found.
go/xcommon/xnet/lonet/lonet.go
View file @
41d5c439
...
...
@@ -72,14 +72,17 @@ import (
"net"
"os"
"path/filepath"
"strconv"
"sync"
"lab.nexedi.com/kirr/go123/xerr"
//
"lab.nexedi.com/kirr/go123/xnet"
"lab.nexedi.com/kirr/go123/xnet"
)
const
NetPrefix
=
"lonet"
// lonet package creates only "lonet*" networks
// XXX errors
// Addr represents address of a lonet endpoint.
type
Addr
struct
{
Net
string
// full network name, e.g. "lonet"
...
...
@@ -119,30 +122,40 @@ type Host struct {
socketv
[]
*
socket
// port -> listener | conn ; [0] is always nil
}
// XXX reenable
//var _ xnet.Networker = (*Host)(nil)
var
_
xnet
.
Networker
=
(
*
Host
)(
nil
)
// socket represents one endpoint entry on Network XXX
// it can be either already connected or listening
// socket represents one endpoint entry on Host.
//
// it can be either already connected or listening.
type
socket
struct
{
host
*
Host
// host/port this socket is bound to
port
int
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 XXX
// conn represents one endpoint of connection created under
lonet network.
type
conn
struct
{
socket
*
socket
peer
sk
*
socket
// the other
side of this connection
socket
*
socket
// local
socket
peer
Addr
*
Addr
// lonet address of the remote
side of this connection
net
.
Conn
closeOnce
sync
.
Once
}
// XXX listener
// listener implements net.Listener for Host.
type
listener
struct
{
// subnetwork/host/port we are listening on
socket
*
socket
// dialq chan dialReq // Dial requests to our port go here
down
chan
struct
{}
// Close -> down=ready
closeOnce
sync
.
Once
}
// XXX dialReq
...
...
@@ -212,30 +225,76 @@ func (n *SubNetwork) NewHost(name string) (*Host, error) {
return
host
,
nil
}
// resolveAddr resolves addr on the network from the host point of view
// must be called with Network.mu held XXX
func
(
h
*
Host
)
resolveAddr
(
addr
string
)
(
host
*
Host
,
port
int
,
err
error
)
{
// XXX Host.resolveAddr
// XXX
func
(
h
*
Host
)
Listen
(
laddr
string
)
(
net
.
Listener
,
error
)
{
panic
(
"TODO"
)
/*
a, err := h.network.ParseAddr(addr)
if err != nil {
return nil, 0, err
}
}
// local host if host name omitted
if a.Host == ""
{
a.Host = h.name
}
// XXX
func
(
h
*
Host
)
Dial
(
ctx
context
.
Context
,
addr
string
)
(
net
.
Conn
,
error
)
{
panic
(
"TODO"
)
}
host = h.network.hostMap[a.Host]
if host == nil {
return nil, 0, &net.AddrError{Err: "no such host", Addr: addr}
}
// Close closes network endpoint and unregisters conn from Host.
//
// All currently in-flight blocked IO is interrupted with an error
func
(
c
*
conn
)
Close
()
(
err
error
)
{
c
.
closeOnce
.
Do
(
func
()
{
err
=
c
.
Conn
.
Close
()
sk
:=
c
.
socket
h
:=
sk
.
host
n
:=
h
.
subnet
n
.
mu
.
Lock
()
defer
n
.
mu
.
Unlock
()
sk
.
conn
=
nil
if
sk
.
empty
()
{
h
.
socketv
[
sk
.
port
]
=
nil
}
})
return
err
}
// LocalAddr returns address of local end of connection.
func
(
c
*
conn
)
LocalAddr
()
net
.
Addr
{
return
c
.
socket
.
addr
()
}
// RemoteAddr returns address of remote end of connection.
func
(
c
*
conn
)
RemoteAddr
()
net
.
Addr
{
return
c
.
peerAddr
}
// ----------------------------------------
return host, a.Port, nil
*/
// XXX Host.allocFreeSocket
// empty checks whether socket's both conn and listener are all nil.
// XXX recheck we really need this.
func
(
sk
*
socket
)
empty
()
bool
{
return
sk
.
conn
==
nil
&&
sk
.
listener
==
nil
}
// addr returns address corresponding to socket.
func
(
sk
*
socket
)
addr
()
*
Addr
{
h
:=
sk
.
host
return
&
Addr
{
Net
:
h
.
Network
(),
Host
:
h
.
name
,
Port
:
sk
.
port
}
}
func
(
a
*
Addr
)
Network
()
string
{
return
a
.
Net
}
func
(
a
*
Addr
)
String
()
string
{
return
net
.
JoinHostPort
(
a
.
Host
,
strconv
.
Itoa
(
a
.
Port
))
}
// XXX ParseAddr
// Addr returns address where listener is accepting incoming connections.
func
(
l
*
listener
)
Addr
()
net
.
Addr
{
return
l
.
socket
.
addr
()
}
// Network returns full network name this subnetwork is part of.
func
(
n
*
SubNetwork
)
Network
()
string
{
return
NetPrefix
+
n
.
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