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
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
Levin Zimmermann
neoppod
Commits
2ad63c2c
Commit
2ad63c2c
authored
Dec 05, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
cb81558c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
16 deletions
+103
-16
t/neo/byteorder.go
t/neo/byteorder.go
+74
-0
t/neo/connection.go
t/neo/connection.go
+19
-6
t/neo/pkt.go
t/neo/pkt.go
+10
-10
No files found.
t/neo/byteorder.go
0 → 100644
View file @
2ad63c2c
// Copyright (C) 2016 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 2, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// NEO | Work with bigendian data
package
neo
import
(
"encoding/binary"
"unsafe"
)
type
be16
uint16
type
be32
uint32
type
be64
uint64
func
ntoh16
(
v
be16
)
uint16
{
b
:=
(
*
[
2
]
byte
)(
unsafe
.
Pointer
(
&
v
))
return
binary
.
BigEndian
.
Uint16
(
b
[
:
])
}
/* NOTE ^^^ is as efficient
func ntoh16_2(v be16) uint16 {
b := (*[2]byte)(unsafe.Pointer(&v))
return uint16(b[1]) | uint16(b[0])<<8
}
*/
/* FIXME compiler emits instruction to pre-clear r, probably because of &r
func hton16_2(v uint16) (r be16) {
b := (*[2]byte)(unsafe.Pointer(&r))
binary.BigEndian.PutUint16(b[:], v)
return r
}
*/
// NOTE here we are leveraging BigEndian.Uint16**2 = identity
func
hton16
(
v
uint16
)
be16
{
// FIXME just doing
// return be16(ntoh16(be16(v)))
// emits more prologue/epilogue
b
:=
(
*
[
2
]
byte
)(
unsafe
.
Pointer
(
&
v
))
return
be16
(
binary
.
BigEndian
.
Uint16
(
b
[
:
])
)
}
func
ntoh32
(
v
be32
)
uint32
{
b
:=
(
*
[
4
]
byte
)(
unsafe
.
Pointer
(
&
v
))
return
binary
.
BigEndian
.
Uint32
(
b
[
:
])
}
func
hton32
(
v
uint32
)
be32
{
b
:=
(
*
[
4
]
byte
)(
unsafe
.
Pointer
(
&
v
))
return
be32
(
binary
.
BigEndian
.
Uint32
(
b
[
:
])
)
}
func
ntoh64
(
v
be64
)
uint64
{
b
:=
(
*
[
8
]
byte
)(
unsafe
.
Pointer
(
&
v
))
return
binary
.
BigEndian
.
Uint64
(
b
[
:
])
}
func
hton64
(
v
uint64
)
be64
{
b
:=
(
*
[
8
]
byte
)(
unsafe
.
Pointer
(
&
v
))
return
be64
(
binary
.
BigEndian
.
Uint64
(
b
[
:
])
)
}
t/neo/connection.go
View file @
2ad63c2c
...
...
@@ -31,17 +31,17 @@ import (
// created and data is sent over it, on peer's side another corresponding
// new connection will be created - accepting first packet "request" - and all
// further communication send/receive exchange will be happenning in between
// those 2 connections.
TODO conn close
// those 2 connections.
//
// For a node to be able to accept new incoming connection it has to register
// corresponding handler with .HandleNewConn() . Without such handler
// registered the node will be able to only initiate new connections, not
// accept new ones from its peer.
//
//
TODO NodeLink close
//
A NodeLink has to be explicitly closed, once it is no longer needed.
//
// It is safe to use NodeLink from multiple goroutines simultaneously.
type
NodeLink
struct
{
// XXX naming (-> PeerLink ?)
type
NodeLink
struct
{
peerLink
net
.
Conn
// raw conn to peer
// TODO locking
...
...
@@ -56,7 +56,7 @@ type NodeLink struct { // XXX naming (-> PeerLink ?)
// Data can be sent and received over it.
// Once connection is no longer needed it has to be closed.
//
//
TODO goroutine guarantee (looks to be safe, but if not check whether we need it)
//
It is safe to use Conn from multiple goroutines simultaneously.
type
Conn
struct
{
nodeLink
*
NodeLink
rxq
chan
*
PktBuf
...
...
@@ -64,8 +64,14 @@ type Conn struct {
// Buffer with packet data
type
PktBuf
struct
{
PktHead
Body
[]
byte
//PktHead
Data
[]
byte
// whole packet data including all headers
}
// Get pointer to packet header
func
(
pkt
*
PktBuf
)
Head
()
*
PktHead
{
// XXX check len(Data) < PktHead ?
return
(
*
PktHead
)(
unsafe
.
Pointer
(
&
pkt
.
Data
[
0
]))
}
...
...
@@ -177,6 +183,13 @@ func (nl *NodeLink) HandleNewConn(h func(*Conn)) {
nl
.
handleNewConn
=
h
// NOTE can change handler at runtime XXX do we need this?
}
// Close node-node link.
// IO on connections established over it is automatically interrupted with an error.
// XXX ^^^ recheck
func
(
nl
*
NodeLink
)
Close
()
error
{
// TODO
return
nil
}
...
...
t/neo/pkt.go
View file @
2ad63c2c
...
...
@@ -99,7 +99,7 @@ type Checksum [20]byte
type
PTid
uint64
// XXX move to common place ?
// TODO None encodes as '\xff' * 8 (XXX use nan for None ?)
type
Float
float64
type
Float
64
float64
// NOTE original NodeList = []NodeInfo
type
NodeInfo
struct
{
...
...
@@ -107,19 +107,19 @@ type NodeInfo struct {
Address
UUID
NodeState
IdTimestamp
Float
IdTimestamp
Float
64
}
//
XXX -> CellInfo (and use []CellInfo) ?
type
Cell
List
[]
struct
{
//
type CellList []struct {
type
Cell
Info
struct
{
UUID
UUID
// XXX maybe simply 'UUID' ?
CellState
CellState
// ----///----
}
//
XXX -> RowInfo (and use []RowInfo) ?
type
Row
List
[]
struct
{
//
type RowList []struct {
type
Row
Info
struct
{
Offset
uint32
// PNumber
CellList
CellList
CellList
[]
CellInfo
}
...
...
@@ -240,7 +240,7 @@ type PartitionTable struct {
type
AnswerPartitionTable
struct
{
PktHead
PTid
RowList
RowList
RowList
[]
RowInfo
}
...
...
@@ -248,7 +248,7 @@ type AnswerPartitionTable struct {
type
NotifyPartitionTable
struct
{
PktHead
PTid
RowList
RowList
RowList
[]
RowInfo
}
// Notify a subset of a partition table. This is used to notify changes.
...
...
@@ -556,7 +556,7 @@ type PartitionList struct {
type
AnswerPartitionList
struct
{
PktHead
PTid
RowList
RowList
RowList
[]
RowInfo
}
// Ask information about nodes
...
...
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