Commit 99b8a6f4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 0a6642af
......@@ -98,14 +98,28 @@ func (n *netTLS) Listen(laddr string) (net.Listener, error) {
// ----------------------------------------
// String formats Address to canonical host:port form
// String formats Address to networked address string
func (addr Address) String() string {
// XXX in py if .Host == "" -> whole Address is assumed to be empty
return net.JoinHostPort(addr.Host, fmt.Sprintf("%d", addr.Port))
// e.g. on unix, pipenet, etc there is no host/port split - the address
// is single string which we put into .Host and set .Port=0
switch addr.Port {
case 0:
return addr.Host
default:
return net.JoinHostPort(addr.Host, fmt.Sprintf("%d", addr.Port))
}
}
// ParseAddress parses networked address of form host:port into NEO Address
func ParseAddress(hostport string) (Address, error) {
// ParseAddress parses networked address (XXX of form host:port) into NEO Address
func ParseAddress(addr string) (Address, error) {
// e.g. on unix, pipenet, etc there is no host/port split - the address
// is single string which we put into .Host and set .Port=0
// TODO detect :port presence ?
// XXX pass net.Addr() here instead of string?
host, portstr, err := net.SplitHostPort(hostport)
if err != nil {
return Address{}, err
......
......@@ -36,9 +36,9 @@ import (
const NetPrefix = "pipe" // pipenet package works only with "pipe*" networks
var (
errBadNetwork = errors.New("pipenet: invalid network")
// errBadNetwork = errors.New("pipenet: invalid network")
errBadAddress = errors.New("invalid address")
errNetNotFound = errors.New("no such network")
// errNetNotFound = errors.New("no such network")
errNetClosed = errors.New("network connection closed")
errAddrAlreadyUsed = errors.New("address already in use")
errConnRefused = errors.New("connection refused")
......@@ -52,8 +52,6 @@ type Addr struct {
// Network implements synchronous in-memory network of pipes
// It can be worked with the same way a regular TCP network is handled with Dial/Listen/Accept/...
//
// Network must be created with New XXX is it really ok to have global state ?
type Network struct {
// name of this network under "pipe" namespace -> e.g. ""
// full network name will be reported as "pipe"+Name XXX -> just full name ?
......@@ -167,7 +165,7 @@ func (n *Network) Listen(laddr string) (net.Listener, error) {
if laddr != "" {
port, err := strconv.Atoi(laddr)
if err != nil || port < 0 {
return nil, lerr(errBadAddress)
return nil, lerr(errBadAddress) // XXX -> net.AddrError ?
}
}
......@@ -232,7 +230,8 @@ func (l *listener) Accept() (net.Conn, error) {
}
}
// Dial tries to connect to Accept called on listener corresponding to addr
// Dial dials address on the network
// It tries to connect to Accept called on listener corresponding to addr.
func (n *Network) Dial(ctx context.Context, addr string) (net.Conn, error) {
derr := func(err error) error {
return &net.OpError{Op: "dial", Net: n.netname(), Addr: &Addr{n.netname(), addr}, Err: err}
......@@ -240,7 +239,7 @@ func (n *Network) Dial(ctx context.Context, addr string) (net.Conn, error) {
port, err := strconv.Atoi(addr)
if err != nil || port < 0 {
return nil, derr(errBadAddress)
return nil, derr(errBadAddress) // XXX -> net.AddrError ?
}
n.mu.Lock()
......@@ -323,6 +322,7 @@ func (c *conn) RemoteAddr() net.Addr {
// ----------------------------------------
/*
var (
netMu sync.Mutex
networks = map[string]*Network{} // netSuffix -> Network
......@@ -385,3 +385,4 @@ func Listen(network, laddr string) (net.Listener, error) {
return n.Listen(laddr)
}
*/
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