mirror of
https://github.com/markqvist/reticulum-cpp
synced 2026-08-12 18:35:00 -04:00
Changed all time references to use decimal seconds to match Python reference implementation. Fixed memory issues caused by storing references to objects instead of copies. More implementation of Transport logic. This is the first build that fully implements end-to-end path finding and routing.
73 lines
No EOL
1.7 KiB
C++
73 lines
No EOL
1.7 KiB
C++
#pragma once
|
|
|
|
#include "Destination.h"
|
|
#include "Bytes.h"
|
|
#include "Type.h"
|
|
|
|
#include <memory>
|
|
|
|
namespace RNS {
|
|
|
|
class Packet;
|
|
|
|
class Link {
|
|
|
|
public:
|
|
class Callbacks {
|
|
public:
|
|
typedef void (*established)(Link *link);
|
|
typedef void (*closed)(Link *link);
|
|
};
|
|
|
|
public:
|
|
Link(Type::NoneConstructor none) {
|
|
mem("Link NONE object created");
|
|
}
|
|
Link(const Link& link) : _object(link._object) {
|
|
mem("Link object copy created");
|
|
}
|
|
Link(const Destination& destination);
|
|
virtual ~Link(){
|
|
mem("Link object destroyed");
|
|
}
|
|
|
|
inline Link& operator = (const Link& link) {
|
|
_object = link._object;
|
|
return *this;
|
|
}
|
|
inline operator bool() const {
|
|
return _object.get() != nullptr;
|
|
}
|
|
inline bool operator < (const Link& link) const {
|
|
return _object.get() < link._object.get();
|
|
}
|
|
|
|
public:
|
|
void set_link_id(const Packet& packet);
|
|
void receive(const Packet& packet);
|
|
|
|
// getters/setters
|
|
inline const Destination& destination() const { assert(_object); return _object->_destination; }
|
|
inline const Bytes& link_id() const { assert(_object); return _object->_link_id; }
|
|
inline const Bytes& hash() const { assert(_object); return _object->_hash; }
|
|
inline Type::Link::status status() const { assert(_object); return _object->_status; }
|
|
|
|
inline std::string toString() const { assert(_object); return "{Link: unknown}"; }
|
|
|
|
private:
|
|
class Object {
|
|
public:
|
|
Object(const Destination& destination) : _destination(destination) {}
|
|
virtual ~Object() {}
|
|
private:
|
|
Destination _destination = {Type::NONE};
|
|
Bytes _link_id;
|
|
Bytes _hash;
|
|
Type::Link::status _status = Type::Link::PENDING;
|
|
friend class Link;
|
|
};
|
|
std::shared_ptr<Object> _object;
|
|
|
|
};
|
|
|
|
} |