Skip to content
Snippets Groups Projects
Commit c54a41be authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Switch to weaker protocol handshake mechanism

parent 030e5119
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,10 @@ This monorepo contains all elements of the FTL software system. ...@@ -4,7 +4,10 @@ This monorepo contains all elements of the FTL software system.
* p2p-remote-array : Access 2D memory arrays on other machines in P2P group * p2p-remote-array : Access 2D memory arrays on other machines in P2P group
* fabric : C++ library implementing the neural fabric * fabric : C++ library implementing the neural fabric
* fabric-modules : custom native fabric relations * fabric-js : Node.js bindings for C++ fabric
* fabric-js : Node.js bindings for fabric * fabric-js-modules : Additional fabric-js based native and non-native components
* peer-node : P2P node.js application providing a web-service interface
* front-end : Client side FTL code
* www : FTL Website
The architecture relies on NodeJS with C++ native addons for processing. The architecture relies on NodeJS with C++ native addons for processing.
...@@ -172,6 +172,7 @@ class Socket { ...@@ -172,6 +172,7 @@ class Socket {
std::string uri_; std::string uri_;
std::string peerid_; std::string peerid_;
std::string remote_proto_;
Protocol *proto_; Protocol *proto_;
......
...@@ -111,11 +111,21 @@ Listener::~Listener() { ...@@ -111,11 +111,21 @@ Listener::~Listener() {
} }
void Listener::connection(shared_ptr<Socket> &s) { void Listener::connection(shared_ptr<Socket> &s) {
Handshake hs1;
hs1.magic = ftl::net::MAGIC;
hs1.name_size = 0;
if (default_proto_) { if (default_proto_) {
s->setProtocol(default_proto_); s->setProtocol(default_proto_);
hs1.proto_size = default_proto_->id().size();
s->send(FTL_PROTOCOL_HS1, hs1, default_proto_->id());
} else { } else {
s->setProtocol(NULL); s->setProtocol(NULL);
hs1.proto_size = 0;
s->send(FTL_PROTOCOL_HS1, hs1);
} }
LOG(INFO) << "Handshake initiated with " << s->getURI();
for (auto h : handler_connect_) h(s); for (auto h : handler_connect_) h(s);
} }
......
...@@ -211,20 +211,23 @@ void Socket::setProtocol(Protocol *p) { ...@@ -211,20 +211,23 @@ void Socket::setProtocol(Protocol *p) {
if (proto_ == p) return; if (proto_ == p) return;
if (proto_ && proto_->id() == p->id()) return; if (proto_ && proto_->id() == p->id()) return;
if (remote_proto_ != "") {
Handshake hs1;
hs1.magic = ftl::net::MAGIC;
hs1.name_size = 0;
hs1.proto_size = p->id().size();
send(FTL_PROTOCOL_HS1, hs1, p->id());
LOG(INFO) << "Handshake initiated with " << uri_;
}
proto_ = p; proto_ = p;
Handshake hs1;
hs1.magic = ftl::net::MAGIC;
hs1.name_size = 0;
hs1.proto_size = p->id().size();
send(FTL_PROTOCOL_HS1, hs1, p->id());
LOG(INFO) << "Handshake initiated with " << uri_;
} else { } else {
Handshake hs1; /*Handshake hs1;
hs1.magic = ftl::net::MAGIC; hs1.magic = ftl::net::MAGIC;
hs1.name_size = 0; hs1.name_size = 0;
hs1.proto_size = 0; hs1.proto_size = 0;
send(FTL_PROTOCOL_HS1, hs1); send(FTL_PROTOCOL_HS1, hs1);
LOG(INFO) << "Handshake initiated with " << uri_; LOG(INFO) << "Handshake initiated with " << uri_;*/
} }
} }
...@@ -331,14 +334,8 @@ void Socket::handshake1() { ...@@ -331,14 +334,8 @@ void Socket::handshake1() {
if (header.proto_size > 0) read(protouri,header.proto_size); if (header.proto_size > 0) read(protouri,header.proto_size);
if (protouri.size() > 0) { if (protouri.size() > 0) {
auto proto = Protocol::find(protouri); remote_proto_ = protouri;
if (proto == NULL) { // TODO Validate protocols with local protocol?
LOG(ERROR) << "Protocol (" << protouri << ") not found during handshake for " << uri_;
close();
return;
} else {
proto_ = proto;
}
} }
send(FTL_PROTOCOL_HS2); // TODO Counterpart protocol. send(FTL_PROTOCOL_HS2); // TODO Counterpart protocol.
......
...@@ -211,6 +211,7 @@ TEST_CASE("Net Integration", "[integrate]") { ...@@ -211,6 +211,7 @@ TEST_CASE("Net Integration", "[integrate]") {
l->onConnection([&s1](auto &s) { s1 = s; }); l->onConnection([&s1](auto &s) { s1 = s; });
shared_ptr<Socket> s2 = ftl::net::connect("tcp://localhost:9000"); shared_ptr<Socket> s2 = ftl::net::connect("tcp://localhost:9000");
s2->setProtocol(&p);
REQUIRE( s2 != nullptr ); REQUIRE( s2 != nullptr );
ftl::net::wait([&s2]() { return s2->isConnected(); }); ftl::net::wait([&s2]() { return s2->isConnected(); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment