24#include <interfaces/ProtobufPeerInterface.h>
26#include <core/exceptions/software.h>
44ProtobufPeerInterface::ProtobufPeerInterface() : Interface()
46 data_size =
sizeof(ProtobufPeerInterface_data_t);
47 data_ptr = malloc(data_size);
48 data = (ProtobufPeerInterface_data_t *)data_ptr;
49 data_ts = (interface_data_ts_t *)data_ptr;
50 memset(data_ptr, 0, data_size);
51 add_fieldinfo(IFT_INT64,
"peers", 16, &data->peers);
52 add_messageinfo(
"CreatePeerMessage");
53 add_messageinfo(
"CreatePeerLocalMessage");
54 add_messageinfo(
"CreatePeerCryptoMessage");
55 add_messageinfo(
"CreatePeerLocalCryptoMessage");
56 unsigned char tmp_hash[] = {0x58, 0xc8, 0xa0, 0x57, 0x5c, 0x89, 0x32, 0xeb, 0x5a, 0xf0, 0x75, 0xbc, 0x6d, 0x15, 0xb3, 0x90};
61ProtobufPeerInterface::~ProtobufPeerInterface()
71ProtobufPeerInterface::peers()
const
83ProtobufPeerInterface::peers(
unsigned int index)
const
86 throw Exception(
"Index value %u out of bounds (0..15)", index);
88 return data->peers[index];
96ProtobufPeerInterface::maxlenof_peers()
const
106ProtobufPeerInterface::set_peers(
const int64_t * new_peers)
108 set_field(data->peers, new_peers);
117ProtobufPeerInterface::set_peers(
unsigned int index,
const int64_t new_peers)
119 set_field(data->peers, index, new_peers);
123ProtobufPeerInterface::create_message(
const char *type)
const
125 if ( strncmp(
"CreatePeerMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
127 }
else if ( strncmp(
"CreatePeerLocalMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
129 }
else if ( strncmp(
"CreatePeerCryptoMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
131 }
else if ( strncmp(
"CreatePeerLocalCryptoMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
135 "message type for this interface type.", type);
144ProtobufPeerInterface::copy_values(
const Interface *other)
149 type(), other->
type());
151 memcpy(data, oi->data,
sizeof(ProtobufPeerInterface_data_t));
155ProtobufPeerInterface::enum_tostring(
const char *enumtype,
int val)
const
172ProtobufPeerInterface::CreatePeerMessage::CreatePeerMessage(
const char * ini_address,
const int32_t ini_port) :
Message(
"CreatePeerMessage")
174 data_size =
sizeof(CreatePeerMessage_data_t);
177 data = (CreatePeerMessage_data_t *)
data_ptr;
179 strncpy(data->address, ini_address, 255-1);
180 data->address[255-1] = 0;
181 data->port = ini_port;
188 data_size =
sizeof(CreatePeerMessage_data_t);
191 data = (CreatePeerMessage_data_t *)
data_ptr;
211 data = (CreatePeerMessage_data_t *)
data_ptr;
223 return data->address;
300 data_size =
sizeof(CreatePeerLocalMessage_data_t);
303 data = (CreatePeerLocalMessage_data_t *)
data_ptr;
305 strncpy(data->address, ini_address, 255-1);
306 data->address[255-1] = 0;
307 data->send_to_port = ini_send_to_port;
308 data->recv_on_port = ini_recv_on_port;
316 data_size =
sizeof(CreatePeerLocalMessage_data_t);
319 data = (CreatePeerLocalMessage_data_t *)
data_ptr;
340 data = (CreatePeerLocalMessage_data_t *)
data_ptr;
352 return data->address;
382 return data->send_to_port;
402 set_field(data->send_to_port, new_send_to_port);
412 return data->recv_on_port;
432 set_field(data->recv_on_port, new_recv_on_port);
460 data_size =
sizeof(CreatePeerCryptoMessage_data_t);
463 data = (CreatePeerCryptoMessage_data_t *)
data_ptr;
465 strncpy(data->address, ini_address, 255-1);
466 data->address[255-1] = 0;
467 data->port = ini_port;
468 strncpy(data->crypto_key, ini_crypto_key, 1024-1);
469 data->crypto_key[1024-1] = 0;
470 strncpy(data->cipher, ini_cipher, 255-1);
471 data->cipher[255-1] = 0;
480 data_size =
sizeof(CreatePeerCryptoMessage_data_t);
483 data = (CreatePeerCryptoMessage_data_t *)
data_ptr;
505 data = (CreatePeerCryptoMessage_data_t *)
data_ptr;
517 return data->address;
577 return data->crypto_key;
597 set_field(data->crypto_key, new_crypto_key);
656 data_size =
sizeof(CreatePeerLocalCryptoMessage_data_t);
659 data = (CreatePeerLocalCryptoMessage_data_t *)
data_ptr;
661 strncpy(data->address, ini_address, 255-1);
662 data->address[255-1] = 0;
663 data->send_to_port = ini_send_to_port;
664 data->recv_on_port = ini_recv_on_port;
665 strncpy(data->crypto_key, ini_crypto_key, 1024-1);
666 data->crypto_key[1024-1] = 0;
667 strncpy(data->cipher, ini_cipher, 255-1);
668 data->cipher[255-1] = 0;
678 data_size =
sizeof(CreatePeerLocalCryptoMessage_data_t);
681 data = (CreatePeerLocalCryptoMessage_data_t *)
data_ptr;
704 data = (CreatePeerLocalCryptoMessage_data_t *)
data_ptr;
716 return data->address;
746 return data->send_to_port;
766 set_field(data->send_to_port, new_send_to_port);
776 return data->recv_on_port;
796 set_field(data->recv_on_port, new_recv_on_port);
806 return data->crypto_key;
826 set_field(data->crypto_key, new_crypto_key);
Base class for exceptions in Fawkes.
Base class for all Fawkes BlackBoard interfaces.
const char * type() const
Get type of interface.
void * data_ptr
Pointer to local memory storage.
void set_field(FieldT &field, DataT &data)
Set a field, set data_changed to true and update data_changed accordingly.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0, const interface_enum_map_t *enum_map=0)
Add an entry to the info list.
void * data_ptr
Pointer to memory that contains local data.
message_data_ts_t * data_ts
data timestamp aliasing pointer
unsigned int data_size
Size of memory needed to hold all data.
CreatePeerCryptoMessage Fawkes BlackBoard Interface Message.
int32_t port() const
Get port value.
void set_cipher(const char *new_cipher)
Set cipher value.
virtual Message * clone() const
Clone this message.
char * cipher() const
Get cipher value.
void set_address(const char *new_address)
Set address value.
size_t maxlenof_cipher() const
Get maximum length of cipher value.
void set_port(const int32_t new_port)
Set port value.
char * address() const
Get address value.
size_t maxlenof_crypto_key() const
Get maximum length of crypto_key value.
size_t maxlenof_port() const
Get maximum length of port value.
CreatePeerCryptoMessage()
Constructor.
void set_crypto_key(const char *new_crypto_key)
Set crypto_key value.
size_t maxlenof_address() const
Get maximum length of address value.
~CreatePeerCryptoMessage()
Destructor.
char * crypto_key() const
Get crypto_key value.
CreatePeerLocalCryptoMessage Fawkes BlackBoard Interface Message.
char * cipher() const
Get cipher value.
int32_t send_to_port() const
Get send_to_port value.
size_t maxlenof_send_to_port() const
Get maximum length of send_to_port value.
~CreatePeerLocalCryptoMessage()
Destructor.
size_t maxlenof_recv_on_port() const
Get maximum length of recv_on_port value.
void set_send_to_port(const int32_t new_send_to_port)
Set send_to_port value.
void set_crypto_key(const char *new_crypto_key)
Set crypto_key value.
size_t maxlenof_cipher() const
Get maximum length of cipher value.
void set_address(const char *new_address)
Set address value.
CreatePeerLocalCryptoMessage()
Constructor.
void set_recv_on_port(const int32_t new_recv_on_port)
Set recv_on_port value.
virtual Message * clone() const
Clone this message.
char * address() const
Get address value.
size_t maxlenof_crypto_key() const
Get maximum length of crypto_key value.
void set_cipher(const char *new_cipher)
Set cipher value.
char * crypto_key() const
Get crypto_key value.
size_t maxlenof_address() const
Get maximum length of address value.
int32_t recv_on_port() const
Get recv_on_port value.
CreatePeerLocalMessage Fawkes BlackBoard Interface Message.
~CreatePeerLocalMessage()
Destructor.
char * address() const
Get address value.
void set_send_to_port(const int32_t new_send_to_port)
Set send_to_port value.
void set_recv_on_port(const int32_t new_recv_on_port)
Set recv_on_port value.
int32_t recv_on_port() const
Get recv_on_port value.
size_t maxlenof_send_to_port() const
Get maximum length of send_to_port value.
void set_address(const char *new_address)
Set address value.
int32_t send_to_port() const
Get send_to_port value.
CreatePeerLocalMessage()
Constructor.
size_t maxlenof_address() const
Get maximum length of address value.
size_t maxlenof_recv_on_port() const
Get maximum length of recv_on_port value.
virtual Message * clone() const
Clone this message.
CreatePeerMessage Fawkes BlackBoard Interface Message.
~CreatePeerMessage()
Destructor.
int32_t port() const
Get port value.
char * address() const
Get address value.
size_t maxlenof_port() const
Get maximum length of port value.
virtual Message * clone() const
Clone this message.
size_t maxlenof_address() const
Get maximum length of address value.
void set_address(const char *new_address)
Set address value.
void set_port(const int32_t new_port)
Set port value.
CreatePeerMessage()
Constructor.
ProtobufPeerInterface Fawkes BlackBoard Interface.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
Fawkes library namespace.
@ IFT_INT32
32 bit integer field
Timestamp data, must be present and first entries for each interface data structs!...