forstio/source/forstio/io_auth.h

54 lines
1.0 KiB
C++

#pragma once
#include "io.h"
namespace saw {
class peer {
public:
peer(const std::string &ident);
peer(std::string &&ident);
const std::string &identity() const;
private:
std::string identity_value_;
};
class authenticated_io_stream {
public:
// This is the easiest way to implement Authenticated streams.
// This is a simple pair of the stream and the peer.
own<io_stream> stream;
maybe<own<peer>> peer;
};
class authenticated_server {
public:
virtual ~authenticated_server() = default;
virtual conveyor<authenticated_io_stream> accept() = 0;
};
/**
* Authenticated Network class which provides a peer identity when connecting
*/
class authenticated_network {
public:
virtual ~authenticated_network() = default;
/**
* Connects to the provided address.
* Returns as soon as it is authenticated or fails
*/
virtual conveyor<authenticated_io_stream>
connect(network_address &address) = 0;
/**
* Creates a server listening for connections
*/
virtual own<authenticated_server> listen() = 0;
};
} // namespace saw