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) { ...@@ -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 { func (addr Address) String() string {
// XXX in py if .Host == "" -> whole Address is assumed to be empty // XXX in py if .Host == "" -> whole Address is assumed to be empty
// 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)) return net.JoinHostPort(addr.Host, fmt.Sprintf("%d", addr.Port))
}
} }
// ParseAddress parses networked address of form host:port into NEO Address // ParseAddress parses networked address (XXX of form host:port) into NEO Address
func ParseAddress(hostport string) (Address, error) { 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) host, portstr, err := net.SplitHostPort(hostport)
if err != nil { if err != nil {
return Address{}, err return Address{}, err
......
...@@ -36,9 +36,9 @@ import ( ...@@ -36,9 +36,9 @@ import (
const NetPrefix = "pipe" // pipenet package works only with "pipe*" networks const NetPrefix = "pipe" // pipenet package works only with "pipe*" networks
var ( var (
errBadNetwork = errors.New("pipenet: invalid network") // errBadNetwork = errors.New("pipenet: invalid network")
errBadAddress = errors.New("invalid address") errBadAddress = errors.New("invalid address")
errNetNotFound = errors.New("no such network") // errNetNotFound = errors.New("no such network")
errNetClosed = errors.New("network connection closed") errNetClosed = errors.New("network connection closed")
errAddrAlreadyUsed = errors.New("address already in use") errAddrAlreadyUsed = errors.New("address already in use")
errConnRefused = errors.New("connection refused") errConnRefused = errors.New("connection refused")
...@@ -52,8 +52,6 @@ type Addr struct { ...@@ -52,8 +52,6 @@ type Addr struct {
// Network implements synchronous in-memory network of pipes // 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/... // 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 { type Network struct {
// name of this network under "pipe" namespace -> e.g. "" // name of this network under "pipe" namespace -> e.g. ""
// full network name will be reported as "pipe"+Name XXX -> just full name ? // 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) { ...@@ -167,7 +165,7 @@ func (n *Network) Listen(laddr string) (net.Listener, error) {
if laddr != "" { if laddr != "" {
port, err := strconv.Atoi(laddr) port, err := strconv.Atoi(laddr)
if err != nil || port < 0 { 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) { ...@@ -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) { func (n *Network) Dial(ctx context.Context, addr string) (net.Conn, error) {
derr := func(err error) error { derr := func(err error) error {
return &net.OpError{Op: "dial", Net: n.netname(), Addr: &Addr{n.netname(), addr}, Err: err} 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) { ...@@ -240,7 +239,7 @@ func (n *Network) Dial(ctx context.Context, addr string) (net.Conn, error) {
port, err := strconv.Atoi(addr) port, err := strconv.Atoi(addr)
if err != nil || port < 0 { if err != nil || port < 0 {
return nil, derr(errBadAddress) return nil, derr(errBadAddress) // XXX -> net.AddrError ?
} }
n.mu.Lock() n.mu.Lock()
...@@ -323,6 +322,7 @@ func (c *conn) RemoteAddr() net.Addr { ...@@ -323,6 +322,7 @@ func (c *conn) RemoteAddr() net.Addr {
// ---------------------------------------- // ----------------------------------------
/*
var ( var (
netMu sync.Mutex netMu sync.Mutex
networks = map[string]*Network{} // netSuffix -> Network networks = map[string]*Network{} // netSuffix -> Network
...@@ -385,3 +385,4 @@ func Listen(network, laddr string) (net.Listener, error) { ...@@ -385,3 +385,4 @@ func Listen(network, laddr string) (net.Listener, error) {
return n.Listen(laddr) 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