/*
 * (c) 2005 Research Group Dr. Fuhrmann, University of Karlsruhe, Germany
 * All rights reserved.
 *
 * Author:
 *         Stefan Denk <denk@ira.uka.de>
 *
 * $Id: vidtrans.h,v 1.37 2005/12/27 12:12:33 kutzner Exp $
 *
 */

#ifndef _VIDTRANS_H_
#define _VIDTRANS_H_

#include "video_hash.h"

using namespace std;

string longtostr(long from, int base);
int startclient(void);
bool iframe(char* ptr); 

/// stores the information parsed from _transport, allowing a clientthread to connect to the respective server using tcp_connect.
struct transportaddress
{
	string protocol;
	string hostname;
	string port;
};

class ctasks;

/**
 * List of source addresses for each hash triple of a given task.
 * Idea: create a data structure that holds a source address for every (three) hash blocks.
 * This could hold added information like upstream speeds of the opposite side (could be published in the aggregation destination?).
 * When a task is executed, it first tries to fill this data structure from the list of gathered sources, then starts clients which download
 * either a triple or a larger slice.
 * These downloads could then be saved to a single file, using a more refined downloadstatus (describing every task, which could either
 * be a single hash value, a hash triple or more).
 */

/**
class sourcelistpertask
{
	private: 
		struct sourcelist_t
		{
			uchar hash[21];			// 160 bits for the hash block + trailing \n
			uint32_t length;		// 32 bits for the length of that block
			// uint32_t offset;		// 32 bits for the offset (where to store this block)
							// Note: if the entries are added in correct order, this entry is not needed!
			string sourceaddress;		// the source address (tcp://my.domain.com:port)
			uint32_t upstreamspeed;		// the source's upstream speed
		};
		vector<sourcelist_t> _sourcelist;	// make this a vector with one entry per hash block
		_sourcelist * current;			// pointer to the current entry
		
		struct minsrclist
		{
			uchar hash[21];
			uint32_t length;
			string sourceaddress;
		};
	public:
		_sourcelist * sourcecelistpertask()
		{
			_sourcelist * sl;
			sl = new _sourcelist;
			return sl;
		};
		void ~sourcelistpertask(_sourcelist * sl)
		{
			_sl->erase();
		};
		void sourcelistpertask::add(uchar hash[21], uint32_t length, string sourceaddress, uint32_t upstreamspeed)
		{
			_sourcelist.push_back(hash, length, sourceaddress, upstreamspeed);
		};
		/// replace an old hash value with a new hash value (return 0 if successful, -1 on error)
		int sourcelistpertask::replace(uchar oldhash[21], uchar newhash[21]);
		/// insert a hash value after a given hash value (is this really needed?) (return 0 if successful, -1 on error)
		int sourcelistpertask::insert(uchar hashtoinsert[21], uchar afterhash[21]);
		/// retrieve an entry from the sourcelist to supply a new clientthread with all needed information
		minsrclist * sourcelistpertask::get(int whichone);
		/// retreve the next entry
		minsrclist * sourcelistpertask::getnext();
		...

};
**/

#endif // _VIDTRANS_H_


