#pragma once
#include "main.hpp"
#include "net.hpp"
#include "ssl.hpp"
#include <map>


class SSLStream {
    protected:
        class Buf { ///< simple, contiguous, growing buffer
            public:
                Buf();
                ~Buf();
                const unsigned char* buf;
                size_t len;

                void push(const unsigned char*, size_t);
                void pop(size_t);
        };

    private:
        Buf backlog[2]; ///< in case we need buffering for client [1] or upstream [0] side
        SSLSession sess;

    public:
        bool push(const packet_t&); ///< add/parse new captured data, prints to stdout
};


class Stream {
    private:
        typedef struct {
            conn_t pkt; ///< for collision detection
            uint32_t next_seq[2]; ///< expected upcoming seqnum
            SSLStream* stream;
        } entry_t;
        std::map<uint32_t, entry_t> streams;

    public:
        ~Stream();
        void push(const packet_t&);
};