Skip to content
Snippets Groups Projects
Select Git revision
  • 27bfd547c58db1db7a2c3ac43e6f88aeca8b5e21
  • master default
  • cmake_fixes
  • pulls/1772757862/750
  • copilot/fix-770
  • windows_ci_static
  • c_link
  • cpack
  • windows_ci
  • cert_pk_id
  • proxy_push_result
  • cnode_put_id
  • update-windows-build
  • proxy
  • resubscribe_on_token_change
  • actions
  • client_mode
  • llhttp
  • search_node_add
  • crypto_aes_gcm_argon2
  • ios_notifications
  • v3.4.0
  • v3.3.1
  • v3.3.1rc1
  • v3.3.1rc2
  • v3.3.0
  • v3.2.0
  • v3.1.11
  • v3.1.10
  • v3.1.9
  • v3.1.8.2
  • v3.1.8.1
  • v3.1.8
  • v3.1.7
  • v3.1.6
  • v3.1.5
  • v3.1.4
  • v3.1.3
  • v3.1.2
  • v3.1
  • v3.0.1
41 results

opendht.cpp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    opendht.cpp 18.70 KiB
    /*
     *  Copyright (C) 2014-2023 Savoir-faire Linux Inc.
     *  Author : Adrien Béraud <adrien.beraud@savoirfairelinux.com>
     *
     *  This program is free software; you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation; either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program 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 General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program. If not, see <https://www.gnu.org/licenses/>.
     */
    
    #include "opendht_c.h"
    
    #include <opendht.h>
    #include <opendht/log.h>
    
    using ValueSp = std::shared_ptr<dht::Value>;
    using PrivkeySp = std::shared_ptr<dht::crypto::PrivateKey>;
    using PubkeySp = std::shared_ptr<const dht::crypto::PublicKey>;
    using CertSp = std::shared_ptr<dht::crypto::Certificate>;
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    #include <errno.h>
    
    const char* dht_version()
    {
        return dht::version();
    }
    
    // dht::InfoHash
    
    inline dht_infohash dht_infohash_to_c(const dht::InfoHash& h) {
        dht_infohash ret;
        *reinterpret_cast<dht::InfoHash*>(&ret) = h;
        return ret;
    }
    
    inline dht_pkid dht_pkid_to_c(const dht::PkId& h) {
        dht_pkid ret;
        *reinterpret_cast<dht::PkId*>(&ret) = h;
        return ret;
    }
    
    const char* dht_infohash_print(const dht_infohash* h) {
        return reinterpret_cast<const dht::InfoHash*>(h)->to_c_str();
    }
    
    void dht_infohash_zero(dht_infohash* h) {
        *reinterpret_cast<dht::InfoHash*>(h) = dht::InfoHash{};
    }
    
    void dht_infohash_random(dht_infohash* h) {
        *reinterpret_cast<dht::InfoHash*>(h) = dht::InfoHash::getRandom();
    }
    
    void dht_infohash_get(dht_infohash* h, const uint8_t* dat, size_t dat_size) {
        *reinterpret_cast<dht::InfoHash*>(h) = dht::InfoHash::get(dat, dat_size);
    }
    
    void dht_infohash_get_from_string(dht_infohash* h, const char* dat) {