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
badeb060
Commit
badeb060
authored
Apr 28, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X identify chat draftly works
parent
cb23e144
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
12 deletions
+68
-12
go/neo/client.go
go/neo/client.go
+12
-3
go/neo/connection.go
go/neo/connection.go
+2
-2
go/neo/server.go
go/neo/server.go
+51
-5
go/neo/storage.go
go/neo/storage.go
+3
-2
No files found.
go/neo/client.go
View file @
badeb060
...
...
@@ -53,7 +53,8 @@ func (c *Client) LastTid() (zodb.Tid, error) {
reply
,
err
:=
RecvAndDecode
(
c
.
storConn
)
if
err
!=
nil
{
return
0
,
err
// XXX err context
// XXX err context (e.g. peer resetting connection -> currently only EOF)
return
0
,
err
}
switch
reply
:=
reply
.
(
type
)
{
...
...
@@ -87,13 +88,21 @@ func openClientByURL(u *url.URL) (zodb.IStorage, error) {
return
nil
,
err
}
// identify ourselves via conn
storType
,
err
:=
IdentifyMe
(
storLink
,
CLIENT
)
if
err
!=
nil
{
return
nil
,
err
// XXX err ctx
}
if
storType
!=
STORAGE
{
storLink
.
Close
()
// XXX err
return
nil
,
fmt
.
Errorf
(
"%v: peer is not storage (identifies as %v)"
,
storLink
,
storType
)
}
conn
,
err
:=
storLink
.
NewConn
()
if
err
!=
nil
{
return
nil
,
err
// XXX err ctx ?
}
// TODO identify ourselves via conn
return
&
Client
{
storLink
,
conn
},
nil
}
...
...
go/neo/connection.go
View file @
badeb060
...
...
@@ -467,7 +467,7 @@ func (nl *NodeLink) serveSend() {
// sendPkt sends raw packet to peer
// tx error, if any, is returned as is and is analyzed in serveSend
func
(
nl
*
NodeLink
)
sendPkt
(
pkt
*
PktBuf
)
error
{
if
fals
e
{
if
tru
e
{
// XXX -> log
fmt
.
Printf
(
"%v > %v: %v
\n
"
,
nl
.
peerLink
.
LocalAddr
(),
nl
.
peerLink
.
RemoteAddr
(),
pkt
)
//defer fmt.Printf("\t-> sendPkt err: %v\n", err)
...
...
@@ -524,7 +524,7 @@ func (nl *NodeLink) recvPkt() (*PktBuf, error) {
}
}
if
fals
e
{
if
tru
e
{
// XXX -> log
fmt
.
Printf
(
"%v < %v: %v
\n
"
,
nl
.
peerLink
.
LocalAddr
(),
nl
.
peerLink
.
RemoteAddr
(),
pkt
)
}
...
...
go/neo/server.go
View file @
badeb060
...
...
@@ -80,10 +80,10 @@ func ListenAndServe(ctx context.Context, net_, laddr string, srv Server) error {
// ----------------------------------------
// Identify identifies peer on the link
// it expects peer to send RequestIdentification packet and replies with AcceptIdentification if identification pa
rameters are ok
.
// Identify
Peer
identifies peer on the link
// it expects peer to send RequestIdentification packet and replies with AcceptIdentification if identification pa
sses
.
// returns information about identified node or error.
func
Identify
(
link
*
NodeLink
)
(
nodeInfo
RequestIdentification
/*TODO -> NodeInfo*/
,
err
error
)
{
func
Identify
Peer
(
link
*
NodeLink
,
myNodeType
NodeType
)
(
nodeInfo
RequestIdentification
/*TODO -> NodeInfo*/
,
err
error
)
{
// the first conn must come with RequestIdentification packet
conn
,
err
:=
link
.
Accept
()
if
err
!=
nil
{
...
...
@@ -92,7 +92,7 @@ func Identify(link *NodeLink) (nodeInfo RequestIdentification /*TODO -> NodeInfo
defer
func
()
{
err2
:=
conn
.
Close
()
if
err
==
nil
{
err
=
err2
err
=
err2
// XXX err ctx
// XXX also clear nodeInfo ?
}
}()
...
...
@@ -106,6 +106,8 @@ func Identify(link *NodeLink) (nodeInfo RequestIdentification /*TODO -> NodeInfo
default
:
return
nodeInfo
,
fmt
.
Errorf
(
"expected RequestIdentification ; got %T"
,
pkt
)
// XXX also handle Error
case
*
RequestIdentification
:
if
pkt
.
ProtocolVersion
!=
PROTOCOL_VERSION
{
// TODO also tell peer with Error
...
...
@@ -115,7 +117,7 @@ func Identify(link *NodeLink) (nodeInfo RequestIdentification /*TODO -> NodeInfo
// TODO (.NodeType, .UUID, .Address, .Name, .IdTimestamp) -> check + register to NM
err
=
EncodeAndSend
(
conn
,
&
AcceptIdentification
{
NodeType
:
pkt
.
NodeType
,
NodeType
:
my
NodeType
,
MyUUID
:
0
,
// XXX
NumPartitions
:
0
,
// XXX
NumReplicas
:
0
,
// XXX
...
...
@@ -134,6 +136,50 @@ func Identify(link *NodeLink) (nodeInfo RequestIdentification /*TODO -> NodeInfo
return
nodeInfo
,
nil
}
// IdentifyMe identifies local node to remote peer
func
IdentifyMe
(
link
*
NodeLink
,
nodeType
NodeType
/*XXX*/
)
(
peerType
NodeType
,
err
error
)
{
conn
,
err
:=
link
.
NewConn
()
if
err
!=
nil
{
return
peerType
,
err
}
defer
func
()
{
err2
:=
conn
.
Close
()
if
err
==
nil
&&
err2
!=
nil
{
err
=
err2
// XXX err ctx
// XXX also reset peerType
}
}()
err
=
EncodeAndSend
(
conn
,
&
RequestIdentification
{
ProtocolVersion
:
PROTOCOL_VERSION
,
NodeType
:
nodeType
,
UUID
:
0
,
// XXX
Address
:
Address
{},
// XXX
Name
:
""
,
// XXX cluster name ?
IdTimestamp
:
0
,
// XXX
})
if
err
!=
nil
{
return
peerType
,
err
}
pkt
,
err
:=
RecvAndDecode
(
conn
)
if
err
!=
nil
{
return
peerType
,
err
}
switch
pkt
:=
pkt
.
(
type
)
{
default
:
return
peerType
,
fmt
.
Errorf
(
"expected AcceptIdentification ; got %T"
,
pkt
)
// XXX also handle Error
case
*
AcceptIdentification
:
return
pkt
.
NodeType
,
nil
}
}
// ----------------------------------------
// XXX place = ok ? not ok -> move out of here
// XXX naming for RecvAndDecode and EncodeAndSend
...
...
go/neo/storage.go
View file @
badeb060
...
...
@@ -62,7 +62,7 @@ func (stor *Storage) ServeLink(ctx context.Context, link *NodeLink) {
link
.
Close
()
// XXX err
}()
nodeInfo
,
err
:=
Identify
(
link
)
nodeInfo
,
err
:=
Identify
Peer
(
link
,
STORAGE
)
if
err
!=
nil
{
fmt
.
Printf
(
"peer identification failed: %v
\n
"
,
err
)
return
...
...
@@ -83,7 +83,7 @@ func (stor *Storage) ServeLink(ctx context.Context, link *NodeLink) {
conn
,
err
:=
link
.
Accept
()
if
err
!=
nil
{
fmt
.
Printf
(
"accept: %v
\n
"
,
err
)
// XXX err ctx
continue
break
}
// XXX adjust ctx ?
...
...
@@ -91,6 +91,7 @@ func (stor *Storage) ServeLink(ctx context.Context, link *NodeLink) {
go
serveConn
(
ctx
,
conn
)
}
// TODO wait all spawned serveConn
}
// connAddr returns string describing conn XXX text, naming
...
...
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