diff --git a/README.md b/README.md index 2efa5b69a6d195b3c12362e3c7b88bfa697cd20d..88324979890a2b18cd9c133423ae92a0e30a29e2 100644 --- a/README.md +++ b/README.md @@ -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 * fabric : C++ library implementing the neural fabric -* fabric-modules : custom native fabric relations -* fabric-js : Node.js bindings for fabric +* fabric-js : Node.js bindings for C++ 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. diff --git a/net/include/ftl/net/socket.hpp b/net/include/ftl/net/socket.hpp index 09d0852e30b09536931fedbae28915437cebd48d..96786e4fb6d4e45a5519a7321cee16328b185eaf 100644 --- a/net/include/ftl/net/socket.hpp +++ b/net/include/ftl/net/socket.hpp @@ -172,6 +172,7 @@ class Socket { std::string uri_; std::string peerid_; + std::string remote_proto_; Protocol *proto_; diff --git a/net/src/listener.cpp b/net/src/listener.cpp index c7cc7ed021e1e36d8b75296183efa356cc89cce8..6fd975d1b1ef82e850d029c17d2ee16d2733ea1b 100644 --- a/net/src/listener.cpp +++ b/net/src/listener.cpp @@ -111,11 +111,21 @@ Listener::~Listener() { } void Listener::connection(shared_ptr<Socket> &s) { + Handshake hs1; + hs1.magic = ftl::net::MAGIC; + hs1.name_size = 0; + if (default_proto_) { s->setProtocol(default_proto_); + hs1.proto_size = default_proto_->id().size(); + s->send(FTL_PROTOCOL_HS1, hs1, default_proto_->id()); } else { 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); } diff --git a/net/src/socket.cpp b/net/src/socket.cpp index d6765b1ecbbed88e3e57ad9f77b5dbd80dcb3c57..0eadd46ea0d4f1c68f545fc70b50c6b48face821 100644 --- a/net/src/socket.cpp +++ b/net/src/socket.cpp @@ -211,20 +211,23 @@ void Socket::setProtocol(Protocol *p) { if (proto_ == p) 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; - 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 { - Handshake hs1; + /*Handshake hs1; hs1.magic = ftl::net::MAGIC; hs1.name_size = 0; hs1.proto_size = 0; send(FTL_PROTOCOL_HS1, hs1); - LOG(INFO) << "Handshake initiated with " << uri_; + LOG(INFO) << "Handshake initiated with " << uri_;*/ } } @@ -331,14 +334,8 @@ void Socket::handshake1() { if (header.proto_size > 0) read(protouri,header.proto_size); if (protouri.size() > 0) { - auto proto = Protocol::find(protouri); - if (proto == NULL) { - LOG(ERROR) << "Protocol (" << protouri << ") not found during handshake for " << uri_; - close(); - return; - } else { - proto_ = proto; - } + remote_proto_ = protouri; + // TODO Validate protocols with local protocol? } send(FTL_PROTOCOL_HS2); // TODO Counterpart protocol. diff --git a/net/test/net_integration.cpp b/net/test/net_integration.cpp index 20b2c676028789402b2412c41f9143a2915ba416..86a478d8dab981f5f99b19f0d8a91212be787eac 100644 --- a/net/test/net_integration.cpp +++ b/net/test/net_integration.cpp @@ -211,6 +211,7 @@ TEST_CASE("Net Integration", "[integrate]") { l->onConnection([&s1](auto &s) { s1 = s; }); shared_ptr<Socket> s2 = ftl::net::connect("tcp://localhost:9000"); + s2->setProtocol(&p); REQUIRE( s2 != nullptr ); ftl::net::wait([&s2]() { return s2->isConnected(); });