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
b13e8150
Commit
b13e8150
authored
Jun 09, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
9e223d74
Changes
3
Hide 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 (
"fmt"
"net"
"strconv"
"strings"
"crypto/tls"
"../xcommon/pipenet"
...
...
@@ -35,6 +36,9 @@ import (
// connections, and 2) dial peers. For this reason the interface is not split
// into Dialer and Listener.
type
Network
interface
{
// Network returns name of the network
Network
()
string
// Dial connects to addr on underlying network
// see net.Dial for semantic details
Dial
(
ctx
context
.
Context
,
addr
string
)
(
net
.
Conn
,
error
)
...
...
@@ -53,6 +57,10 @@ func NetPlain(network string) Network {
type
netPlain
string
func
(
n
netPlain
)
Network
()
string
{
return
string
(
n
)
}
func
(
n
netPlain
)
Dial
(
ctx
context
.
Context
,
addr
string
)
(
net
.
Conn
,
error
)
{
d
:=
net
.
Dialer
{}
return
d
.
DialContext
(
ctx
,
string
(
n
),
addr
)
...
...
@@ -80,6 +88,10 @@ type netTLS struct {
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
)
{
c
,
err
:=
n
.
inner
.
Dial
(
ctx
,
addr
)
if
err
!=
nil
{
...
...
@@ -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
func
Addr
(
addr
net
.
Addr
)
(
Address
,
error
)
{
addrstr
:=
addr
.
String
()
func
AddrString
(
network
,
addr
string
)
(
Address
,
error
)
{
// 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
switch
addr
.
Network
()
{
default
:
return
Address
{
Host
:
addrstr
,
Port
:
0
},
nil
// networks that have host:port split
case
"tcp"
,
"tcp4"
,
"tcp6"
,
"udp"
,
"udp4"
,
"udp6"
:
host
,
portstr
,
err
:=
net
.
SplitHostPort
(
addrstr
)
if
strings
.
HasPrefix
(
network
,
"tcp"
)
||
strings
.
HasPrefix
(
network
,
"udp"
)
{
// networks that have host:port split
host
,
portstr
,
err
:=
net
.
SplitHostPort
(
addr
)
if
err
!=
nil
{
return
Address
{},
err
}
// XXX also lookup portstr in /etc/services (net.LookupPort) ?
port
,
err
:=
strconv
.
ParseUint
(
portstr
,
10
,
16
)
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
:
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
...
...
go/neo/server/storage.go
View file @
b13e8150
...
...
@@ -36,8 +36,8 @@ type Storage struct {
myInfo
neo
.
NodeInfo
// XXX -> only Address + NodeUUID ?
clusterName
string
net
neo
.
Network
// network we are sending/receiving on
masterAddr
string
// address of master
XXX -> Address ?
net
neo
.
Network
// network we are sending/receiving on
masterAddr
string
// address of master
// ---- 8< ----
zstor
zodb
.
IStorage
// underlying ZODB storage XXX temp ?
...
...
@@ -48,7 +48,7 @@ type Storage struct {
// 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
{
// convert serveAddr into neo format
addr
,
err
:=
neo
.
ParseAddress
(
serveAddr
)
addr
,
err
:=
neo
.
AddrString
(
net
.
Network
(),
serveAddr
)
if
err
!=
nil
{
panic
(
err
)
// XXX
}
...
...
go/xcommon/pipenet/pipenet.go
View file @
b13e8150
...
...
@@ -122,7 +122,7 @@ func New(name string) *Network {
// Connection requests created by Dials could be accepted via Accept.
func
(
n
*
Network
)
Listen
(
laddr
string
)
(
net
.
Listener
,
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
...
...
@@ -195,7 +195,7 @@ func (l *listener) Accept() (net.Conn, error) {
select
{
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
:
// someone dialed us - let's connect
...
...
@@ -219,7 +219,7 @@ func (l *listener) Accept() (net.Conn, error) {
// 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
.
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
)
...
...
@@ -328,7 +328,7 @@ func (e *entry) empty() bool {
// addr returns address corresponding to entry
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
}
...
...
@@ -340,5 +340,5 @@ func (l *listener) Addr() net.Addr {
return
l
.
entry
.
addr
()
}
// N
ame
returns full network name of this network
func
(
n
*
Network
)
N
ame
()
string
{
return
NetPrefix
+
n
.
name
}
// N
etwork
returns full network name of this network
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