Compare commits
No commits in common. "b1906172851017a87c83a81400dc7936a68bf362" and "9edf3fcf2f23d855487854c74fc50019b68e9f66" have entirely different histories.
b190617285
...
9edf3fcf2f
29
ft_recv.dot
29
ft_recv.dot
@ -1,29 +0,0 @@
|
|||||||
digraph ft_send {
|
|
||||||
fontname="Helvetica,Arial,sans-serif"
|
|
||||||
node [fontname="Helvetica,Arial,sans-serif"]
|
|
||||||
edge [fontname="Helvetica,Arial,sans-serif"]
|
|
||||||
|
|
||||||
label="FT1_Receiver";
|
|
||||||
labelloc="t";
|
|
||||||
|
|
||||||
start [label="start | we got FT_INIT"];
|
|
||||||
fail [shape=doublecircle];
|
|
||||||
done [shape=doublecircle];
|
|
||||||
|
|
||||||
// peer offline (how)
|
|
||||||
start -> fail [label="peer offline"]
|
|
||||||
|
|
||||||
start -> starting [label="send FT_INIT_ACK"];
|
|
||||||
starting -> starting [label="if timeout or get FT_INIT send FT_INIT_ACK"];
|
|
||||||
starting -> fail [label="if timeout too often"];
|
|
||||||
|
|
||||||
|
|
||||||
subgraph cluster_data {
|
|
||||||
label="for each data chunk";
|
|
||||||
style=filled;
|
|
||||||
|
|
||||||
starting -> got_data [label="got FT_DATA"];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
69
ft_send.dot
69
ft_send.dot
@ -1,69 +0,0 @@
|
|||||||
digraph ft_send {
|
|
||||||
fontname="Helvetica,Arial,sans-serif"
|
|
||||||
node [fontname="Helvetica,Arial,sans-serif"]
|
|
||||||
edge [fontname="Helvetica,Arial,sans-serif"]
|
|
||||||
|
|
||||||
label="FT1_Sender";
|
|
||||||
labelloc="t";
|
|
||||||
|
|
||||||
//layout=fdp
|
|
||||||
//rankdir = LR
|
|
||||||
|
|
||||||
start;
|
|
||||||
fail [shape=doublecircle];
|
|
||||||
done [shape=doublecircle];
|
|
||||||
|
|
||||||
// peer offline (how)
|
|
||||||
start -> fail [label="peer offline"]
|
|
||||||
|
|
||||||
// TODO: move to single node with loop
|
|
||||||
subgraph cluster_init {
|
|
||||||
label="Send Init";
|
|
||||||
|
|
||||||
style=filled;
|
|
||||||
//color=lightgrey;
|
|
||||||
|
|
||||||
|
|
||||||
// if it fails
|
|
||||||
sent_init1 -> sent_init2 [label="send FT_INIT"]
|
|
||||||
|
|
||||||
// if it fails again
|
|
||||||
sent_init2 -> sent_init3 [label="send FT_INIT"]
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
start -> sent_init1 [label="send FT_INIT"]
|
|
||||||
|
|
||||||
// peer offline (how)
|
|
||||||
sent_init1 -> fail [label="peer offline"]
|
|
||||||
|
|
||||||
// peer offline (how)
|
|
||||||
sent_init2 -> fail [label="peer offline"]
|
|
||||||
|
|
||||||
// give up after 3. attempt
|
|
||||||
sent_init3 -> fail [label="no ack / peer offline"]
|
|
||||||
|
|
||||||
// got an ack after an init
|
|
||||||
sent_init1 -> have_data [label="got init_ack"]
|
|
||||||
sent_init2 -> have_data [label="got init_ack"]
|
|
||||||
sent_init3 -> have_data [label="got init_ack"]
|
|
||||||
|
|
||||||
subgraph cluster_data {
|
|
||||||
label="for each data chunk";
|
|
||||||
style=filled;
|
|
||||||
//node [style=filled];
|
|
||||||
|
|
||||||
have_data -> data_awaiting_ack [label="send FT_DATA"];
|
|
||||||
data_awaiting_ack -> data_wait_for_all [label="get FT_DATA_ACK"];
|
|
||||||
data_awaiting_ack -> have_data [label="no FT_DATA_ACK"];
|
|
||||||
|
|
||||||
data_wait_for_all;
|
|
||||||
}
|
|
||||||
|
|
||||||
// fail
|
|
||||||
have_data -> fail [label="peer offline"]
|
|
||||||
data_wait_for_all -> fail [label="peer offline"]
|
|
||||||
|
|
||||||
data_wait_for_all -> done [label="all chunks acked"];
|
|
||||||
}
|
|
||||||
|
|
@ -72,13 +72,13 @@ enum _PacketType : uint8_t {
|
|||||||
// - ]
|
// - ]
|
||||||
FT1_DATA_ACK,
|
FT1_DATA_ACK,
|
||||||
|
|
||||||
//// sender has gotten every data fragment acked, so we signal finish
|
// sender has gotten every data fragment acked, so we signal finish
|
||||||
//// - 1 byte (temporary_file_tf_id)
|
// - 1 byte (temporary_file_tf_id)
|
||||||
//FT1_DATA_FIN,
|
FT1_DATA_FIN,
|
||||||
|
|
||||||
//// and we ack that, we need this, so file_id is not reused earlier
|
// and we ack that, we need this, so file_id is not reused earlier
|
||||||
//// - 1 byte (temporary_file_tf_id)
|
// - 1 byte (temporary_file_tf_id)
|
||||||
//FT1_DATA_FIN_ACK,
|
FT1_DATA_FIN_ACK,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GroupKey {
|
struct _GroupKey {
|
||||||
|
59
ngc_hs1.cpp
59
ngc_hs1.cpp
@ -71,14 +71,14 @@ void _handle_HS1_RESPONSE_LAST_IDS(
|
|||||||
size_t length
|
size_t length
|
||||||
);
|
);
|
||||||
|
|
||||||
void _handle_HS1_ft_recv_request(
|
void _handle_HS1_ft_request_message(
|
||||||
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
||||||
uint32_t group_number,
|
uint32_t group_number,
|
||||||
uint32_t peer_number,
|
uint32_t peer_number,
|
||||||
const uint8_t* file_id, size_t file_id_size
|
const uint8_t* file_id, size_t file_id_size
|
||||||
);
|
);
|
||||||
|
|
||||||
bool _handle_HS1_ft_recv_init(
|
bool _handle_HS1_ft_init_message(
|
||||||
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
||||||
uint32_t group_number,
|
uint32_t group_number,
|
||||||
uint32_t peer_number,
|
uint32_t peer_number,
|
||||||
@ -87,15 +87,6 @@ bool _handle_HS1_ft_recv_init(
|
|||||||
const size_t file_size
|
const size_t file_size
|
||||||
);
|
);
|
||||||
|
|
||||||
void _handle_HS1_ft_recv_data(
|
|
||||||
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
|
||||||
uint32_t group_number,
|
|
||||||
uint32_t peer_number,
|
|
||||||
uint8_t transfer_id,
|
|
||||||
size_t data_offset,
|
|
||||||
const uint8_t* data, size_t data_size
|
|
||||||
);
|
|
||||||
|
|
||||||
bool NGC_HS1_init(NGC_EXT_CTX* ngc_ext_ctx, const struct NGC_HS1_options* options) {
|
bool NGC_HS1_init(NGC_EXT_CTX* ngc_ext_ctx, const struct NGC_HS1_options* options) {
|
||||||
ngc_ext_ctx->ngc_hs1_ctx = new NGC_HS1;
|
ngc_ext_ctx->ngc_hs1_ctx = new NGC_HS1;
|
||||||
ngc_ext_ctx->ngc_hs1_ctx->options = *options;
|
ngc_ext_ctx->ngc_hs1_ctx->options = *options;
|
||||||
@ -103,10 +94,8 @@ bool NGC_HS1_init(NGC_EXT_CTX* ngc_ext_ctx, const struct NGC_HS1_options* option
|
|||||||
ngc_ext_ctx->callbacks[HS1_REQUEST_LAST_IDS] = _handle_HS1_REQUEST_LAST_IDS;
|
ngc_ext_ctx->callbacks[HS1_REQUEST_LAST_IDS] = _handle_HS1_REQUEST_LAST_IDS;
|
||||||
ngc_ext_ctx->callbacks[HS1_RESPONSE_LAST_IDS] = _handle_HS1_RESPONSE_LAST_IDS;
|
ngc_ext_ctx->callbacks[HS1_RESPONSE_LAST_IDS] = _handle_HS1_RESPONSE_LAST_IDS;
|
||||||
|
|
||||||
NGC_FT1_register_callback_recv_request(ngc_ext_ctx, NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID, _handle_HS1_ft_recv_request);
|
NGC_FT1_register_callback_recv_request(ngc_ext_ctx, NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID, _handle_HS1_ft_request_message);
|
||||||
NGC_FT1_register_callback_recv_init(ngc_ext_ctx, NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID, _handle_HS1_ft_recv_init);
|
NGC_FT1_register_callback_recv_init(ngc_ext_ctx, NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID, _handle_HS1_ft_init_message);
|
||||||
NGC_FT1_register_callback_recv_data(ngc_ext_ctx, NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID, _handle_HS1_ft_recv_data);
|
|
||||||
//NGC_FT1_register_callback_send_data(ngc_ext_ctx, NGC_FT1_file_kind::NGC_HS1_MESSAGE_BY_ID, _handle_HS1_ft_init_message);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -361,7 +350,7 @@ void NGC_HS1_record_message(
|
|||||||
ngc_hs1_ctx->history[g_id].peers[p_id].append(message_id, type, std::string{message, message+length});
|
ngc_hs1_ctx->history[g_id].peers[p_id].append(message_id, type, std::string{message, message+length});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handle_HS1_ft_recv_request(
|
void _handle_HS1_ft_request_message(
|
||||||
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
||||||
uint32_t group_number,
|
uint32_t group_number,
|
||||||
uint32_t peer_number,
|
uint32_t peer_number,
|
||||||
@ -422,7 +411,7 @@ void _handle_HS1_ft_recv_request(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _handle_HS1_ft_recv_init(
|
bool _handle_HS1_ft_init_message(
|
||||||
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
||||||
uint32_t group_number,
|
uint32_t group_number,
|
||||||
uint32_t peer_number,
|
uint32_t peer_number,
|
||||||
@ -471,48 +460,12 @@ bool _handle_HS1_ft_recv_init(
|
|||||||
return false; // deny
|
return false; // deny
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: if allready acked but got init again, they did not get the ack
|
|
||||||
|
|
||||||
// TODO: more?
|
// TODO: more?
|
||||||
pending.at(msg_id).time_since_ft_activity = 0.f;
|
pending.at(msg_id).time_since_ft_activity = 0.f;
|
||||||
//pending.at(msg_id).transfer_acked;
|
|
||||||
group.transfers
|
|
||||||
|
|
||||||
return true; // accept
|
return true; // accept
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handle_HS1_ft_recv_data(
|
|
||||||
Tox *tox, NGC_EXT_CTX* ngc_ext_ctx,
|
|
||||||
uint32_t group_number,
|
|
||||||
uint32_t peer_number,
|
|
||||||
uint8_t transfer_id,
|
|
||||||
size_t data_offset,
|
|
||||||
const uint8_t* data, size_t data_size
|
|
||||||
) {
|
|
||||||
// get group id
|
|
||||||
_GroupKey g_id{};
|
|
||||||
{ // TODO: error
|
|
||||||
tox_group_get_chat_id(tox, group_number, g_id.data.data(), nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& group = ngc_ext_ctx->ngc_hs1_ctx->history[g_id];
|
|
||||||
|
|
||||||
//auto& pending = group.peers[peer_key].pending;
|
|
||||||
// get based on transfer_id
|
|
||||||
if (!group.transfers.count(std::make_pair(peer_number, transfer_id))) {
|
|
||||||
if (data_offset != 0) {
|
|
||||||
fprintf(stderr, "!! got stray tf data from %d tid:%d\n", peer_number, transfer_id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// new transfer?
|
|
||||||
fprintf(stderr, "!! got transfer from %d tid:%d\n", peer_number, transfer_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// add data to tmp buffer
|
|
||||||
// TODO: data done?
|
|
||||||
}
|
|
||||||
|
|
||||||
#define _HS1_HAVE(x, error) if ((length - curser) < (x)) { error; }
|
#define _HS1_HAVE(x, error) if ((length - curser) < (x)) { error; }
|
||||||
|
|
||||||
void _handle_HS1_REQUEST_LAST_IDS(
|
void _handle_HS1_REQUEST_LAST_IDS(
|
||||||
|
11
ngc_hs1.hpp
11
ngc_hs1.hpp
@ -51,17 +51,6 @@ struct NGC_HS1 {
|
|||||||
|
|
||||||
struct Group {
|
struct Group {
|
||||||
std::map<_PeerKey, Peer> peers;
|
std::map<_PeerKey, Peer> peers;
|
||||||
|
|
||||||
struct FileTransfers {
|
|
||||||
//uint32_t peer_number; // the peer we requested the message from
|
|
||||||
float time_since_ft_activity {0.f};
|
|
||||||
_PeerKey msg_peer;
|
|
||||||
uint32_t msg_id;
|
|
||||||
std::vector<uint8_t> recv_buffer; // message gets dumped into here
|
|
||||||
};
|
|
||||||
// key: peer_number + transfer_id
|
|
||||||
std::map<std::pair<uint32_t, uint8_t>, FileTransfers> transfers;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::map<_GroupKey, Group> history;
|
std::map<_GroupKey, Group> history;
|
||||||
|
Reference in New Issue
Block a user