Finish data encapsulation
This commit is contained in:
parent
aced19e374
commit
d5c57ad133
5 changed files with 28 additions and 24 deletions
|
@ -114,10 +114,10 @@ void context_t::run(int argc, char *argv[]) {
|
||||||
nodes.push_back(node3);
|
nodes.push_back(node3);
|
||||||
|
|
||||||
gmrf_addr_t addr1 = {{1}}, addr2 = {{2}}, addr3 = {{3}}, addr4 = {{4}};
|
gmrf_addr_t addr1 = {{1}}, addr2 = {{2}}, addr3 = {{3}}, addr4 = {{4}};
|
||||||
add_iface(node1, net0, "mmss0", &addr1);
|
iface_t::add(node1, net0, "mmss0", &addr1);
|
||||||
add_iface(node2, net0, "mmss0", &addr2);
|
iface_t::add(node2, net0, "mmss0", &addr2);
|
||||||
add_iface(node2, net1, "mmss1", &addr3);
|
iface_t::add(node2, net1, "mmss1", &addr3);
|
||||||
add_iface(node3, net1, "mmss1", &addr4);
|
iface_t::add(node3, net1, "mmss1", &addr4);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (now() > 10000000)
|
if (now() > 10000000)
|
||||||
|
|
|
@ -34,13 +34,13 @@
|
||||||
|
|
||||||
namespace MMSS {
|
namespace MMSS {
|
||||||
|
|
||||||
void add_iface(const std::shared_ptr<node_t> &node, const std::shared_ptr<network_t> &net, const std::string &name, const gmrf_addr_t *address) {
|
std::shared_ptr<iface_t> iface_t::add(const std::shared_ptr<node_t> &node, const std::shared_ptr<network_t> &net, const std::string &name, const gmrf_addr_t *address) {
|
||||||
std::shared_ptr<iface_t> iface = std::make_shared<iface_t>(node.get(), net.get(), name, address);
|
std::shared_ptr<iface_t> iface = std::shared_ptr<iface_t>(new iface_t(node.get(), net.get(), name, address));
|
||||||
|
|
||||||
node->interfaces.push_back(iface);
|
|
||||||
net->interfaces.push_back(iface);
|
|
||||||
|
|
||||||
|
net->add_iface(iface);
|
||||||
node->add_iface(iface);
|
node->add_iface(iface);
|
||||||
|
|
||||||
|
return iface;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,10 +44,10 @@ private:
|
||||||
|
|
||||||
void enqueue(context_t *mmss, const std::shared_ptr<iface_t> &dest, const void *data, size_t len);
|
void enqueue(context_t *mmss, const std::shared_ptr<iface_t> &dest, const void *data, size_t len);
|
||||||
|
|
||||||
public:
|
|
||||||
iface_t(node_t *node0, network_t *net0, const std::string &name0, const gmrf_addr_t *address0)
|
iface_t(node_t *node0, network_t *net0, const std::string &name0, const gmrf_addr_t *address0)
|
||||||
: node(node0), net(net0), name(name0), address(*address0) {}
|
: node(node0), net(net0), name(name0), address(*address0) {}
|
||||||
|
|
||||||
|
public:
|
||||||
node_t* get_node() const {
|
node_t* get_node() const {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -71,8 +71,8 @@ public:
|
||||||
void send_bc(const void *data, size_t len) {
|
void send_bc(const void *data, size_t len) {
|
||||||
net->send_bc(data, len, this);
|
net->send_bc(data, len, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::shared_ptr<iface_t> add(const std::shared_ptr<node_t> &node, const std::shared_ptr<network_t> &net, const std::string &name, const gmrf_addr_t *address);
|
||||||
};
|
};
|
||||||
|
|
||||||
void add_iface(const std::shared_ptr<node_t> &node, const std::shared_ptr<network_t> &net, const std::string &name, const gmrf_addr_t *address);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
|
|
||||||
#include "types.hpp"
|
#include "types.hpp"
|
||||||
|
|
||||||
#include <list>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
|
||||||
namespace MMSS {
|
namespace MMSS {
|
||||||
|
@ -37,16 +37,19 @@ namespace MMSS {
|
||||||
class network_t : public nocopy_t {
|
class network_t : public nocopy_t {
|
||||||
private:
|
private:
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
size_t mtu;
|
size_t mtu;
|
||||||
|
|
||||||
|
std::unordered_set<std::shared_ptr<iface_t>> interfaces;
|
||||||
|
|
||||||
void enqueue(const void *data, size_t len, const iface_t *src_iface, const std::shared_ptr<iface_t> &dest_iface);
|
void enqueue(const void *data, size_t len, const iface_t *src_iface, const std::shared_ptr<iface_t> &dest_iface);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::list<std::shared_ptr<iface_t>> interfaces;
|
|
||||||
|
|
||||||
network_t(const std::string &name0) : name(name0), mtu(1500) {}
|
network_t(const std::string &name0) : name(name0), mtu(1500) {}
|
||||||
|
|
||||||
|
void add_iface(const std::shared_ptr<iface_t> &iface) {
|
||||||
|
interfaces.insert(iface);
|
||||||
|
}
|
||||||
|
|
||||||
const std::string& get_name() const {
|
const std::string& get_name() const {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +60,6 @@ public:
|
||||||
|
|
||||||
void send(const void *data, size_t len, const iface_t *src_iface, const gmrf_addr_t *dest);
|
void send(const void *data, size_t len, const iface_t *src_iface, const gmrf_addr_t *dest);
|
||||||
void send_bc(const void *data, size_t len, const iface_t *src_iface);
|
void send_bc(const void *data, size_t len, const iface_t *src_iface);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,9 @@
|
||||||
#include "iface.hpp"
|
#include "iface.hpp"
|
||||||
#include "protocol.hpp"
|
#include "protocol.hpp"
|
||||||
|
|
||||||
#include <list>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
|
||||||
namespace MMSS {
|
namespace MMSS {
|
||||||
|
@ -49,18 +49,24 @@ private:
|
||||||
unsigned rand_seed;
|
unsigned rand_seed;
|
||||||
std::shared_ptr<const protocol_t> proto;
|
std::shared_ptr<const protocol_t> proto;
|
||||||
|
|
||||||
|
std::unordered_set<std::shared_ptr<iface_t>> interfaces;
|
||||||
|
|
||||||
node_t(context_t *mmss0, const std::string &name0, unsigned rand_seed0, const std::shared_ptr<const protocol_t> &proto0) :
|
node_t(context_t *mmss0, const std::string &name0, unsigned rand_seed0, const std::shared_ptr<const protocol_t> &proto0) :
|
||||||
mmss(mmss0), name(name0), gmrf_ctx(nullptr), rand_seed(rand_seed0), proto(proto0) {
|
mmss(mmss0), name(name0), gmrf_ctx(nullptr), rand_seed(rand_seed0), proto(proto0) {
|
||||||
}
|
}
|
||||||
public:
|
|
||||||
std::list<std::shared_ptr<iface_t>> interfaces;
|
|
||||||
|
|
||||||
|
public:
|
||||||
static std::shared_ptr<node_t> create(context_t *mmss, const std::string &name, unsigned rand_seed, const std::shared_ptr<const protocol_t> &proto) {
|
static std::shared_ptr<node_t> create(context_t *mmss, const std::string &name, unsigned rand_seed, const std::shared_ptr<const protocol_t> &proto) {
|
||||||
auto node = std::shared_ptr<node_t>(new node_t(mmss, name, rand_seed, proto));
|
auto node = std::shared_ptr<node_t>(new node_t(mmss, name, rand_seed, proto));
|
||||||
node->gmrf_ctx = proto->init(node.get());
|
node->gmrf_ctx = proto->init(node.get());
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add_iface(const std::shared_ptr<iface_t> &iface) {
|
||||||
|
interfaces.insert(iface);
|
||||||
|
proto->add_iface(this, gmrf_ctx, iface.get());
|
||||||
|
}
|
||||||
|
|
||||||
context_t* get_context() const {
|
context_t* get_context() const {
|
||||||
return mmss;
|
return mmss;
|
||||||
}
|
}
|
||||||
|
@ -73,10 +79,6 @@ public:
|
||||||
return rand_r(&rand_seed);
|
return rand_r(&rand_seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_iface(const std::shared_ptr<iface_t> &iface) {
|
|
||||||
proto->add_iface(this, gmrf_ctx, iface.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_packet(const std::shared_ptr<iface_t> &iface, const gmrf_addr_t *source, const void *data, size_t len) {
|
void handle_packet(const std::shared_ptr<iface_t> &iface, const gmrf_addr_t *source, const void *data, size_t len) {
|
||||||
proto->handle_packet(this, gmrf_ctx, iface.get(), source, data, len);
|
proto->handle_packet(this, gmrf_ctx, iface.get(), source, data, len);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue