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
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
b13e8150
Commit
b13e8150
authored
Jun 09, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
9e223d74
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
21 deletions
+35
-21
go/neo/net.go
go/neo/net.go
+26
-12
go/neo/server/storage.go
go/neo/server/storage.go
+3
-3
go/xcommon/pipenet/pipenet.go
go/xcommon/pipenet/pipenet.go
+6
-6
No files found.
go/neo/net.go
View file @
b13e8150
...
@@ -23,6 +23,7 @@ import (
...
@@ -23,6 +23,7 @@ import (
"fmt"
"fmt"
"net"
"net"
"strconv"
"strconv"
"strings"
"crypto/tls"
"crypto/tls"
"../xcommon/pipenet"
"../xcommon/pipenet"
...
@@ -35,6 +36,9 @@ import (
...
@@ -35,6 +36,9 @@ import (
// connections, and 2) dial peers. For this reason the interface is not split
// connections, and 2) dial peers. For this reason the interface is not split
// into Dialer and Listener.
// into Dialer and Listener.
type
Network
interface
{
type
Network
interface
{
// Network returns name of the network
Network
()
string
// Dial connects to addr on underlying network
// Dial connects to addr on underlying network
// see net.Dial for semantic details
// see net.Dial for semantic details
Dial
(
ctx
context
.
Context
,
addr
string
)
(
net
.
Conn
,
error
)
Dial
(
ctx
context
.
Context
,
addr
string
)
(
net
.
Conn
,
error
)
...
@@ -53,6 +57,10 @@ func NetPlain(network string) Network {
...
@@ -53,6 +57,10 @@ func NetPlain(network string) Network {
type
netPlain
string
type
netPlain
string
func
(
n
netPlain
)
Network
()
string
{
return
string
(
n
)
}
func
(
n
netPlain
)
Dial
(
ctx
context
.
Context
,
addr
string
)
(
net
.
Conn
,
error
)
{
func
(
n
netPlain
)
Dial
(
ctx
context
.
Context
,
addr
string
)
(
net
.
Conn
,
error
)
{
d
:=
net
.
Dialer
{}
d
:=
net
.
Dialer
{}
return
d
.
DialContext
(
ctx
,
string
(
n
),
addr
)
return
d
.
DialContext
(
ctx
,
string
(
n
),
addr
)
...
@@ -80,6 +88,10 @@ type netTLS struct {
...
@@ -80,6 +88,10 @@ type netTLS struct {
config
*
tls
.
Config
config
*
tls
.
Config
}
}
func
(
n
*
netTLS
)
Network
()
string
{
return
n
.
inner
.
Network
()
+
"+tls"
// XXX is this a good idea?
}
func
(
n
*
netTLS
)
Dial
(
ctx
context
.
Context
,
addr
string
)
(
net
.
Conn
,
error
)
{
func
(
n
*
netTLS
)
Dial
(
ctx
context
.
Context
,
addr
string
)
(
net
.
Conn
,
error
)
{
c
,
err
:=
n
.
inner
.
Dial
(
ctx
,
addr
)
c
,
err
:=
n
.
inner
.
Dial
(
ctx
,
addr
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -98,31 +110,33 @@ func (n *netTLS) Listen(laddr string) (net.Listener, error) {
...
@@ -98,31 +110,33 @@ func (n *netTLS) Listen(laddr string) (net.Listener, error) {
// ----------------------------------------
// ----------------------------------------
// Addr converts net
.Addr
into NEO Address
// Addr converts net
work address string
into NEO Address
// TODO make neo.Address just string without host:port split
// TODO make neo.Address just string without host:port split
func
Addr
(
addr
net
.
Addr
)
(
Address
,
error
)
{
func
AddrString
(
network
,
addr
string
)
(
Address
,
error
)
{
addrstr
:=
addr
.
String
()
// e.g. on unix, pipenet, etc networks there is no host/port split - the address there
// e.g. on unix, pipenet, etc networks there is no host/port split - the address there
// is single string -> we put it into .Host and set .Port=0 to indicate such cases
// is single string -> we put it into .Host and set .Port=0 to indicate such cases
switch
addr
.
Network
()
{
if
strings
.
HasPrefix
(
network
,
"tcp"
)
||
strings
.
HasPrefix
(
network
,
"udp"
)
{
default
:
return
Address
{
Host
:
addrstr
,
Port
:
0
},
nil
// networks that have host:port split
// networks that have host:port split
case
"tcp"
,
"tcp4"
,
"tcp6"
,
"udp"
,
"udp4"
,
"udp6"
:
host
,
portstr
,
err
:=
net
.
SplitHostPort
(
addr
)
host
,
portstr
,
err
:=
net
.
SplitHostPort
(
addrstr
)
if
err
!=
nil
{
if
err
!=
nil
{
return
Address
{},
err
return
Address
{},
err
}
}
// XXX also lookup portstr in /etc/services (net.LookupPort) ?
// XXX also lookup portstr in /etc/services (net.LookupPort) ?
port
,
err
:=
strconv
.
ParseUint
(
portstr
,
10
,
16
)
port
,
err
:=
strconv
.
ParseUint
(
portstr
,
10
,
16
)
if
err
!=
nil
{
if
err
!=
nil
{
return
Address
{},
&
net
.
AddrError
{
Err
:
"invalid port"
,
Addr
:
addr
str
}
return
Address
{},
&
net
.
AddrError
{
Err
:
"invalid port"
,
Addr
:
addr
}
}
}
return
Address
{
Host
:
host
,
Port
:
uint16
(
port
)},
nil
return
Address
{
Host
:
host
,
Port
:
uint16
(
port
)},
nil
}
}
return
Address
{
Host
:
addr
,
Port
:
0
},
nil
}
// Addr converts net.Addre into NEO Address
func
Addr
(
addr
net
.
Addr
)
(
Address
,
error
)
{
return
AddrString
(
addr
.
Network
(),
addr
.
String
())
}
}
// String formats Address to networked address string
// String formats Address to networked address string
...
...
go/neo/server/storage.go
View file @
b13e8150
...
@@ -37,7 +37,7 @@ type Storage struct {
...
@@ -37,7 +37,7 @@ type Storage struct {
clusterName
string
clusterName
string
net
neo
.
Network
// network we are sending/receiving on
net
neo
.
Network
// network we are sending/receiving on
masterAddr
string
// address of master
XXX -> Address ?
masterAddr
string
// address of master
// ---- 8< ----
// ---- 8< ----
zstor
zodb
.
IStorage
// underlying ZODB storage XXX temp ?
zstor
zodb
.
IStorage
// underlying ZODB storage XXX temp ?
...
@@ -48,7 +48,7 @@ type Storage struct {
...
@@ -48,7 +48,7 @@ type Storage struct {
// To actually start running the node - call Run. XXX text
// To actually start running the node - call Run. XXX text
func
NewStorage
(
cluster
string
,
masterAddr
string
,
serveAddr
string
,
net
neo
.
Network
,
zstor
zodb
.
IStorage
)
*
Storage
{
func
NewStorage
(
cluster
string
,
masterAddr
string
,
serveAddr
string
,
net
neo
.
Network
,
zstor
zodb
.
IStorage
)
*
Storage
{
// convert serveAddr into neo format
// convert serveAddr into neo format
addr
,
err
:=
neo
.
ParseAddress
(
serveAddr
)
addr
,
err
:=
neo
.
AddrString
(
net
.
Network
(),
serveAddr
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
// XXX
panic
(
err
)
// XXX
}
}
...
...
go/xcommon/pipenet/pipenet.go
View file @
b13e8150
...
@@ -122,7 +122,7 @@ func New(name string) *Network {
...
@@ -122,7 +122,7 @@ func New(name string) *Network {
// Connection requests created by Dials could be accepted via Accept.
// Connection requests created by Dials could be accepted via Accept.
func
(
n
*
Network
)
Listen
(
laddr
string
)
(
net
.
Listener
,
error
)
{
func
(
n
*
Network
)
Listen
(
laddr
string
)
(
net
.
Listener
,
error
)
{
lerr
:=
func
(
err
error
)
error
{
lerr
:=
func
(
err
error
)
error
{
return
&
net
.
OpError
{
Op
:
"listen"
,
Net
:
n
.
N
ame
(),
Addr
:
&
Addr
{
n
.
Name
(),
laddr
},
Err
:
err
}
return
&
net
.
OpError
{
Op
:
"listen"
,
Net
:
n
.
N
etwork
(),
Addr
:
&
Addr
{
n
.
Network
(),
laddr
},
Err
:
err
}
}
}
// laddr must be empty or int >= 0
// laddr must be empty or int >= 0
...
@@ -195,7 +195,7 @@ func (l *listener) Accept() (net.Conn, error) {
...
@@ -195,7 +195,7 @@ func (l *listener) Accept() (net.Conn, error) {
select
{
select
{
case
<-
l
.
down
:
case
<-
l
.
down
:
return
nil
,
&
net
.
OpError
{
Op
:
"accept"
,
Net
:
n
.
N
ame
(),
Addr
:
l
.
Addr
(),
Err
:
errNetClosed
}
return
nil
,
&
net
.
OpError
{
Op
:
"accept"
,
Net
:
n
.
N
etwork
(),
Addr
:
l
.
Addr
(),
Err
:
errNetClosed
}
case
resp
:=
<-
l
.
dialq
:
case
resp
:=
<-
l
.
dialq
:
// someone dialed us - let's connect
// someone dialed us - let's connect
...
@@ -219,7 +219,7 @@ func (l *listener) Accept() (net.Conn, error) {
...
@@ -219,7 +219,7 @@ func (l *listener) Accept() (net.Conn, error) {
// It tries to connect to Accept called on listener corresponding to addr.
// 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
.
N
ame
(),
Addr
:
&
Addr
{
n
.
Name
(),
addr
},
Err
:
err
}
return
&
net
.
OpError
{
Op
:
"dial"
,
Net
:
n
.
N
etwork
(),
Addr
:
&
Addr
{
n
.
Network
(),
addr
},
Err
:
err
}
}
}
port
,
err
:=
strconv
.
Atoi
(
addr
)
port
,
err
:=
strconv
.
Atoi
(
addr
)
...
@@ -328,7 +328,7 @@ func (e *entry) empty() bool {
...
@@ -328,7 +328,7 @@ func (e *entry) empty() bool {
// addr returns address corresponding to entry
// addr returns address corresponding to entry
func
(
e
*
entry
)
addr
()
*
Addr
{
func
(
e
*
entry
)
addr
()
*
Addr
{
return
&
Addr
{
network
:
e
.
network
.
N
ame
(),
addr
:
fmt
.
Sprintf
(
"%d"
,
e
.
port
)}
return
&
Addr
{
network
:
e
.
network
.
N
etwork
(),
addr
:
fmt
.
Sprintf
(
"%d"
,
e
.
port
)}
}
}
func
(
a
*
Addr
)
Network
()
string
{
return
a
.
network
}
func
(
a
*
Addr
)
Network
()
string
{
return
a
.
network
}
...
@@ -340,5 +340,5 @@ func (l *listener) Addr() net.Addr {
...
@@ -340,5 +340,5 @@ func (l *listener) Addr() net.Addr {
return
l
.
entry
.
addr
()
return
l
.
entry
.
addr
()
}
}
// N
ame
returns full network name of this network
// N
etwork
returns full network name of this network
func
(
n
*
Network
)
N
ame
()
string
{
return
NetPrefix
+
n
.
name
}
func
(
n
*
Network
)
N
etwork
()
string
{
return
NetPrefix
+
n
.
name
}
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