Compare commits
3 Commits
2e6b15e4ad
...
37b92f67c8
Author | SHA1 | Date | |
---|---|---|---|
37b92f67c8 | |||
01c892df8c | |||
6eb5826616 |
@ -44,8 +44,10 @@ target_link_libraries(solanaceae_ngcft1 PUBLIC
|
||||
########################################
|
||||
|
||||
add_library(solanaceae_ngchs2
|
||||
./solanaceae/ngc_hs2/ngc_hs2.hpp
|
||||
./solanaceae/ngc_hs2/ngc_hs2.cpp
|
||||
./solanaceae/ngc_hs2/ngc_hs2_send.hpp
|
||||
./solanaceae/ngc_hs2/ngc_hs2_send.cpp
|
||||
./solanaceae/ngc_hs2/ngc_hs2_recv.hpp
|
||||
./solanaceae/ngc_hs2/ngc_hs2_recv.cpp
|
||||
)
|
||||
target_include_directories(solanaceae_ngchs2 PUBLIC .)
|
||||
target_compile_features(solanaceae_ngchs2 PUBLIC cxx_std_17)
|
||||
|
@ -12,7 +12,7 @@ struct FlowOnly : public CCAI {
|
||||
public: // config
|
||||
static constexpr float RTT_EMA_ALPHA = 0.001f; // might need change over time
|
||||
static constexpr float RTT_UP_MAX = 3.0f; // how much larger a delay can be to be taken into account
|
||||
static constexpr float RTT_MAX = 2.f; // 2 sec is probably too much
|
||||
static constexpr float RTT_MAX = 2.f; // maybe larger for tunneled connections
|
||||
|
||||
protected:
|
||||
// initialize to low value, will get corrected very fast
|
||||
|
@ -625,7 +625,8 @@ bool NGCFT1::onEvent(const Events::NGCEXT_ft1_data& e) {
|
||||
|
||||
// TODO: keep around for remote timeout + delay + offset, so we can be sure all acks where received
|
||||
// or implement a dedicated finished that needs to be acked
|
||||
transfer.finishing_timer = 0.75f; // TODO: we are receiving, we dont know delay
|
||||
//transfer.finishing_timer = 0.75f; // TODO: we are receiving, we dont know delay
|
||||
transfer.finishing_timer = FlowOnly::RTT_MAX;
|
||||
|
||||
dispatch(
|
||||
NGCFT1_Event::recv_done,
|
||||
|
@ -1165,6 +1165,13 @@ bool SHA1_NGCFT1::onEvent(const Events::NGCFT1_recv_message& e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: make perms go though contacts
|
||||
// TODO: consider temporal component? not here, here is now
|
||||
if (!_tcm.groupPeerCanSpeak(e.group_number, e.peer_number)) {
|
||||
// peer has not the permission to speak, discard
|
||||
return false; // return true?
|
||||
}
|
||||
|
||||
uint64_t ts = Message::getTimeMS();
|
||||
|
||||
const auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number);
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "./ngc_hs2.hpp"
|
||||
#include "./ngc_hs2_recv.hpp"
|
||||
|
||||
#include <solanaceae/tox_contacts/tox_contact_model2.hpp>
|
||||
|
||||
NGCHS2::NGCHS2(
|
||||
NGCHS2Recv::NGCHS2Recv(
|
||||
Contact3Registry& cr,
|
||||
RegistryMessageModelI& rmm,
|
||||
ToxContactModel2& tcm,
|
||||
@ -29,7 +29,6 @@ NGCHS2::NGCHS2(
|
||||
;
|
||||
|
||||
_nftep_sr
|
||||
.subscribe(NGCFT1_Event::recv_init)
|
||||
.subscribe(NGCFT1_Event::recv_request)
|
||||
.subscribe(NGCFT1_Event::recv_init)
|
||||
.subscribe(NGCFT1_Event::recv_data)
|
||||
@ -39,26 +38,26 @@ NGCHS2::NGCHS2(
|
||||
;
|
||||
}
|
||||
|
||||
NGCHS2::~NGCHS2(void) {
|
||||
NGCHS2Recv::~NGCHS2Recv(void) {
|
||||
}
|
||||
|
||||
float NGCHS2::iterate(float delta) {
|
||||
float NGCHS2Recv::iterate(float delta) {
|
||||
return 1000.f;
|
||||
}
|
||||
|
||||
bool NGCHS2::onEvent(const Message::Events::MessageConstruct&) {
|
||||
bool NGCHS2Recv::onEvent(const Message::Events::MessageConstruct&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NGCHS2::onEvent(const Message::Events::MessageUpdated&) {
|
||||
bool NGCHS2Recv::onEvent(const Message::Events::MessageUpdated&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NGCHS2::onEvent(const Message::Events::MessageDestory&) {
|
||||
bool NGCHS2Recv::onEvent(const Message::Events::MessageDestory&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NGCHS2::onEvent(const Events::NGCFT1_recv_request& e) {
|
||||
bool NGCHS2Recv::onEvent(const Events::NGCFT1_recv_request& e) {
|
||||
if (
|
||||
e.file_kind != NGCFT1_file_kind::HS2_INFO_RANGE_TIME &&
|
||||
e.file_kind != NGCFT1_file_kind::HS2_SINGLE_MESSAGE
|
||||
@ -69,7 +68,7 @@ bool NGCHS2::onEvent(const Events::NGCFT1_recv_request& e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NGCHS2::onEvent(const Events::NGCFT1_recv_init& e) {
|
||||
bool NGCHS2Recv::onEvent(const Events::NGCFT1_recv_init& e) {
|
||||
if (
|
||||
e.file_kind != NGCFT1_file_kind::HS2_INFO_RANGE_TIME &&
|
||||
e.file_kind != NGCFT1_file_kind::HS2_SINGLE_MESSAGE
|
||||
@ -80,23 +79,23 @@ bool NGCHS2::onEvent(const Events::NGCFT1_recv_init& e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NGCHS2::onEvent(const Events::NGCFT1_recv_data&) {
|
||||
bool NGCHS2Recv::onEvent(const Events::NGCFT1_recv_data&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NGCHS2::onEvent(const Events::NGCFT1_send_data&) {
|
||||
bool NGCHS2Recv::onEvent(const Events::NGCFT1_send_data&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NGCHS2::onEvent(const Events::NGCFT1_recv_done&) {
|
||||
bool NGCHS2Recv::onEvent(const Events::NGCFT1_recv_done&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NGCHS2::onEvent(const Events::NGCFT1_send_done&) {
|
||||
bool NGCHS2Recv::onEvent(const Events::NGCFT1_send_done&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NGCHS2::onToxEvent(const Tox_Event_Group_Peer_Join* e) {
|
||||
bool NGCHS2Recv::onToxEvent(const Tox_Event_Group_Peer_Join* e) {
|
||||
const auto group_number = tox_event_group_peer_join_get_group_number(e);
|
||||
const auto peer_number = tox_event_group_peer_join_get_peer_id(e);
|
||||
|
||||
@ -108,7 +107,7 @@ bool NGCHS2::onToxEvent(const Tox_Event_Group_Peer_Join* e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NGCHS2::onToxEvent(const Tox_Event_Group_Peer_Exit* e) {
|
||||
bool NGCHS2Recv::onToxEvent(const Tox_Event_Group_Peer_Exit* e) {
|
||||
return false;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ class ToxContactModel2;
|
||||
// deal with a queue, and delay (at least 1sec, 3-10sec after a peer con change)
|
||||
// or we always overrequest (eg 48h), and only fetch messages in, or close to range
|
||||
|
||||
class NGCHS2 : public RegistryMessageModelEventI, public ToxEventI, public NGCFT1EventI {
|
||||
class NGCHS2Recv : public RegistryMessageModelEventI, public ToxEventI, public NGCFT1EventI {
|
||||
Contact3Registry& _cr;
|
||||
RegistryMessageModelI& _rmm;
|
||||
RegistryMessageModelI::SubscriptionReference _rmm_sr;
|
||||
@ -47,7 +47,7 @@ class NGCHS2 : public RegistryMessageModelEventI, public ToxEventI, public NGCFT
|
||||
static const int64_t _max_time_into_past_default {60}; // s
|
||||
|
||||
public:
|
||||
NGCHS2(
|
||||
NGCHS2Recv(
|
||||
Contact3Registry& cr,
|
||||
RegistryMessageModelI& rmm,
|
||||
ToxContactModel2& tcm,
|
||||
@ -55,7 +55,7 @@ class NGCHS2 : public RegistryMessageModelEventI, public ToxEventI, public NGCFT
|
||||
NGCFT1& nf
|
||||
);
|
||||
|
||||
~NGCHS2(void);
|
||||
~NGCHS2Recv(void);
|
||||
|
||||
float iterate(float delta);
|
||||
|
143
solanaceae/ngc_hs2/ngc_hs2_send.cpp
Normal file
143
solanaceae/ngc_hs2/ngc_hs2_send.cpp
Normal file
@ -0,0 +1,143 @@
|
||||
#include "./ngc_hs2_send.hpp"
|
||||
|
||||
#include <solanaceae/util/span.hpp>
|
||||
|
||||
#include <solanaceae/tox_contacts/tox_contact_model2.hpp>
|
||||
|
||||
#include <solanaceae/contact/components.hpp>
|
||||
|
||||
// https://www.youtube.com/watch?v=AdAqsgga3qo
|
||||
|
||||
NGCHS2Send::NGCHS2Send(
|
||||
Contact3Registry& cr,
|
||||
RegistryMessageModelI& rmm,
|
||||
ToxContactModel2& tcm,
|
||||
NGCFT1& nft
|
||||
) :
|
||||
_cr(cr),
|
||||
_rmm(rmm),
|
||||
_tcm(tcm),
|
||||
_nft(nft),
|
||||
_nftep_sr(_nft.newSubRef(this))
|
||||
{
|
||||
_nftep_sr
|
||||
.subscribe(NGCFT1_Event::recv_request)
|
||||
//.subscribe(NGCFT1_Event::recv_init) // we only send init
|
||||
//.subscribe(NGCFT1_Event::recv_data) // we only send data
|
||||
.subscribe(NGCFT1_Event::send_data)
|
||||
//.subscribe(NGCFT1_Event::recv_done)
|
||||
.subscribe(NGCFT1_Event::send_done)
|
||||
;
|
||||
}
|
||||
|
||||
NGCHS2Send::~NGCHS2Send(void) {
|
||||
}
|
||||
|
||||
float NGCHS2Send::iterate(float delta) {
|
||||
|
||||
// work request queue
|
||||
// check if already running, discard
|
||||
|
||||
return 1000.f;
|
||||
}
|
||||
|
||||
void NGCHS2Send::handleRange(Contact3Handle c, const Events::NGCFT1_recv_request& e) {
|
||||
ByteSpan fid{e.file_id, e.file_id_size};
|
||||
// parse
|
||||
// - ts start
|
||||
// - ts end
|
||||
|
||||
// dedupe insert into queue
|
||||
}
|
||||
|
||||
void NGCHS2Send::handleSingleMessage(Contact3Handle c, const Events::NGCFT1_recv_request& e) {
|
||||
ByteSpan fid{e.file_id, e.file_id_size};
|
||||
if (fid.size != 32+sizeof(uint32_t)+sizeof(uint64_t)) {
|
||||
// error
|
||||
return;
|
||||
}
|
||||
|
||||
// parse
|
||||
// - ppk
|
||||
// TOX_GROUP_PEER_PUBLIC_KEY_SIZE (32)
|
||||
ByteSpan ppk{fid.ptr, 32};
|
||||
|
||||
// - mid
|
||||
//static_assert(sizeof(Tox_Group_Message_Id) == sizeof(uint32_t));
|
||||
ByteSpan mid_bytes{fid.ptr+ppk.size, sizeof(uint32_t)};
|
||||
|
||||
// - ts
|
||||
// uint64_t (seconds? we dont want milliseconds
|
||||
ByteSpan ts_bytes{mid_bytes.ptr+mid_bytes.size, sizeof(uint64_t)};
|
||||
|
||||
// file content
|
||||
// - message type (text/textaction/file(ft1sha1))
|
||||
// - if text/textaction
|
||||
// - text (string)
|
||||
// - else if file
|
||||
// - file type
|
||||
// - file id
|
||||
|
||||
// for queue, we need group, peer, msg_ppk, msg_mid, msg_ts
|
||||
|
||||
// dedupe insert into queue
|
||||
}
|
||||
|
||||
bool NGCHS2Send::onEvent(const Message::Events::MessageConstruct&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NGCHS2Send::onEvent(const Message::Events::MessageUpdated&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NGCHS2Send::onEvent(const Message::Events::MessageDestory&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NGCHS2Send::onEvent(const Events::NGCFT1_recv_request& e) {
|
||||
if (
|
||||
e.file_kind != NGCFT1_file_kind::HS2_INFO_RANGE_TIME &&
|
||||
e.file_kind != NGCFT1_file_kind::HS2_SINGLE_MESSAGE
|
||||
) {
|
||||
return false; // not for us
|
||||
}
|
||||
|
||||
// TODO: when is it done from queue?
|
||||
|
||||
auto c = _tcm.getContactGroupPeer(e.group_number, e.peer_number);
|
||||
if (!c) {
|
||||
return false; // how
|
||||
}
|
||||
|
||||
// is other peer allowed to make requests
|
||||
//bool quick_allow {false};
|
||||
bool quick_allow {true}; // HACK: disable all restrictions for this early test
|
||||
// TODO: quick deny?
|
||||
{
|
||||
// - tagged as weakself
|
||||
if (!quick_allow && c.all_of<Contact::Components::TagSelfWeak>()) {
|
||||
quick_allow = true;
|
||||
}
|
||||
|
||||
// - sub perm level??
|
||||
// - out of max time range (ft specific, not a quick_allow)
|
||||
}
|
||||
|
||||
if (e.file_kind == NGCFT1_file_kind::HS2_INFO_RANGE_TIME) {
|
||||
handleRange(c, e);
|
||||
} else if (e.file_kind == NGCFT1_file_kind::HS2_SINGLE_MESSAGE) {
|
||||
handleSingleMessage(c, e);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NGCHS2Send::onEvent(const Events::NGCFT1_send_data&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NGCHS2Send::onEvent(const Events::NGCFT1_send_done&) {
|
||||
return false;
|
||||
}
|
||||
|
56
solanaceae/ngc_hs2/ngc_hs2_send.hpp
Normal file
56
solanaceae/ngc_hs2/ngc_hs2_send.hpp
Normal file
@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include <solanaceae/toxcore/tox_event_interface.hpp>
|
||||
|
||||
#include <solanaceae/contact/contact_model3.hpp>
|
||||
#include <solanaceae/message3/registry_message_model.hpp>
|
||||
|
||||
#include <solanaceae/ngc_ft1/ngcft1.hpp>
|
||||
|
||||
#include <entt/container/dense_map.hpp>
|
||||
|
||||
// fwd
|
||||
class ToxContactModel2;
|
||||
|
||||
// limit to 2 uploads per peer simultaniously
|
||||
|
||||
class NGCHS2Send : public RegistryMessageModelEventI, public NGCFT1EventI {
|
||||
Contact3Registry& _cr;
|
||||
RegistryMessageModelI& _rmm;
|
||||
ToxContactModel2& _tcm;
|
||||
NGCFT1& _nft;
|
||||
NGCFT1EventProviderI::SubscriptionReference _nftep_sr;
|
||||
|
||||
// open/running info requests (by c)
|
||||
|
||||
// open/running info responses (by c)
|
||||
|
||||
static const bool _only_send_self_observed {true};
|
||||
static const int64_t _max_time_into_past_default {60}; // s
|
||||
|
||||
public:
|
||||
NGCHS2Send(
|
||||
Contact3Registry& cr,
|
||||
RegistryMessageModelI& rmm,
|
||||
ToxContactModel2& tcm,
|
||||
NGCFT1& nf
|
||||
);
|
||||
|
||||
~NGCHS2Send(void);
|
||||
|
||||
float iterate(float delta);
|
||||
|
||||
void handleRange(Contact3Handle c, const Events::NGCFT1_recv_request&);
|
||||
void handleSingleMessage(Contact3Handle c, const Events::NGCFT1_recv_request&);
|
||||
|
||||
protected:
|
||||
bool onEvent(const Message::Events::MessageConstruct&) override;
|
||||
bool onEvent(const Message::Events::MessageUpdated&) override;
|
||||
bool onEvent(const Message::Events::MessageDestory&) override;
|
||||
|
||||
protected:
|
||||
bool onEvent(const Events::NGCFT1_recv_request&) override;
|
||||
bool onEvent(const Events::NGCFT1_send_data&) override;
|
||||
bool onEvent(const Events::NGCFT1_send_done&) override;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user