Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefane Fermigier
neo
Commits
99b8a6f4
Commit
99b8a6f4
authored
Jun 08, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
0a6642af
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
11 deletions
+26
-11
go/neo/net.go
go/neo/net.go
+18
-4
go/xcommon/pipenet/pipenet.go
go/xcommon/pipenet/pipenet.go
+8
-7
No files found.
go/neo/net.go
View file @
99b8a6f4
...
...
@@ -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
...
...
go/xcommon/pipenet/pipenet.go
View file @
99b8a6f4
...
...
@@ -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)
}
*/
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