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

Start p2p net implementation

parent d008509d
No related branches found
No related tags found
No related merge requests found
#ifndef _FTL_P2P_RM_PROTOCOL_HPP_
#define _FTL_P2P_RM_PROTOCOL_HPP_
/* To get the service space for p2p */
#include <ftl/net/protocol.hpp>
#define P2P_SYNC (FTL_PROTOCOL_P2P + 1)
#define P2P_REQUESTOWNERSHIP (FTL_PROTOCOL_P2P + 2)
#define P2P_FINDOWNER (FTL_PROTOCOL_P2P + 3)
#define P2P_NOTIFYOWNERSHIP (FTL_PROTOCOL_P2P + 4)
#define P2P_URISEARCH (FTL_PROTOCOL_P2P + 5)
#define P2P_PEERSEARCH (FTL_PROTOCOL_P2P + 6)
#endif // _FTL_P2P_RM_PROTOCOL_HPP_
#include <memory.h>
#include <ftl/net.hpp>
#include "ftl/p2p-rm/blob.hpp"
#define MEMORY_SYNC 0x1000
struct Header {
uint32_t blobid;
uint32_t offset;
uint32_t size;
};
void ftl::rm::Blob::sync(size_t offset, size_t size) {
// Sanity check
if (offset + size > size_) throw -1;
// TODO Delay send to collate many write operations?
if (sockets_.size() > 0) {
Header header{blobid_,static_cast<uint32_t>(offset),static_cast<uint32_t>(size)};
// If local, write direct to data_, otherwise send over network
for (auto s : sockets_) {
// Send over network
s->send2(MEMORY_SYNC, std::string((const char*)&header,sizeof(header)),
std::string(&data_[offset],size));
}
}
}
/*void ftl::rm::Blob::write(size_t offset, const char *data, size_t size) {
// Sanity check
......
#include "ftl/p2p-rm.hpp"
#include "ftl/p2p-rm/blob.hpp"
#include "ftl/p2p-rm/protocol.hpp"
#include <ftl/uri.hpp>
#include <ftl/net.hpp>
#include <map>
#include <string>
......@@ -13,6 +17,29 @@ void ftl::rm::reset() {
blobs.clear();
}
struct SyncHeader {
uint32_t blobid;
uint32_t offset;
uint32_t size;
};
void ftl::rm::_sync(const ftl::rm::Blob &blob, size_t offset, size_t size) {
// Sanity check
if (offset + size > size_) throw -1;
// TODO Delay send to collate many write operations?
if (blob.sockets_.size() > 0) {
SyncHeader header{blob.blobid_,static_cast<uint32_t>(offset),static_cast<uint32_t>(size)};
for (auto s : blob.sockets_) {
// Send over network
s->send2(P2P_SYNC, std::string((const char*)&header,sizeof(header)),
std::string(&data_[offset],size));
}
}
}
ftl::rm::Blob *ftl::rm::_lookup(const char *uri) {
URI u(uri);
if (!u.isValid()) return NULL;
......
#include "catch.hpp"
#include <ftl/p2p-rm.hpp>
#include <vector>
// --- Mock Socket Send
static std::vector<uint32_t> msgs;
int ftl::net::raw::Socket::send2(uint32_t service, const std::string &data1, const std::string &data2) {
msgs.push_back(service);
return 0;
}
......@@ -73,5 +77,12 @@ SCENARIO( "Getting a read_ref", "[get]" ) {
REQUIRE( r.pointer().is_local() );
REQUIRE( r == 89 );
}
GIVEN( "a valid URI to remote memory" ) {
const auto r = ftl::rm::getReadable<int>("ftl://uti.fi/memory/remote0");
REQUIRE( r.is_valid() );
REQUIRE( !r.pointer().is_local() );
REQUIRE( r == 888 );
}
}
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