void PacketHandler::handleSessionCreated(ByteArrayConstItr &begin, ByteArrayConstItr end, EstablishmentStatePtr const &state) { if(state->getState() != EstablishmentState::State::REQUEST_SENT) return; state->setTheirDH(begin, begin + 256), begin += 256; unsigned char ipSize = *(begin++); if(ipSize != 4 && ipSize != 16) return; ByteArray ip(begin, begin + ipSize); begin += ipSize; uint16_t port = parseUint16(begin); state->setMyEndpoint(Endpoint(ip, port)); uint32_t relayTag = parseUint32(begin); state->setRelayTag(relayTag); uint32_t ts = parseUint32(begin); state->setSignatureTimestamp(ts); state->setSignature(begin, begin + 48); state->setState(EstablishmentState::State::CREATED_RECEIVED); m_context.establishmentManager.post(state); }
void PaloHttpRequest::fillIdentifier(IdentifierType& identifier, char* valueStart, char* valueEnd) { if (valueEnd != valueStart) { uint32_t id = parseUint32(valueStart, valueEnd); identifier = (IdentifierType)id; } }
sf::Uint32 ConfigReader::getUint32(const std::string theSection, const std::string theName, const sf::Uint32 theDefault) const { sf::Uint32 anResult = theDefault; // Check if theSection really exists std::map<const std::string, typeNameValue*>::const_iterator iter; iter = mSections.find(theSection); if (iter != mSections.end()) { // Try to obtain the name, value pair typeNameValue* anMap = iter->second; if (NULL != anMap) { typeNameValueIter iterNameValue; iterNameValue = anMap->find(theName); if (iterNameValue != anMap->end()) { anResult = parseUint32(iterNameValue->second, theDefault); } } } // Return the result found or theDefault assigned above return anResult; }
sf::Vector2u parseVector2u(const std::string theValue, const sf::Vector2u theDefault) { sf::Vector2u anResult = theDefault; // Buscamos la primera coma size_t anCommaOffset = theValue.find_first_of(','); if (anCommaOffset != std::string::npos) { sf::Uint32 anX = parseUint32(theValue.substr(0, anCommaOffset), theDefault.x); sf::Uint32 anY = parseUint32(theValue.substr(anCommaOffset + 1), theDefault.y); // Ahora que los 2 valores han sido parseados, devolvemos el vector encontrado anResult.x = anX; anResult.y = anY; } // Devolvemos el resultado que hemos encontrado o el valor theDefault que se nos ha proporcionado return anResult; }
sf::Vector2u parseVector2u(const std::string theValue, const sf::Vector2u theDefault) { sf::Vector2u anResult = theDefault; // Try to find the first comma size_t anCommaOffset = theValue.find_first_of(','); if(anCommaOffset != std::string::npos) { Uint32 anX = parseUint32(theValue.substr(0, anCommaOffset), theDefault.x); Uint32 anY = parseUint32(theValue.substr(anCommaOffset+1), theDefault.y); // Now that both values have been parsed, return the vector found anResult.x = anX; anResult.y = anY; } // Return the result found or theDefault assigned above return anResult; }
Lease::Lease(ByteArrayConstItr &begin, ByteArrayConstItr end) { if(std::distance(begin, end) != 44) throw std::runtime_error("malformed lease"); std::copy(begin, begin + 32, m_gw.begin()); begin += 32; m_tid = parseUint32(begin); m_end = Date(begin, end); }
DatabaseStore DatabaseStore::parse(ByteArrayConstItr &begin, ByteArrayConstItr end) { DatabaseStore ds; std::copy(begin, begin + 32, ds.m_key.begin()); begin += 32; ds.m_type = (DataType)*(begin++); ds.m_replyToken = parseUint32(begin); if(ds.m_replyToken) { ds.m_replyTunnelId = parseUint32(begin); std::copy(begin, begin + 32, ds.m_replyGateway.begin()); begin += 32; } uint16_t size = parseUint16(begin); ds.m_data = ByteArray(begin, begin + size); return ds; }
void PacketHandler::handleSessionConfirmed(ByteArrayConstItr &begin, ByteArrayConstItr end, EstablishmentStatePtr const &state) { if(state->getState() != EstablishmentState::State::CREATED_SENT) return; unsigned char info = *(begin++); uint16_t size = parseUint16(begin); (void)info; (void)size; // Stop compiler from complaining RouterIdentity ri(begin, end); state->setTheirIdentity(ri); uint32_t ts = parseUint32(begin); state->setSignatureTimestamp(ts); state->setSignature(end - 40, end); state->setState(EstablishmentState::State::CONFIRMED_RECEIVED); m_context.establishmentManager.post(state); }
sf::Uint32 ConfigReader::getUint32(const std::string theSection, const std::string theName, const sf::Uint32 theDefault) const { sf::Uint32 anResult = theDefault; // Comprueba si la sección existe std::map<const std::string, typeNameValue*>::const_iterator iter; iter = this->sections.find(theSection); if (iter != this->sections.end()) { // Intenta obtener el par <clave, valor> typeNameValue* anMap = iter->second; if (NULL != anMap) { typeNameValueIter iterNameValue; iterNameValue = anMap->find(theName); if (iterNameValue != anMap->end()) { anResult = parseUint32(iterNameValue->second, theDefault); } } } // Devuelve el resultado encontrado o el valor de theDefault return anResult; }
void PaloHttpRequest::fillUint(uint32_t& identifier, char* valueStart, char* valueEnd) { uint32_t id = parseUint32(valueStart, valueEnd); identifier = (uint32_t)id; }
void PaloHttpRequest::fillToken(uint32_t*& identifier, char* valueStart, char* valueEnd) { identifier = new uint32_t; *identifier = parseUint32(valueStart, valueEnd); }
MessagePtr Message::fromBytes(uint32_t msgId, ByteArray const &data, bool standardHeader) { MessagePtr m; auto dataItr = data.cbegin(); auto end = data.cend(); Type mtype = (Type)*(dataItr++); Date longExpiration; uint32_t expiration; if(standardHeader) { msgId = parseUint32(dataItr); longExpiration = Date(dataItr, end); uint16_t size = parseUint16(dataItr); uint8_t checksum = *dataItr++; // TODO verify this if(end - dataItr != size) throw std::runtime_error("error parsing I2NP message"); } else expiration = parseUint32(dataItr); switch(mtype) { case Type::DELIVERY_STATUS: m = std::make_shared<DeliveryStatus>(DeliveryStatus::parse(dataItr, end)); break; case Type::DB_LOOKUP: m = std::make_shared<DatabaseLookup>(DatabaseLookup::parse(dataItr, end)); break; case Type::DB_STORE: m = std::make_shared<DatabaseStore>(DatabaseStore::parse(dataItr, end)); break; case Type::DB_SEARCH_REPLY: m = std::make_shared<DatabaseSearchReply>(DatabaseSearchReply::parse(dataItr, end)); break; case Type::VARIABLE_TUNNEL_BUILD: m = std::make_shared<VariableTunnelBuild>(VariableTunnelBuild::parse(dataItr, end)); break; case Type::VARIABLE_TUNNEL_BUILD_REPLY: m = std::make_shared<VariableTunnelBuildReply>(VariableTunnelBuildReply::parse(dataItr, end)); break; case Type::TUNNEL_DATA: m = std::make_shared<TunnelData>(TunnelData::parse(dataItr, end)); break; case Type::TUNNEL_GATEWAY: m = std::make_shared<TunnelGateway>(TunnelGateway::parse(dataItr, end)); break; case Type::GARLIC: m = std::make_shared<Garlic>(Garlic::parse(dataItr, end)); break; default: return MessagePtr(); } m->m_msgId = msgId; m->m_longExpiration = longExpiration; m->m_expiration = expiration; return m; }