Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPC 2.0 #2487

Merged
merged 14 commits into from
Feb 20, 2020
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ qrc_resources.cpp
qt_system
resources.qrc.depends

# Autogenerated Flatbuffers source files
nano/ipc_flatbuffers_lib/generated/flatbuffers/nanoapi_generated.h

# CMake artifacts
_CPack_Packages
CPack*
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
[submodule "nano-pow-server"]
path = nano-pow-server
url = https://github.com/nanocurrency/nano-pow-server.git
[submodule "flatbuffers"]
path = flatbuffers
url = https://github.com/google/flatbuffers.git
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ endif ()
include_directories(cpptoml/include)
add_subdirectory(crypto/ed25519-donna)

add_subdirectory(nano/ipc_flatbuffers_lib)
add_subdirectory(nano/ipc_flatbuffers_test)

set (UPNPC_BUILD_SHARED OFF CACHE BOOL "")
add_subdirectory (miniupnp/miniupnpc EXCLUDE_FROM_ALL)
# FIXME: This fixes miniupnpc include directories without modifying miniupnpc's
Expand Down
256 changes: 256 additions & 0 deletions api/flatbuffers/nanoapi.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
/*
Flatbuffer schema for the Nano IPC API.
Please see https://google.github.io/flatbuffers/md__schemas.html for recommended schema evolution practices.
*/
namespace nanoapi;

/** Returns the voting weight for the given account */
table AccountWeight {
/** A nano_ address */
account: string (required);
}

/** Response to AccountWeight */
table AccountWeightResponse {
/** Voting weight as a decimal number*/
voting_weight: string (required);
}

/**
* Block subtype for state blocks.
* Note that the node makes no distinction between open and receive subtypes.
*/
enum BlockSubType: byte {
invalid = 0,
receive,
send,
change,
epoch
}

/** Block union */
union Block {
BlockState,
BlockOpen,
BlockReceive,
BlockSend,
BlockChange
}

table BlockOpen {
/** Hash of this block */
hash: string;
/** Account being opened */
account: string;
/** Hash of send block */
source: string;
/** Representative address */
representative: string;
/** Signature as a hex string */
signature: string;
/** Work is a hex string representing work. This is a string as the work value may not fit in native numeric types. */
work: string;
}

table BlockReceive {
/** Hash of this block */
hash: string;
/** Hash of previous block */
previous: string;
/** Source hash */
source: string;
/** Signature as a hex string */
signature: string;
/** Work is a hex string representing work. This is a string as the work value may not fit in native numeric types. */
work: string;
}

table BlockSend {
/** Hash of this block */
hash: string;
/** Hash of previous block */
previous: string;
/** Destination account */
destination: string;
/** Balance in raw */
balance: string;
/** Signature as a hex string */
signature: string;
/** Work is a hex string representing work. This is a string as the work value may not fit in native numeric types. */
work: string;
}

table BlockChange {
/** Hash of this block */
hash: string;
/** Hash of previous block */
previous: string;
/** Representative address */
representative: string;
/** Signature as a hex string */
signature: string;
/** Work is a hex string representing work. This is a string as the work value may not fit in native numeric types. */
work: string;
}

table BlockState {
/** Hash of this block */
hash: string;
/** Account as nano_ string */
account: string;
/** Hash of previous block */
previous: string;
/** Representative as nano_ string */
representative: string;
/** Balance in raw */
balance: string;
/** Link as a hex string */
link: string;
/** Link interpreted as a nano_ address */
link_as_account: string;
/** Signature as a hex string */
signature: string;
/** Work is a hex string representing work. This is a string as the work value may not fit in native numeric types. */
work: string;
/** Subtype of this state block */
subtype: BlockSubType;
}

/** Information about a block */
table BlockInfo {
block: Block;
}

/** Called by a service (usually an external process) to register itself */
table ServiceRegister {
service_name: string;
}

/** Request the node to send an EventServiceStop event to the given service */
table ServiceStop {
/** Name of service to stop. */
service_name: string (required);
/** If true, restart the service */
restart: bool = false;
}

/**
* Subscribe or unsubscribe to EventServiceStop events.
* The service must first have registered itself on the same session.
*/
table TopicServiceStop {
/** Set to true to unsubscribe */
unsubscribe: bool;
}

/** Sent to a service to request it to stop itself */
table EventServiceStop {
}

/**
* All subscriptions are acknowledged. Use the envelope's correlation id
* if you need to match the ack with the subscription.
*/
table EventAck {
}

/** Requested confirmation type */
enum TopicConfirmationTypeFilter : byte { all, active, active_quorum, active_confirmation_height, inactive }

/** Type of block confirmation */
enum TopicConfirmationType : byte { active_quorum, active_confirmation_height, inactive }

/** Subscribe or unsubscribe to block confirmations of type EventConfirmation */
table TopicConfirmation {
/** Set to true to unsubscribe */
unsubscribe: bool;
options: TopicConfirmationOptions;
}

table TopicConfirmationOptions {
confirmation_type_filter: TopicConfirmationTypeFilter = all;
all_local_accounts: bool;
accounts: [string];
include_block: bool = true;
include_election_info: bool = true;
}

/** Notification of block confirmation. */
table EventConfirmation {
confirmation_type: TopicConfirmationType;
account: string;
amount: string;
hash: string;
block: Block;
election_info: ElectionInfo;
}

table ElectionInfo {
duration: uint64;
time: uint64;
tally: string;
request_count: uint64;
block_count: uint64;
voter_count: uint64;
}

/** Error response. All fields are optional */
table Error {
/** Error code. May be negative or positive. */
code: int;
/** Error category code */
category: int;
/** Error message */
message: string;
}

/**
* A general purpose success response for messages that don't return a message.
* The response includes an optional message text.
*/
table Success {
message: string;
}

/** IsAlive request and response. Any node issues will be reported through an error in the envelope. */
table IsAlive {
}

/**
* A union is the idiomatic way in Flatbuffers to transmit messages of multiple types.
* All top-level message types (including response types) must be listed here.
* @warning To ensure compatibility, only append and deprecate message types.
*/
union Message {
Error,
Success,
IsAlive,
EventAck,
BlockInfo,
AccountWeight,
AccountWeightResponse,
TopicConfirmation,
EventConfirmation,
ServiceRegister,
ServiceStop,
TopicServiceStop,
EventServiceStop
}

/**
* All messages are wrapped in an envelope which contains information such as
* message type, credentials and correlation id. For responses, the message may be an Error.
*/
table Envelope {
/** Milliseconds since epoch when the message was sent. */
time: uint64;
/** An optional and arbitrary string used for authentication. The corresponding http header for api keys is "nano-api-key" */
credentials: string;
/** Correlation id is an optional and arbitrary string. The corresponding http header is "nano-correlation-id" */
correlation_id: string;
/** The contained message. A 'message_type' property will be automatically added to JSON messages. */
message: Message;
}

/** The Envelope is the type marshalled over IPC, and also serves as the top-level JSON type */
root_type Envelope;
1 change: 1 addition & 0 deletions docker/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ RUN groupadd --gid 1000 nanocurrency && \
COPY --from=0 /tmp/build/nano_node /usr/bin
COPY --from=0 /tmp/build/nano_rpc /usr/bin
COPY --from=0 /tmp/build/nano_pow_server /usr/bin
COPY --from=0 /tmp/src/api/ /usr/bin/api/
COPY --from=0 /etc/nano-network /etc
COPY docker/node/entry.sh /usr/bin/entry.sh
COPY docker/node/config /usr/share/nano/config
Expand Down
1 change: 1 addition & 0 deletions flatbuffers
Submodule flatbuffers added at 3b458f
Loading