/* * libretroshare/src/services: ftturtlefiletransferitem.cc * * Services for RetroShare. * * Copyright 2013 by Cyril Soler * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License Version 2 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. * * Please report all bugs and problems to "csoler@users.sourceforge.net". * */ #include #include #include #include uint32_t RsTurtleFileRequestItem::serial_size() { uint32_t s = 0 ; s += 8 ; // header s += 4 ; // tunnel id s += 8 ; // file offset s += 4 ; // chunk size return s ; } uint32_t RsTurtleFileDataItem::serial_size() { uint32_t s = 0 ; s += 8 ; // header s += 4 ; // tunnel id s += 8 ; // file offset s += 4 ; // chunk size s += chunk_size ; // actual data size. return s ; } uint32_t RsTurtleFileMapRequestItem::serial_size() { uint32_t s = 0 ; s += 8 ; // header s += 4 ; // tunnel id s += 4 ; // direction return s ; } uint32_t RsTurtleFileMapItem::serial_size() { uint32_t s = 0 ; s += 8 ; // header s += 4 ; // tunnel id s += 4 ; // direction s += 4 ; // compressed_map.size() s += 4 * compressed_map._map.size() ; return s ; } uint32_t RsTurtleChunkCrcItem::serial_size() { uint32_t s = 0 ; s += 8 ; // header s += 4 ; // tunnel id s += 4 ; // chunk number s += check_sum.serial_size() ; // check_sum return s ; } uint32_t RsTurtleChunkCrcRequestItem::serial_size() { uint32_t s = 0 ; s += 8 ; // header s += 4 ; // tunnel id s += 4 ; // chunk number return s ; } bool RsTurtleFileMapRequestItem::serialize(void *data,uint32_t& pktsize) { uint32_t tlvsize = serial_size(); uint32_t offset = 0; if (pktsize < tlvsize) return false; /* not enough space */ pktsize = tlvsize; bool ok = true; ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize); /* skip the header */ offset += 8; /* add mandatory parts first */ ok &= setRawUInt32(data, tlvsize, &offset, tunnel_id); ok &= setRawUInt32(data, tlvsize, &offset, direction); if (offset != tlvsize) { ok = false; #ifdef RSSERIAL_DEBUG std::cerr << "RsFileConfigSerialiser::serialiseTransfer() Size Error! " << std::endl; #endif } return ok; } bool RsTurtleFileMapItem::serialize(void *data,uint32_t& pktsize) { uint32_t tlvsize = serial_size(); uint32_t offset = 0; if (pktsize < tlvsize) return false; /* not enough space */ pktsize = tlvsize; bool ok = true; ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize); /* skip the header */ offset += 8; /* add mandatory parts first */ ok &= setRawUInt32(data, tlvsize, &offset, tunnel_id); ok &= setRawUInt32(data, tlvsize, &offset, direction); ok &= setRawUInt32(data, tlvsize, &offset, compressed_map._map.size()); for(uint32_t i=0;i