Commit 2ad63c2c authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent cb81558c
// 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[:]) )
}
......@@ -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
}
......
......@@ -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 Float64 float64
// NOTE original NodeList = []NodeInfo
type NodeInfo struct {
......@@ -107,19 +107,19 @@ type NodeInfo struct {
Address
UUID
NodeState
IdTimestamp Float
IdTimestamp Float64
}
// XXX -> CellInfo (and use []CellInfo) ?
type CellList []struct {
//type CellList []struct {
type CellInfo struct {
UUID UUID // XXX maybe simply 'UUID' ?
CellState CellState // ----///----
}
// XXX -> RowInfo (and use []RowInfo) ?
type RowList []struct {
//type RowList []struct {
type RowInfo 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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment