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
c867321f
Commit
c867321f
authored
7 years ago
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
99b8a6f4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
16 deletions
+22
-16
go/neo/net.go
go/neo/net.go
+22
-16
No files found.
go/neo/net.go
View file @
c867321f
...
...
@@ -107,28 +107,34 @@ func (addr Address) String() string {
switch
addr
.
Port
{
case
0
:
return
addr
.
Host
default
:
return
net
.
JoinHostPort
(
addr
.
Host
,
fmt
.
Sprintf
(
"%d"
,
addr
.
Port
))
}
}
// 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
//
func ParseAddress(addr string) (Address, error) {
func
ConvAddress
(
addr
net
.
Addr
)
(
Address
,
error
)
{
addrstr
:=
addr
.
String
()
// TODO detect :port presence ?
// XXX pass net.Addr() here instead of string?
host
,
portstr
,
err
:=
net
.
SplitHostPort
(
hostport
)
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
:
hostport
}
// e.g. on unix, pipenet, etc networks there is no host/port split - the address
// is single string which we put into .Host and set .Port=0 to indicate such cases
switch
addr
.
Network
()
{
default
:
return
Address
{
Host
:
addrstr
,
Port
:
0
},
nil
case
"tcp"
,
"tcp4"
,
"tcp6"
,
"udp"
,
"udp4"
,
"udp6"
:
host
,
portstr
,
err
:=
net
.
SplitHostPort
(
addrstr
)
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
:
addrstr
}
}
return
Address
{
Host
:
host
,
Port
:
uint16
(
port
)},
nil
}
return
Address
{
Host
:
host
,
Port
:
uint16
(
port
)},
nil
}
This diff is collapsed.
Click to expand it.
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