├── .gitignore ├── doc └── logo.png ├── rct ├── Cargo.toml ├── src │ └── lib.rs └── LICENSE-MIT ├── keys ├── Cargo.toml ├── src │ ├── lib.rs │ ├── secret_key.rs │ ├── utils.rs │ ├── key_image.rs │ ├── signature.rs │ └── public_key.rs └── LICENSE-MIT ├── varint ├── Cargo.toml ├── LICENSE-MIT └── src │ └── lib.rs ├── p2p ├── src │ ├── types │ │ ├── cn │ │ │ ├── mod.rs │ │ │ ├── core_sync_data.rs │ │ │ ├── cmd │ │ │ │ ├── new_transactions.rs │ │ │ │ ├── new_block.rs │ │ │ │ ├── request_get_objects.rs │ │ │ │ ├── new_fluffy_block.rs │ │ │ │ ├── request_chain.rs │ │ │ │ ├── request_fluffy_missing_tx.rs │ │ │ │ ├── response_get_objects.rs │ │ │ │ ├── response_chain_entry.rs │ │ │ │ └── mod.rs │ │ │ └── block_complete_entry.rs │ │ ├── cmd │ │ │ ├── mod.rs │ │ │ ├── timedsync.rs │ │ │ ├── handshake.rs │ │ │ ├── request_support_flags.rs │ │ │ └── ping.rs │ │ ├── mod.rs │ │ ├── basic_node_data.rs │ │ ├── peerlist_entry.rs │ │ ├── ipv4_address.rs │ │ └── peerid.rs │ ├── utils │ │ ├── mod.rs │ │ └── peerlist.rs │ ├── net │ │ ├── mod.rs │ │ └── peer_context.rs │ ├── protocol │ │ └── mod.rs │ ├── event_loop.rs │ ├── config.rs │ └── lib.rs └── Cargo.toml ├── crypto ├── Cargo.toml ├── src │ └── ffi.rs ├── sys │ ├── keccak.h │ ├── jh.h │ ├── mvsc │ │ └── alloca.h │ ├── hash-extra-blake.c │ ├── hash-extra-groestl.c │ ├── hash-extra-skein.c │ ├── skein.h │ ├── hash-extra-jh.c │ ├── oaes_config.h │ ├── hash.c │ ├── hash-ops.h │ ├── blake256.h │ └── groestl.h ├── build.rs └── LICENSE-MIT ├── format ├── Cargo.toml ├── src │ ├── lib.rs │ ├── impls.rs │ └── ser.rs └── LICENSE-MIT ├── verification ├── Cargo.toml └── src │ ├── lib.rs │ └── pow.rs ├── primitives ├── Cargo.toml ├── src │ └── lib.rs └── LICENSE-MIT ├── storage ├── Cargo.toml └── src │ ├── block_chain.rs │ ├── best_block.rs │ ├── block_provider.rs │ ├── block_ref.rs │ ├── lib.rs │ └── store.rs ├── portable-storage-utils ├── Cargo.toml ├── src │ ├── stl │ │ ├── mod.rs │ │ ├── element.rs │ │ ├── vector.rs │ │ └── linked_list.rs │ ├── lib.rs │ ├── blob.rs │ └── bytes_uuid.rs └── LICENSE-MIT ├── portable-storage ├── Cargo.toml ├── LICENSE-MIT └── src │ ├── header.rs │ └── raw_size.rs ├── chain ├── Cargo.toml ├── src │ ├── lib.rs │ ├── transaction │ │ ├── tx_in_gen.rs │ │ ├── tx_out_to_key.rs │ │ ├── tx_out_to_script_hash.rs │ │ ├── mod.rs │ │ ├── tx_out.rs │ │ ├── tx_in_to_script.rs │ │ ├── tx_out_to_script.rs │ │ ├── tx_in_to_script_hash.rs │ │ ├── tx_in_to_key.rs │ │ ├── tx_out_target.rs │ │ ├── transaction_prefix.rs │ │ └── tx_in.rs │ ├── indexed_block.rs │ └── block_header.rs └── LICENSE-MIT ├── ci ├── script.sh ├── before_deploy.ps1 └── install.sh ├── sync ├── Cargo.toml └── src │ ├── synchronization_chain.rs │ ├── types.rs │ ├── synchronization_executor.rs │ ├── lib.rs │ ├── connection_factory.rs │ ├── inbound_connection.rs │ └── synchronization_peers.rs ├── network └── Cargo.toml ├── db ├── Cargo.toml └── src │ ├── kv │ ├── mod.rs │ └── db.rs │ ├── error.rs │ └── lib.rs ├── levin ├── src │ ├── bucket │ │ └── mod.rs │ ├── net │ │ ├── mod.rs │ │ ├── bucket_stream.rs │ │ ├── handlers.rs │ │ └── io.rs │ ├── command.rs │ ├── lib.rs │ └── error.rs ├── Cargo.toml └── LICENSE-MIT ├── LICENSE-MIT ├── Cargo.toml ├── README.md ├── dxmr ├── peers.rs ├── utils.rs ├── config.rs └── main.rs ├── appveyor.yml └── .travis.yml /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /target/ 3 | **/*.rs.bk 4 | 5 | compat/build 6 | -------------------------------------------------------------------------------- /doc/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmr-rs/xmr/HEAD/doc/logo.png -------------------------------------------------------------------------------- /rct/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xmr-rct" 3 | version = "0.1.0" 4 | authors = ["Jean Pierre Dudey "] 5 | license = "MIT/Apache-2.0" 6 | include = ["LICENSE-APACHE", "LICENSE-MIT"] 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /keys/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xmr-keys" 3 | version = "0.1.0" 4 | authors = ["Jean Pierre Dudey "] 5 | license = "MIT/Apache-2.0" 6 | include = ["LICENSE-APACHE", "LICENSE-MIT"] 7 | 8 | [dependencies] 9 | xmr-format = { path = "../format" } 10 | -------------------------------------------------------------------------------- /varint/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xmr-varint" 3 | version = "0.1.0" 4 | authors = ["Jean Pierre Dudey "] 5 | license = "MIT/Apache-2.0" 6 | include = ["LICENSE-APACHE", "LICENSE-MIT"] 7 | 8 | [dependencies] 9 | bytes = "0.4.6" 10 | num = "0.1.41" 11 | -------------------------------------------------------------------------------- /p2p/src/types/cn/mod.rs: -------------------------------------------------------------------------------- 1 | //! CryptoNote types. 2 | 3 | pub const CN_COMMAND_BASE_ID: u32 = 2000; 4 | 5 | pub mod cmd; 6 | 7 | mod block_complete_entry; 8 | mod core_sync_data; 9 | 10 | pub use self::block_complete_entry::BlockCompleteEntry; 11 | pub use self::core_sync_data::CoreSyncData; 12 | -------------------------------------------------------------------------------- /crypto/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xmr-crypto" 3 | version = "0.1.0" 4 | authors = ["Jean Pierre Dudey "] 5 | build = "build.rs" 6 | license = "MIT/Apache-2.0" 7 | include = ["LICENSE-MIT", "LICENSE-APACHE", "/sys/**"] 8 | 9 | [dependencies] 10 | libc = "0.2.36" 11 | 12 | [build-dependencies] 13 | cc = "1.0" 14 | -------------------------------------------------------------------------------- /format/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xmr-format" 3 | version = "0.1.0" 4 | authors = ["Jean Pierre Dudey "] 5 | license = "MIT/Apache-2.0" 6 | include = ["LICENSE-APACHE", "LICENSE-MIT"] 7 | 8 | [dependencies] 9 | bytes = "0.4.6" 10 | 11 | failure = "0.1.1" 12 | failure_derive = "0.1.1" 13 | 14 | xmr-varint = { path = "../varint" } 15 | -------------------------------------------------------------------------------- /verification/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xmr-verification" 3 | version = "0.1.0" 4 | authors = [ 5 | "Jean Pierre Dudey ", 6 | "Parity Technologies " 7 | ] 8 | license = "GPL-3.0-only" 9 | include = ["LICENSE-APACHE", "LICENSE-GPL"] 10 | 11 | [dependencies] 12 | xmr-primitives = { path = "../primitives" } 13 | -------------------------------------------------------------------------------- /primitives/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xmr-primitives" 3 | version = "0.1.0" 4 | authors = ["Jean Pierre Dudey "] 5 | license = "MIT/Apache-2.0" 6 | include = ["LICENSE-APACHE", "LICENSE-MIT"] 7 | 8 | [dependencies] 9 | xmr-crypto = { path = "../crypto" } 10 | xmr-format = { path = "../format" } 11 | 12 | serde = "1.0.27" 13 | bytes = "0.4.6" 14 | -------------------------------------------------------------------------------- /storage/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xmr-storage" 3 | version = "0.1.0" 4 | authors = [ 5 | "Jean Pierre Dudey ", 6 | "Parity Technologies " 7 | ] 8 | license = "GPL-3.0-only" 9 | include = ["LICENSE-GPL"] 10 | 11 | [dependencies] 12 | xmr-chain = { path = "../chain" } 13 | xmr-primitives = { path = "../primitives" } 14 | -------------------------------------------------------------------------------- /portable-storage-utils/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xmr-portable-storage-utils" 3 | version = "0.1.0" 4 | authors = ["Jean Pierre Dudey "] 5 | license = "MIT/Apache-2.0" 6 | include = ["LICENSE-APACHE", "LICENSE-MIT"] 7 | 8 | [dependencies] 9 | uuid = "0.5.1" 10 | serde = "1.0.27" 11 | bytes = "0.4.6" 12 | failure = "0.1.1" 13 | failure_derive = "0.1.1" 14 | 15 | xmr-primitives = { path = "../primitives"} 16 | -------------------------------------------------------------------------------- /portable-storage/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xmr-portable-storage" 3 | version = "0.1.0" 4 | authors = ["Jean Pierre Dudey "] 5 | license = "MIT/Apache-2.0" 6 | include = ["LICENSE-APACHE", "LICENSE-MIT"] 7 | 8 | [dependencies] 9 | bytes = "0.4.6" 10 | failure = "0.1.1" 11 | serde = "1.0.27" 12 | linked-hash-map = "0.5.0" 13 | failure_derive = "0.1.1" 14 | 15 | [dev-dependencies] 16 | serde_derive = "1.0.27" 17 | -------------------------------------------------------------------------------- /chain/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xmr-chain" 3 | version = "0.1.0" 4 | authors = ["Jean Pierre Dudey "] 5 | license = "GPL-3.0-only" 6 | include = ["LICENSE-MIT", "LICENSE-APACHE"] 7 | 8 | [dependencies] 9 | bytes = "0.4.6" 10 | 11 | xmr-primitives = { path = "../primitives" } 12 | xmr-keys = { path = "../keys" } 13 | xmr-rct = { path = "../rct" } 14 | xmr-format = { path = "../format" } 15 | xmr-varint = { path = "../varint" } 16 | -------------------------------------------------------------------------------- /ci/script.sh: -------------------------------------------------------------------------------- 1 | # This script takes care of testing your crate 2 | 3 | set -ex 4 | 5 | main() { 6 | cross build --target $TARGET 7 | cross build --target $TARGET --release 8 | 9 | if [ ! -z $DISABLE_TESTS ]; then 10 | return 11 | fi 12 | 13 | cross test --target $TARGET 14 | cross test --target $TARGET --release 15 | } 16 | 17 | # we don't run the "test phase" when doing deploys 18 | if [ -z $TRAVIS_TAG ]; then 19 | main 20 | fi 21 | -------------------------------------------------------------------------------- /rct/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | #[derive(Debug, Default, Clone)] 10 | pub struct Signature; 11 | -------------------------------------------------------------------------------- /p2p/src/types/cn/core_sync_data.rs: -------------------------------------------------------------------------------- 1 | use primitives::H256; 2 | 3 | /// Synchronization information between nodes. 4 | #[derive(Debug, Default, Clone, Deserialize, Serialize)] 5 | pub struct CoreSyncData { 6 | /// The cumulative difficulty. 7 | pub cumulative_difficulty: u64, 8 | /// The current block height 9 | pub current_height: u64, 10 | /// The top block id. 11 | pub top_id: H256, 12 | /// The top block version. 13 | pub top_version: u8, 14 | } 15 | -------------------------------------------------------------------------------- /p2p/src/types/cmd/mod.rs: -------------------------------------------------------------------------------- 1 | mod handshake; 2 | mod ping; 3 | mod request_support_flags; 4 | mod timedsync; 5 | 6 | pub use self::handshake::{Handshake, HandshakeRequest, HandshakeResponse}; 7 | pub use self::ping::{Ping, PingResponse}; 8 | pub use self::request_support_flags::{RequestSupportFlags, SupportFlagsResponse, 9 | P2P_SUPPORT_FLAGS, P2P_SUPPORT_FLAG_FLUFFY_BLOCKS}; 10 | pub use self::timedsync::{TimedSync, TimedSyncRequest, TimedSyncResponse}; 11 | -------------------------------------------------------------------------------- /sync/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xmr-sync" 3 | version = "0.1.0" 4 | authors = [ 5 | "Jean Pierre Dudey ", 6 | "Parity Technologies " 7 | ] 8 | license = "GPL-3.0-only" 9 | include = ["LICENSE-GPL"] 10 | 11 | [dependencies] 12 | log = "0.4.1" 13 | parking_lot = "0.4.8" 14 | 15 | xmr-db = { path = "../db" } 16 | xmr-network = { path = "../network" } 17 | xmr-p2p = { path = "../p2p" } 18 | xmr-primitives = { path = "../primitives" } 19 | xmr-storage = { path = "../storage" } 20 | -------------------------------------------------------------------------------- /network/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xmr-network" 3 | version = "0.1.0" 4 | authors = [ 5 | "Jean Pierre Dudey ", 6 | "Parity Technologies " 7 | ] 8 | license = "GPL-3.0-only" 9 | include = ["LICENSE-GPL"] 10 | 11 | [dependencies] 12 | log = "0.4.1" 13 | uuid = "0.5.0" 14 | 15 | xmr-chain = { path = "../chain" } 16 | xmr-primitives = { path = "../primitives" } 17 | xmr-verification = { path = "../verification" } 18 | 19 | [dev-dependencies] 20 | xmr-format = { path = "../format" } 21 | -------------------------------------------------------------------------------- /verification/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | extern crate xmr_primitives as primitives; 10 | 11 | mod pow; 12 | 13 | pub use pow::{Difficulty, is_valid_proof_of_work}; 14 | -------------------------------------------------------------------------------- /crypto/src/ffi.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_camel_case_types)] 2 | 3 | use libc::{c_void, c_char, size_t}; 4 | 5 | pub const HASH_SIZE: usize = 32; 6 | 7 | extern "C" { 8 | pub fn cn_fast_hash(data: *const c_void, length: size_t, hash: *mut c_char); 9 | pub fn cn_slow_hash(data: *const c_void, length: size_t, hash: *mut c_char); 10 | } 11 | 12 | #[cfg(test)] 13 | pub mod tests { 14 | use super::*; 15 | 16 | fn f(_t: T) {} 17 | 18 | #[test] 19 | fn link() { 20 | f(cn_fast_hash); 21 | f(cn_slow_hash); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /primitives/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | extern crate bytes; 10 | extern crate serde; 11 | 12 | extern crate xmr_crypto as crypto; 13 | extern crate xmr_format as format; 14 | 15 | mod h256; 16 | 17 | pub use h256::{H256, H256_LENGTH}; 18 | -------------------------------------------------------------------------------- /portable-storage-utils/src/stl/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | mod element; 10 | mod linked_list; 11 | mod vector; 12 | 13 | pub use self::element::{StlElement, Error}; 14 | pub use self::linked_list::StlLinkedList; 15 | pub use self::vector::StlVector; 16 | -------------------------------------------------------------------------------- /db/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xmr-db" 3 | version = "0.1.0" 4 | authors = [ 5 | "Jean Pierre Dudey ", 6 | "Parity Technologies " 7 | ] 8 | license = "GPL-3.0-only" 9 | include = ["LICENSE-GPL"] 10 | 11 | [dependencies] 12 | bytes = "0.4.6" 13 | parking_lot = "0.4" 14 | sanakirja = "0.8" 15 | rand = "0.4.2" 16 | 17 | failure = "0.1.1" 18 | failure_derive = "0.1.1" 19 | 20 | xmr-chain = { path = "../chain" } 21 | xmr-format = { path = "../format" } 22 | xmr-primitives = { path = "../primitives" } 23 | xmr-storage = { path = "../storage" } 24 | 25 | [dev-dependencies] 26 | tempdir = "0.3" 27 | -------------------------------------------------------------------------------- /crypto/sys/keccak.h: -------------------------------------------------------------------------------- 1 | // keccak.h 2 | // 19-Nov-11 Markku-Juhani O. Saarinen 3 | 4 | #ifndef KECCAK_H 5 | #define KECCAK_H 6 | 7 | #include 8 | #include 9 | 10 | #ifndef KECCAK_ROUNDS 11 | #define KECCAK_ROUNDS 24 12 | #endif 13 | 14 | #ifndef ROTL64 15 | #define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y)))) 16 | #endif 17 | 18 | // compute a keccak hash (md) of given byte length from "in" 19 | void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen); 20 | 21 | // update the state 22 | void keccakf(uint64_t st[25], int norounds); 23 | 24 | void keccak1600(const uint8_t *in, size_t inlen, uint8_t *md); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /ci/before_deploy.ps1: -------------------------------------------------------------------------------- 1 | # This script takes care of packaging the build artifacts that will go in the 2 | # release zipfile 3 | 4 | $SRC_DIR = $PWD.Path 5 | $STAGE = [System.Guid]::NewGuid().ToString() 6 | 7 | Set-Location $ENV:Temp 8 | New-Item -Type Directory -Name $STAGE 9 | Set-Location $STAGE 10 | 11 | $ZIP = "$SRC_DIR\$($Env:CRATE_NAME)-$($Env:APPVEYOR_REPO_TAG_NAME)-$($Env:TARGET).zip" 12 | 13 | # TODO Update this to package the right artifacts 14 | Copy-Item "$SRC_DIR\target\$($Env:TARGET)\release\hello.exe" '.\' 15 | 16 | 7z a "$ZIP" * 17 | 18 | Push-AppveyorArtifact "$ZIP" 19 | 20 | Remove-Item *.* -Force 21 | Set-Location .. 22 | Remove-Item $STAGE 23 | Set-Location $SRC_DIR 24 | -------------------------------------------------------------------------------- /p2p/src/types/cmd/timedsync.rs: -------------------------------------------------------------------------------- 1 | use portable_storage_utils::stl::StlLinkedList; 2 | 3 | use types::{P2P_COMMAND_BASE_ID, PeerlistEntry}; 4 | use types::cn::CoreSyncData; 5 | use levin::Command; 6 | 7 | #[derive(Debug)] 8 | pub struct TimedSync; 9 | 10 | impl Command for TimedSync { 11 | const ID: u32 = P2P_COMMAND_BASE_ID + 2; 12 | } 13 | 14 | #[derive(Debug, Default, Clone, Deserialize, Serialize)] 15 | pub struct TimedSyncRequest { 16 | pub payload_data: CoreSyncData, 17 | } 18 | 19 | #[derive(Debug, Default, Clone, Deserialize, Serialize)] 20 | pub struct TimedSyncResponse { 21 | pub local_time: u64, 22 | pub payload_data: CoreSyncData, 23 | pub local_peerlist: StlLinkedList, 24 | } 25 | -------------------------------------------------------------------------------- /portable-storage-utils/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | extern crate uuid; 10 | extern crate serde; 11 | extern crate bytes; 12 | 13 | extern crate failure; 14 | #[macro_use] 15 | extern crate failure_derive; 16 | 17 | extern crate xmr_primitives as primitives; 18 | 19 | pub mod stl; 20 | 21 | mod blob; 22 | mod bytes_uuid; 23 | 24 | pub use blob::Blob; 25 | pub use bytes_uuid::BytesUuid; 26 | -------------------------------------------------------------------------------- /keys/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | extern crate xmr_format as format; 10 | 11 | mod key_image; 12 | mod public_key; 13 | mod secret_key; 14 | mod signature; 15 | mod utils; 16 | 17 | pub use key_image::{KEY_IMAGE_LENGTH, KeyImage}; 18 | pub use public_key::{PUBLIC_KEY_LENGTH, PublicKey}; 19 | pub use secret_key::{SECRET_KEY_LENGTH, SecretKey}; 20 | pub use signature::{SIGNATURE_LENGTH, Signature}; 21 | -------------------------------------------------------------------------------- /format/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | extern crate bytes; 10 | 11 | extern crate failure; 12 | #[macro_use] 13 | extern crate failure_derive; 14 | 15 | extern crate xmr_varint as varint; 16 | 17 | mod de; 18 | mod ser; 19 | 20 | pub use de::{Deserialize, DeserializerStream, Error, from_binary}; 21 | pub use ser::{Serialize, SerializerStream, to_binary}; 22 | 23 | mod impls; 24 | 25 | pub use impls::*; 26 | -------------------------------------------------------------------------------- /chain/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | extern crate bytes; 10 | 11 | extern crate xmr_primitives as primitives; 12 | extern crate xmr_keys as keys; 13 | extern crate xmr_rct as rct; 14 | extern crate xmr_format as format; 15 | extern crate xmr_varint as varint; 16 | 17 | pub mod transaction; 18 | 19 | mod block; 20 | mod block_header; 21 | mod indexed_block; 22 | 23 | pub use block::Block; 24 | pub use block_header::BlockHeader; 25 | pub use indexed_block::IndexedBlock; 26 | -------------------------------------------------------------------------------- /p2p/src/utils/mod.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | mod peerlist; 18 | 19 | pub use self::peerlist::Peerlist; 20 | -------------------------------------------------------------------------------- /p2p/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xmr-p2p" 3 | version = "0.1.0" 4 | authors = [ 5 | "Jean Pierre Dudey ", 6 | "Parity Technologies " 7 | ] 8 | license = "GPL-3.0-only" 9 | include = ["LICENSE-GPL"] 10 | 11 | [dependencies] 12 | futures = "0.1.18" 13 | futures-cpupool = "0.1.8" 14 | tokio-io = "0.1.1" 15 | tokio-core = "0.1.12" 16 | 17 | bytes = "0.4.6" 18 | parking_lot = "0.4.8" 19 | rand = "0.4.2" 20 | uuid = "0.5.0" 21 | 22 | failure = "0.1.1" 23 | log = "0.4.1" 24 | 25 | serde = "1.0.27" 26 | serde_derive = "1.0.27" 27 | 28 | xmr-levin = { path = "../levin" } 29 | xmr-network = { path = "../network" } 30 | xmr-portable-storage = { path = "../portable-storage" } 31 | xmr-portable-storage-utils = { path = "../portable-storage-utils" } 32 | xmr-primitives = { path = "../primitives" } 33 | xmr-storage = { path = "../storage" } 34 | -------------------------------------------------------------------------------- /levin/src/bucket/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | //! Buckets 10 | //! 11 | //! Buckets are the packet of information that the levin protocol use 12 | //! to send and receive commands. 13 | 14 | mod bucket; 15 | mod bucket_head; 16 | 17 | pub use self::bucket::{Bucket, Receive}; 18 | pub use self::bucket_head::{BucketHead, LEVIN_SIGNATURE, LEVIN_PACKET_REQUEST, 19 | LEVIN_PACKET_RESPONSE, LEVIN_PROTOCOL_VER_1, BUCKET_HEAD_LENGTH, 20 | LEVIN_OK, LEVIN_DEFAULT_MAX_PACKET_SIZE}; 21 | -------------------------------------------------------------------------------- /format/src/impls.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use de::{Deserialize, DeserializerStream, Error}; 10 | use ser::{Serialize, SerializerStream}; 11 | 12 | impl Deserialize for u64 { 13 | fn deserialize(deserializer: &mut DeserializerStream) -> Result { 14 | deserializer.get_u64() 15 | } 16 | } 17 | 18 | impl Serialize for u64 { 19 | fn serialize(&self, mut serializer: SerializerStream) { 20 | serializer.put_u64(*self) 21 | } 22 | 23 | fn len(&self) -> usize { 24 | 8 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /p2p/src/types/cmd/handshake.rs: -------------------------------------------------------------------------------- 1 | use portable_storage_utils::stl::StlLinkedList; 2 | 3 | use types::{P2P_COMMAND_BASE_ID, BasicNodeData, PeerlistEntry}; 4 | use types::cn::CoreSyncData; 5 | use levin::Command; 6 | 7 | /// The handshake command. 8 | #[derive(Debug, Clone, Copy)] 9 | pub struct Handshake; 10 | 11 | impl Command for Handshake { 12 | const ID: u32 = P2P_COMMAND_BASE_ID + 1; 13 | } 14 | 15 | /// The handshake command request. 16 | #[derive(Debug, Default, Clone, Deserialize, Serialize)] 17 | pub struct HandshakeRequest { 18 | pub node_data: BasicNodeData, 19 | pub payload_data: CoreSyncData, 20 | } 21 | 22 | /// The handshake command response. 23 | #[derive(Debug, Default, Clone, Deserialize, Serialize)] 24 | pub struct HandshakeResponse { 25 | pub node_data: BasicNodeData, 26 | pub payload_data: CoreSyncData, 27 | pub local_peerlist: StlLinkedList, 28 | } 29 | -------------------------------------------------------------------------------- /keys/src/secret_key.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use std::fmt::{self, Debug, Formatter}; 10 | 11 | use utils::fmt_byte_slice; 12 | 13 | /// Secret Key length in bytes. 14 | pub const SECRET_KEY_LENGTH: usize = 32; 15 | 16 | #[derive(Default, Clone)] 17 | pub struct SecretKey(pub [u8; SECRET_KEY_LENGTH]); 18 | 19 | impl AsRef<[u8]> for SecretKey { 20 | fn as_ref(&self) -> &[u8] { 21 | &self.0 22 | } 23 | } 24 | 25 | impl Debug for SecretKey { 26 | fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { 27 | fmt_byte_slice(&self.0, fmt) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /levin/src/net/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | //! Leivn networking 10 | 11 | mod bucket_sink; 12 | mod bucket_stream; 13 | mod handlers; 14 | mod io; 15 | mod tcp_server; 16 | mod tcp_client; 17 | 18 | pub use self::bucket_sink::{BucketSink, bucket_sink}; 19 | pub use self::bucket_stream::{BucketStream, bucket_stream}; 20 | pub use self::handlers::{NotificationHandler, InvokationHandler, RemoteHandler}; 21 | pub use self::io::{IoHandler, IoHandlerRef}; 22 | pub use self::tcp_server::{TcpServer, ConnectionHandler, ConnectionHandlerRef}; 23 | pub use self::tcp_client::{connect, Commands}; 24 | -------------------------------------------------------------------------------- /crypto/sys/jh.h: -------------------------------------------------------------------------------- 1 | /*This program gives the 64-bit optimized bitslice implementation of JH using ANSI C 2 | 3 | -------------------------------- 4 | Performance 5 | 6 | Microprocessor: Intel CORE 2 processor (Core 2 Duo Mobile T6600 2.2GHz) 7 | Operating System: 64-bit Ubuntu 10.04 (Linux kernel 2.6.32-22-generic) 8 | Speed for long message: 9 | 1) 45.8 cycles/byte compiler: Intel C++ Compiler 11.1 compilation option: icc -O2 10 | 2) 56.8 cycles/byte compiler: gcc 4.4.3 compilation option: gcc -O3 11 | 12 | -------------------------------- 13 | Last Modified: January 16, 2011 14 | */ 15 | #ifndef _JH_ 16 | #define _JH_ 17 | 18 | typedef unsigned char BitSequence; 19 | typedef unsigned long long DataLength; 20 | typedef enum {SUCCESS = 0, FAIL = 1, BAD_HASHLEN = 2} HashReturn; 21 | 22 | HashReturn jh_hash(int hashbitlen, const BitSequence *data, DataLength databitlen, BitSequence *hashval); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /p2p/src/net/mod.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | mod connection_counter; 18 | mod peer_context; 19 | 20 | pub use self::connection_counter::{ConnectionType, ConnectionCounter}; 21 | pub use self::peer_context::PeerContext; 22 | -------------------------------------------------------------------------------- /levin/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xmr-levin" 3 | version = "0.1.0" 4 | authors = ["Jean Pierre Dudey "] 5 | license = "MIT/Apache-2.0" 6 | description = "Implementation of the levin protocol used in the Monero cryptocurrency." 7 | keywords = ["futures", "async", "monero", "xmr", "epee"] 8 | # TODO: add real docs link 9 | documentation = "https://github.com/xmr-rs/xmr" 10 | homepage = "https://github.com/xmr-rs/xmr" 11 | repository = "https://github.com/xmr-rs/xmr" 12 | include = ["LICENSE-APACHE", "LICENSE-MIT"] 13 | 14 | [dependencies] 15 | futures = "0.1.18" 16 | tokio-core = "0.1.12" 17 | tokio-io = "0.1.5" 18 | 19 | crossbeam = "0.3.2" 20 | parking_lot = "0.4.8" 21 | 22 | bytes = "0.4.6" 23 | 24 | failure = "0.1.1" 25 | failure_derive = "0.1.1" 26 | 27 | log = "0.4.1" 28 | 29 | xmr-portable-storage = { path = "../portable-storage", version = "0.1.0" } 30 | 31 | [dev-dependencies] 32 | serde = "1.0.27" 33 | serde_derive = "1.0.27" 34 | -------------------------------------------------------------------------------- /levin/src/command.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | /// The start ID of levin commands and notifications. 10 | pub const COMMAND_BASE_ID: u32 = 1000; 11 | 12 | /// The id of a command. 13 | pub type Id = u32; 14 | 15 | /// A levin command. 16 | /// 17 | /// [*See the* `Bucket` *type for more information.*](/bucket/struct.Bucket.html) 18 | pub trait Command { 19 | /// The ID of this notification. 20 | /// 21 | /// Should be higher than [`COMMAND_BASE_ID`][1] and should 22 | /// be different to other commands/notifications IDs. 23 | /// 24 | /// [1]: const.COMMAND_BASE_ID.html 25 | const ID: Id; 26 | } 27 | -------------------------------------------------------------------------------- /p2p/src/types/cmd/request_support_flags.rs: -------------------------------------------------------------------------------- 1 | use levin::Command; 2 | 3 | use types::P2P_COMMAND_BASE_ID; 4 | 5 | /// Support for fluffypony's compact blocks. 6 | pub const P2P_SUPPORT_FLAG_FLUFFY_BLOCKS: u32 = 0x01; 7 | 8 | /// All the support flags. 9 | pub const P2P_SUPPORT_FLAGS: u32 = P2P_SUPPORT_FLAG_FLUFFY_BLOCKS; 10 | 11 | /// Request for support flags. 12 | #[derive(Debug)] 13 | pub struct RequestSupportFlags; 14 | 15 | impl Command for RequestSupportFlags { 16 | const ID: u32 = P2P_COMMAND_BASE_ID + 7; 17 | } 18 | 19 | /// The support flags of a node. 20 | #[derive(Debug, Default, Clone, Deserialize, Serialize)] 21 | pub struct SupportFlagsResponse { 22 | pub support_flags: u32, 23 | } 24 | 25 | impl SupportFlagsResponse { 26 | /// Creates a `SupportFlagsResponse` with the flags 27 | /// supported by this implementation. 28 | pub fn supported() -> SupportFlagsResponse { 29 | SupportFlagsResponse { support_flags: P2P_SUPPORT_FLAGS } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /db/src/kv/mod.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | mod db; 18 | mod transaction; 19 | 20 | pub use self::db::KeyValueDatabase; 21 | pub use self::transaction::{Transaction, KeyState, Key, Value, KeyValue}; 22 | 23 | 24 | mod diskdb; 25 | 26 | pub use self::diskdb::DiskDb; 27 | -------------------------------------------------------------------------------- /p2p/src/protocol/mod.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | mod sync; 18 | 19 | pub use self::sync::{OutboundSync, OutboundSyncConnection, OutboundSyncConnectionRef, 20 | InboundSyncConnection, InboundSyncConnectionRef, LocalSyncNode, 21 | LocalSyncNodeRef}; 22 | -------------------------------------------------------------------------------- /storage/src/block_chain.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use chain::IndexedBlock; 18 | use primitives::H256; 19 | 20 | /// A BlockChain interface. 21 | pub trait BlockChain { 22 | fn insert(&self, block: IndexedBlock) -> Result<(), String>; 23 | 24 | fn canonize(&self, id: &H256) -> Result<(), String>; 25 | } 26 | -------------------------------------------------------------------------------- /db/src/kv/db.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use std::fmt::Debug; 18 | use kv::{Transaction, KeyState, Key, Value}; 19 | 20 | pub trait KeyValueDatabase: Send + Sync + Debug { 21 | fn write(&self, tx: Transaction) -> Result<(), String>; 22 | 23 | fn get(&self, key: &Key) -> Result, String>; 24 | } 25 | -------------------------------------------------------------------------------- /storage/src/best_block.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use primitives::H256; 18 | 19 | /// The best block in the blockchain. 20 | #[derive(Debug, Default, Clone, Eq, PartialEq)] 21 | pub struct BestBlock { 22 | /// This block's height. 23 | pub height: u64, 24 | /// This block's id. 25 | pub id: H256, 26 | } 27 | -------------------------------------------------------------------------------- /p2p/src/event_loop.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use futures::{empty, Empty}; 18 | use tokio_core::reactor::Core; 19 | 20 | /// Creates a new event loop 21 | pub fn event_loop() -> Core { 22 | Core::new().unwrap() 23 | } 24 | 25 | /// Returns a future that runs forever. 26 | pub fn forever() -> Empty<(), ()> { 27 | empty() 28 | } 29 | -------------------------------------------------------------------------------- /p2p/src/types/cmd/ping.rs: -------------------------------------------------------------------------------- 1 | use levin::Command; 2 | use portable_storage_utils::Blob; 3 | 4 | use types::{P2P_COMMAND_BASE_ID, PeerId}; 5 | 6 | /// The ping command. 7 | #[derive(Debug)] 8 | pub struct Ping; 9 | 10 | impl Command for Ping { 11 | const ID: u32 = P2P_COMMAND_BASE_ID + 3; 12 | } 13 | 14 | const PING_RESPONSE_STATUS: &'static [u8] = b"OK\0"; 15 | 16 | /// The response of the ping command. 17 | #[derive(Debug, Default, Clone, Deserialize, Serialize)] 18 | pub struct PingResponse { 19 | /// The ping status. 20 | pub status: Blob, 21 | /// The ID of the peer being ping'ed. 22 | pub peer_id: PeerId, 23 | } 24 | 25 | impl PingResponse { 26 | /// Creates a new ping response. 27 | pub fn new(peer_id: PeerId) -> PingResponse { 28 | PingResponse { 29 | status: PING_RESPONSE_STATUS.into(), 30 | peer_id, 31 | } 32 | } 33 | 34 | /// Checks the status of the ping command, returns `true` if it's ok. 35 | pub fn is_ok(&self) -> bool { 36 | &*self.status.0 == PING_RESPONSE_STATUS 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /storage/src/block_provider.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use primitives::H256; 18 | use chain::IndexedBlock; 19 | use block_ref::BlockRef; 20 | 21 | pub trait BlockProvider { 22 | fn block_id(&self, height: u64) -> Option; 23 | } 24 | 25 | pub trait IndexedBlockProvider: BlockProvider { 26 | fn indexed_block(&self, block_ref: BlockRef) -> Option; 27 | } 28 | -------------------------------------------------------------------------------- /crypto/build.rs: -------------------------------------------------------------------------------- 1 | extern crate cc; 2 | 3 | fn main() { 4 | let mut build = cc::Build::new(); 5 | 6 | let tool = build.get_compiler(); 7 | 8 | if tool.is_like_gnu() || tool.is_like_clang() { 9 | build.flag_if_supported("-std=c99"); 10 | build.flag_if_supported("-msse4.1") 11 | .flag_if_supported("-maes"); 12 | } 13 | 14 | if tool.is_like_msvc() { 15 | build.include("sys/mvsc"); 16 | } 17 | 18 | build.warnings(false); 19 | 20 | build.file("sys/aesb.c") 21 | .file("sys/blake256.c") 22 | .file("sys/crypto-ops-data.c") 23 | .file("sys/crypto-ops.c") 24 | .file("sys/groestl.c") 25 | .file("sys/hash-extra-blake.c") 26 | .file("sys/hash-extra-groestl.c") 27 | .file("sys/hash-extra-jh.c") 28 | .file("sys/hash-extra-skein.c") 29 | .file("sys/hash.c") 30 | .file("sys/jh.c") 31 | .file("sys/keccak.c") 32 | .file("sys/oaes_lib.c") 33 | .file("sys/skein.c") 34 | .file("sys/slow-hash.c") 35 | .include("sys"); 36 | 37 | build.compile("cncrypto"); 38 | } 39 | -------------------------------------------------------------------------------- /p2p/src/types/cn/cmd/new_transactions.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use levin::Command; 18 | use portable_storage_utils::Blob; 19 | 20 | use types::cn::CN_COMMAND_BASE_ID; 21 | 22 | #[derive(Debug, Deserialize, Serialize)] 23 | pub struct NewTransactions { 24 | pub txs: Vec, 25 | } 26 | 27 | impl Command for NewTransactions { 28 | const ID: u32 = CN_COMMAND_BASE_ID + 2; 29 | } 30 | -------------------------------------------------------------------------------- /chain/src/transaction/tx_in_gen.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use format::{Deserialize, DeserializerStream, Error, Serialize, SerializerStream}; 10 | 11 | #[derive(Debug, Clone)] 12 | pub struct TxInGen { 13 | pub height: u64, 14 | } 15 | 16 | impl Deserialize for TxInGen { 17 | fn deserialize(deserializer: &mut DeserializerStream) -> Result { 18 | deserializer 19 | .get_u64_varint() 20 | .map(|height| TxInGen { height }) 21 | } 22 | } 23 | 24 | impl Serialize for TxInGen { 25 | fn serialize(&self, mut serializer: SerializerStream) { 26 | serializer.put_u64_varint(self.height) 27 | } 28 | 29 | fn len(&self) -> usize { 30 | use varint; 31 | 32 | varint::length(self.height) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /p2p/src/types/cn/cmd/new_block.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use levin::Command; 18 | 19 | use types::cn::{CN_COMMAND_BASE_ID, BlockCompleteEntry}; 20 | 21 | #[derive(Debug, Deserialize, Serialize)] 22 | pub struct NewBlock { 23 | pub b: BlockCompleteEntry, 24 | pub current_blockchain_height: u64, 25 | } 26 | 27 | impl Command for NewBlock { 28 | const ID: u32 = CN_COMMAND_BASE_ID + 1; 29 | } 30 | -------------------------------------------------------------------------------- /p2p/src/types/cn/cmd/request_get_objects.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use levin::Command; 18 | use primitives::H256; 19 | 20 | use types::cn::CN_COMMAND_BASE_ID; 21 | 22 | #[derive(Debug, Deserialize, Serialize)] 23 | pub struct RequestGetObjects { 24 | pub txs: Vec, 25 | pub blocks: Vec, 26 | } 27 | 28 | impl Command for RequestGetObjects { 29 | const ID: u32 = CN_COMMAND_BASE_ID + 3; 30 | } 31 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 The Xmr Developers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /chain/src/transaction/tx_out_to_key.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use keys::{PublicKey, PUBLIC_KEY_LENGTH}; 10 | use format::{Deserialize, DeserializerStream, Error, Serialize, SerializerStream}; 11 | 12 | #[derive(Debug, Clone)] 13 | pub struct TxOutToKey { 14 | pub key: PublicKey, 15 | } 16 | 17 | impl Deserialize for TxOutToKey { 18 | fn deserialize(deserializer: &mut DeserializerStream) -> Result { 19 | deserializer 20 | .get_deserializable() 21 | .map(|key| TxOutToKey { key }) 22 | } 23 | } 24 | 25 | impl Serialize for TxOutToKey { 26 | fn serialize(&self, mut serializer: SerializerStream) { 27 | serializer.put_serializable(&self.key); 28 | } 29 | 30 | fn len(&self) -> usize { 31 | PUBLIC_KEY_LENGTH 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /p2p/src/types/cn/cmd/new_fluffy_block.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use levin::Command; 18 | 19 | use types::cn::{CN_COMMAND_BASE_ID, BlockCompleteEntry}; 20 | 21 | #[derive(Debug, Deserialize, Serialize)] 22 | pub struct NewFluffyBlock { 23 | pub b: BlockCompleteEntry, 24 | pub current_blockchain_height: u64, 25 | } 26 | 27 | impl Command for NewFluffyBlock { 28 | const ID: u32 = CN_COMMAND_BASE_ID + 8; 29 | } 30 | -------------------------------------------------------------------------------- /chain/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 The Xmr Developers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /keys/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 The Xmr Developers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /levin/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 The Xmr Developers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /rct/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 The Xmr Developers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /crypto/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 The Xmr Developers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /format/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 The Xmr Developers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /primitives/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 The Xmr Developers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /varint/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 The Xmr Developers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /p2p/src/types/cn/cmd/request_chain.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use levin::Command; 18 | use portable_storage_utils::stl::StlLinkedList; 19 | use primitives::H256; 20 | 21 | use types::cn::CN_COMMAND_BASE_ID; 22 | 23 | #[derive(Debug, Deserialize, Serialize)] 24 | pub struct RequestChain { 25 | pub block_ids: StlLinkedList, 26 | } 27 | 28 | impl Command for RequestChain { 29 | const ID: u32 = CN_COMMAND_BASE_ID + 6; 30 | } 31 | -------------------------------------------------------------------------------- /portable-storage/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 The Xmr Developers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /storage/src/block_ref.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use primitives::H256; 18 | 19 | #[derive(Debug)] 20 | pub enum BlockRef { 21 | Height(u64), 22 | Id(H256), 23 | } 24 | 25 | impl From for BlockRef { 26 | fn from(height: u64) -> BlockRef { 27 | BlockRef::Height(height) 28 | } 29 | } 30 | 31 | 32 | impl From for BlockRef { 33 | fn from(id: H256) -> BlockRef { 34 | BlockRef::Id(id) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /chain/src/transaction/tx_out_to_script_hash.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use primitives::{H256, H256_LENGTH}; 10 | use format::{Deserialize, DeserializerStream, Error, Serialize, SerializerStream}; 11 | 12 | #[derive(Debug, Clone)] 13 | pub struct TxOutToScriptHash { 14 | pub hash: H256, 15 | } 16 | 17 | impl Deserialize for TxOutToScriptHash { 18 | fn deserialize(deserializer: &mut DeserializerStream) -> Result { 19 | deserializer 20 | .get_deserializable() 21 | .map(|hash| TxOutToScriptHash { hash }) 22 | } 23 | } 24 | 25 | impl Serialize for TxOutToScriptHash { 26 | fn serialize(&self, mut serializer: SerializerStream) { 27 | serializer.put_serializable(&self.hash); 28 | } 29 | 30 | fn len(&self) -> usize { 31 | H256_LENGTH 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /portable-storage-utils/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 The Xmr Developers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /p2p/src/types/mod.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use levin::COMMAND_BASE_ID; 18 | 19 | pub const P2P_COMMAND_BASE_ID: u32 = COMMAND_BASE_ID; 20 | 21 | pub mod cmd; 22 | pub mod cn; 23 | 24 | mod basic_node_data; 25 | mod ipv4_address; 26 | mod peerid; 27 | mod peerlist_entry; 28 | 29 | pub use self::basic_node_data::BasicNodeData; 30 | pub use self::ipv4_address::Ipv4Address; 31 | pub use self::peerid::PeerId; 32 | pub use self::peerlist_entry::PeerlistEntry; 33 | -------------------------------------------------------------------------------- /chain/src/indexed_block.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use std::cmp::PartialEq; 10 | 11 | use primitives::H256; 12 | 13 | use block::Block; 14 | 15 | pub struct IndexedBlock { 16 | pub id: H256, 17 | pub raw: Block, 18 | } 19 | 20 | impl IndexedBlock { 21 | pub fn new(block: Block, id: H256) -> IndexedBlock { 22 | IndexedBlock { id, raw: block } 23 | } 24 | 25 | pub fn id(&self) -> &H256 { 26 | &self.id 27 | } 28 | } 29 | 30 | impl From for IndexedBlock { 31 | fn from(block: Block) -> IndexedBlock { 32 | IndexedBlock { 33 | id: block.id(), 34 | raw: block, 35 | } 36 | } 37 | } 38 | 39 | impl PartialEq for IndexedBlock { 40 | fn eq(&self, other: &IndexedBlock) -> bool { 41 | self.id == other.id 42 | } 43 | } 44 | 45 | impl Eq for IndexedBlock {} 46 | -------------------------------------------------------------------------------- /storage/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | extern crate xmr_chain as chain; 18 | extern crate xmr_primitives as primitives; 19 | 20 | mod best_block; 21 | mod block_chain; 22 | mod block_provider; 23 | mod block_ref; 24 | mod store; 25 | 26 | pub use best_block::BestBlock; 27 | pub use block_chain::BlockChain; 28 | pub use block_provider::{BlockProvider, IndexedBlockProvider}; 29 | pub use block_ref::BlockRef; 30 | pub use store::{AsSubstore, CanonStore, Store, SharedStore}; 31 | -------------------------------------------------------------------------------- /db/src/error.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use std::io; 18 | 19 | #[derive(Debug, Fail)] 20 | pub enum Error { 21 | #[fail(display = "{}", _0)] 22 | Io(#[cause] 23 | io::Error), 24 | #[fail(display = "{}", _0)] 25 | DatabaseError(String), 26 | #[fail(display = "database is already open.")] 27 | AlreadyOpen, 28 | #[fail(display = "unknown block parent")] 29 | UnknownParent, 30 | #[fail(display = "can't canonize block")] 31 | CannotCanonize, 32 | } 33 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xmr" 3 | version = "0.1.0" 4 | authors = [ 5 | "Jean Pierre Dudey ", 6 | "Parity Technologies " 7 | ] 8 | license = "GPL-3.0-only" 9 | description = "Monero node implementation in Rust." 10 | documentation = "https://github.com/xmr-rs/xmr" 11 | homepage = "https://github.com/xmr-rs/xmr" 12 | repository = "https://github.com/xmr-rs/xmr.git" 13 | include = ["LICENSE-GPL"] 14 | 15 | [[bin]] 16 | name = "dxmr" 17 | path = "dxmr/main.rs" 18 | 19 | [workspace] 20 | members = [ 21 | "chain", 22 | "crypto", 23 | "db", 24 | "format", 25 | "keys", 26 | "levin", 27 | "network", 28 | "p2p", 29 | "portable-storage-utils", 30 | "portable-storage", 31 | "primitives", 32 | "rct", 33 | "storage", 34 | "sync", 35 | "varint", 36 | "verification", 37 | ] 38 | 39 | [dependencies] 40 | app_dirs = "1.1.1" 41 | clap = "2.29.2" 42 | 43 | env_logger = "0.5.0" 44 | log = "0.4.1" 45 | 46 | failure = "0.1.1" 47 | 48 | rand = "0.4.2" 49 | 50 | xmr-chain = { path = "chain" } 51 | xmr-db = { path = "db" } 52 | xmr-network = { path = "network" } 53 | xmr-storage = { path = "storage" } 54 | xmr-p2p = { path = "p2p" } 55 | xmr-sync = { path = "sync" } 56 | -------------------------------------------------------------------------------- /p2p/src/types/cn/cmd/request_fluffy_missing_tx.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | 18 | use levin::Command; 19 | use portable_storage_utils::stl::StlVector; 20 | use primitives::H256; 21 | 22 | use types::cn::CN_COMMAND_BASE_ID; 23 | 24 | #[derive(Debug, Deserialize, Serialize)] 25 | pub struct RequestFluffyMissingTx { 26 | pub block_hash: H256, 27 | pub current_blockchain_length: u64, 28 | pub missing_tx_indices: StlVector, 29 | } 30 | 31 | impl Command for RequestFluffyMissingTx { 32 | const ID: u32 = CN_COMMAND_BASE_ID + 9; 33 | } 34 | -------------------------------------------------------------------------------- /chain/src/transaction/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | mod transaction; 10 | mod transaction_prefix; 11 | 12 | pub use self::transaction::{Transaction, SignatureType}; 13 | pub use self::transaction_prefix::TransactionPrefix; 14 | 15 | mod tx_in; 16 | mod tx_in_gen; 17 | mod tx_in_to_key; 18 | mod tx_in_to_script; 19 | mod tx_in_to_script_hash; 20 | 21 | pub use self::tx_in::TxIn; 22 | pub use self::tx_in_gen::TxInGen; 23 | pub use self::tx_in_to_key::TxInToKey; 24 | pub use self::tx_in_to_script::TxInToScript; 25 | pub use self::tx_in_to_script_hash::TxInToScriptHash; 26 | 27 | mod tx_out; 28 | mod tx_out_target; 29 | mod tx_out_to_key; 30 | mod tx_out_to_script; 31 | mod tx_out_to_script_hash; 32 | 33 | pub use self::tx_out::TxOut; 34 | pub use self::tx_out_target::TxOutTarget; 35 | pub use self::tx_out_to_key::TxOutToKey; 36 | pub use self::tx_out_to_script::TxOutToScript; 37 | pub use self::tx_out_to_script_hash::TxOutToScriptHash; 38 | -------------------------------------------------------------------------------- /db/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | extern crate bytes; 18 | extern crate parking_lot; 19 | extern crate sanakirja; 20 | extern crate rand; 21 | 22 | extern crate failure; 23 | #[macro_use] 24 | extern crate failure_derive; 25 | 26 | extern crate xmr_chain as chain; 27 | extern crate xmr_format as format; 28 | extern crate xmr_primitives as primitives; 29 | extern crate xmr_storage as storage; 30 | 31 | pub mod kv; 32 | 33 | mod block_chain_db; 34 | mod error; 35 | 36 | pub use self::block_chain_db::BlockChainDatabase; 37 | pub use self::error::Error; 38 | -------------------------------------------------------------------------------- /p2p/src/types/basic_node_data.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use portable_storage_utils::BytesUuid; 18 | use types::PeerId; 19 | 20 | /// Basic information about a node. 21 | #[derive(Debug, Default, Clone, Deserialize, Serialize)] 22 | pub struct BasicNodeData { 23 | /// The peer's local time 24 | pub local_time: u64, 25 | 26 | /// The peer's listening port. 27 | pub my_port: u32, 28 | 29 | /// The network UUID, should be the same for all peers. 30 | pub network_id: BytesUuid, 31 | 32 | /// The peer's id. 33 | pub peer_id: PeerId, 34 | } 35 | -------------------------------------------------------------------------------- /keys/src/utils.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use std::fmt::{self, Formatter}; 10 | 11 | pub fn fmt_byte_slice(slice: &[u8], fmt: &mut Formatter) -> fmt::Result { 12 | write!(fmt, "\"")?; 13 | 14 | for b in slice.iter() { 15 | write!(fmt, "{:02x}", b)?; 16 | } 17 | 18 | write!(fmt, "\"") 19 | } 20 | 21 | #[cfg(test)] 22 | pub mod tests { 23 | use super::*; 24 | 25 | use std::fmt; 26 | 27 | #[test] 28 | fn fmt_byte_slice_() { 29 | struct Blob([u8; 32]); 30 | impl fmt::Debug for Blob { 31 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { 32 | fmt_byte_slice(&self.0, fmt) 33 | } 34 | } 35 | 36 | let blob = Blob([0u8; 32]); 37 | 38 | 39 | let blob_str = format!("{:?}", blob); 40 | 41 | assert_eq!(&*blob_str, 42 | "\"0000000000000000000000000000000000000000000000000000000000000000\""); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /p2p/src/types/cn/cmd/response_get_objects.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | 18 | use levin::Command; 19 | use primitives::H256; 20 | use portable_storage_utils::Blob; 21 | 22 | use types::cn::{CN_COMMAND_BASE_ID, BlockCompleteEntry}; 23 | 24 | #[derive(Debug, Deserialize, Serialize)] 25 | pub struct ResponseGetObjects { 26 | pub txs: Vec, 27 | pub blocks: Vec, 28 | pub missed_ids: Vec, 29 | pub current_blockchain_height: u64, 30 | } 31 | 32 | impl Command for ResponseGetObjects { 33 | const ID: u32 = CN_COMMAND_BASE_ID + 4; 34 | } 35 | -------------------------------------------------------------------------------- /p2p/src/types/cn/cmd/response_chain_entry.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use levin::Command; 18 | use portable_storage_utils::stl::StlLinkedList; 19 | use primitives::H256; 20 | 21 | use types::cn::CN_COMMAND_BASE_ID; 22 | 23 | #[derive(Debug, Deserialize, Serialize)] 24 | pub struct ResponseChainEntry { 25 | pub start_height: u64, 26 | pub total_height: u64, 27 | pub cummulative_difficulty: u64, 28 | #[serde(rename = "m_block_ids")] 29 | pub block_ids: StlLinkedList, 30 | } 31 | 32 | impl Command for ResponseChainEntry { 33 | const ID: u32 = CN_COMMAND_BASE_ID + 7; 34 | } 35 | -------------------------------------------------------------------------------- /chain/src/transaction/tx_out.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use transaction::TxOutTarget; 10 | use format::{Deserialize, DeserializerStream, Error, Serialize, SerializerStream}; 11 | 12 | /// Transaction output. 13 | #[derive(Debug, Clone)] 14 | pub struct TxOut { 15 | pub amount: u64, 16 | pub target: TxOutTarget, 17 | } 18 | 19 | impl Deserialize for TxOut { 20 | fn deserialize(deserializer: &mut DeserializerStream) -> Result { 21 | let amount = deserializer.get_u64_varint()?; 22 | let target = deserializer.get_deserializable()?; 23 | 24 | Ok(TxOut { amount, target }) 25 | } 26 | } 27 | 28 | impl Serialize for TxOut { 29 | fn serialize(&self, mut serializer: SerializerStream) { 30 | serializer.put_u64_varint(self.amount); 31 | serializer.put_serializable(&self.target); 32 | } 33 | 34 | fn len(&self) -> usize { 35 | use varint; 36 | 37 | varint::length(self.amount) + self.target.len() 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /sync/src/synchronization_chain.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use primitives::H256; 18 | 19 | use types::StorageRef; 20 | 21 | pub struct Chain { 22 | storage: StorageRef, 23 | } 24 | 25 | impl Chain { 26 | pub fn new(storage: StorageRef) -> Chain { 27 | Chain { storage } 28 | } 29 | 30 | pub fn storage(&self) -> StorageRef { 31 | self.storage.clone() 32 | } 33 | 34 | pub fn have_block(&self, id: H256) -> bool { 35 | self.storage.indexed_block(id.into()).is_some() 36 | } 37 | 38 | pub fn height(&self) -> u64 { 39 | self.storage.height() 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /levin/src/net/bucket_stream.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use std::io; 10 | use std::mem::replace; 11 | 12 | use futures::{Future, Poll, Async}; 13 | use futures::stream::Stream; 14 | 15 | use tokio_io::AsyncRead; 16 | 17 | use bucket::{Bucket, Receive}; 18 | use error::Result; 19 | 20 | /// Creates the bucket stream. 21 | pub fn bucket_stream(a: A) -> BucketStream 22 | where A: AsyncRead 23 | { 24 | BucketStream { future: Bucket::receive_future(a) } 25 | } 26 | 27 | /// A stream of buckets. 28 | #[derive(Debug)] 29 | pub struct BucketStream { 30 | future: Receive, 31 | } 32 | 33 | impl Stream for BucketStream 34 | where A: AsyncRead 35 | { 36 | type Item = Result; 37 | type Error = io::Error; 38 | 39 | fn poll(&mut self) -> Poll, io::Error> { 40 | let (stream, result) = try_ready!(self.future.poll()); 41 | 42 | replace(&mut self.future, Bucket::receive_future(stream)); 43 | 44 | Ok(Async::Ready(Some(result))) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 |

5 | 6 | 7 | 8 | 9 | 10 | 11 |

12 | 13 | # Xmr Monero node 14 | 15 | Xmr is an implementation of the Monero cryptocurrency. It aims to be a full 16 | Monero node with wallet functionality. 17 | 18 | *This is a work in progress that is not yet functional* 19 | 20 | ## Building Xmr 21 | 22 | Xmr is built with the [Cargo][1] package manager. First, ensure you have the 23 | latest stable Rust version (it hasn't been tested with older Rust versions). 24 | Then run this in the `xmr` repository folder: 25 | 26 | [1]: https://crates.io/ 27 | 28 | ```bash 29 | cargo build 30 | ``` 31 | 32 | This will create the `dxmr` binary in the *target/debug* directory. 33 | 34 | To build the binary optimized for release: 35 | 36 | ```bash 37 | cargo build --release 38 | ``` 39 | 40 | ## License 41 | Some parts of the code are GPLv3 due to them being base on the `parity-bitcoin` code. 42 | However the code that isn't related to the `parity-bitcoin` code is licensed under 43 | the MIT or Apache 2.0 at your option. 44 | -------------------------------------------------------------------------------- /p2p/src/types/cn/cmd/mod.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | mod new_block; 18 | mod new_fluffy_block; 19 | mod new_transactions; 20 | mod request_chain; 21 | mod request_fluffy_missing_tx; 22 | mod request_get_objects; 23 | mod response_chain_entry; 24 | mod response_get_objects; 25 | 26 | pub use self::new_block::NewBlock; 27 | pub use self::new_fluffy_block::NewFluffyBlock; 28 | pub use self::new_transactions::NewTransactions; 29 | pub use self::request_chain::RequestChain; 30 | pub use self::request_fluffy_missing_tx::RequestFluffyMissingTx; 31 | pub use self::request_get_objects::RequestGetObjects; 32 | pub use self::response_chain_entry::ResponseChainEntry; 33 | pub use self::response_get_objects::ResponseGetObjects; 34 | -------------------------------------------------------------------------------- /p2p/src/config.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use std::net::SocketAddr; 18 | use network::Network; 19 | 20 | use types::PeerId; 21 | 22 | /// P2P configuration. 23 | #[derive(Debug, Clone)] 24 | pub struct Config { 25 | /// Number of threads. 26 | pub threads: usize, 27 | /// The network id. 28 | pub network: Network, 29 | /// Peers to connect. 30 | pub peers: Vec, 31 | /// Listening port. 32 | pub listen_port: Option, 33 | /// Hide my port. 34 | pub hide_my_port: bool, 35 | /// Maximum of outbound peers. 36 | pub out_peers: u32, 37 | /// Maximum of inbound peers. 38 | pub in_peers: u32, 39 | /// The peer ID. 40 | pub peer_id: PeerId, 41 | } 42 | -------------------------------------------------------------------------------- /sync/src/types.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use std::sync::Arc; 18 | 19 | use parking_lot::Mutex; 20 | 21 | use storage::SharedStore; 22 | 23 | use local_node::LocalNode; 24 | use synchronization_client::SynchronizationClient; 25 | use synchronization_client_core::SynchronizationClientCore; 26 | use synchronization_executor::LocalSynchronizationTaskExecutor; 27 | use synchronization_peers::Peers; 28 | 29 | pub type LocalNodeRef = Arc; 30 | pub type ClientRef = Arc; 31 | pub type ClientCoreRef = Arc>; 32 | pub type PeersRef = Arc; 33 | pub type ExecutorRef = Arc; 34 | pub type StorageRef = SharedStore; 35 | pub type PeerIndex = usize; 36 | -------------------------------------------------------------------------------- /ci/install.sh: -------------------------------------------------------------------------------- 1 | set -ex 2 | 3 | main() { 4 | local target= 5 | if [ $TRAVIS_OS_NAME = linux ]; then 6 | target=x86_64-unknown-linux-musl 7 | sort=sort 8 | else 9 | target=x86_64-apple-darwin 10 | sort=gsort # for `sort --sort-version`, from brew's coreutils. 11 | fi 12 | 13 | # Builds for iOS are done on OSX, but require the specific target to be 14 | # installed. 15 | case $TARGET in 16 | aarch64-apple-ios) 17 | rustup target install aarch64-apple-ios 18 | ;; 19 | armv7-apple-ios) 20 | rustup target install armv7-apple-ios 21 | ;; 22 | armv7s-apple-ios) 23 | rustup target install armv7s-apple-ios 24 | ;; 25 | i386-apple-ios) 26 | rustup target install i386-apple-ios 27 | ;; 28 | x86_64-apple-ios) 29 | rustup target install x86_64-apple-ios 30 | ;; 31 | esac 32 | 33 | # This fetches latest stable release 34 | local tag=$(git ls-remote --tags --refs --exit-code https://github.com/japaric/cross \ 35 | | cut -d/ -f3 \ 36 | | grep -E '^v[0.1.0-9.]+$' \ 37 | | $sort --version-sort \ 38 | | tail -n1) 39 | curl -LSfs https://japaric.github.io/trust/install.sh | \ 40 | sh -s -- \ 41 | --force \ 42 | --git japaric/cross \ 43 | --tag $tag \ 44 | --target $target 45 | } 46 | 47 | main 48 | -------------------------------------------------------------------------------- /p2p/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | extern crate futures; 18 | extern crate futures_cpupool; 19 | extern crate tokio_core; 20 | extern crate tokio_io; 21 | 22 | extern crate bytes; 23 | extern crate parking_lot; 24 | extern crate rand; 25 | extern crate uuid; 26 | 27 | extern crate serde; 28 | #[macro_use] 29 | extern crate serde_derive; 30 | 31 | extern crate failure; 32 | #[macro_use] 33 | extern crate log; 34 | 35 | extern crate xmr_levin as levin; 36 | extern crate xmr_network as network; 37 | extern crate xmr_portable_storage as portable_storage; 38 | extern crate xmr_portable_storage_utils as portable_storage_utils; 39 | extern crate xmr_primitives as primitives; 40 | extern crate xmr_storage as storage; 41 | 42 | pub mod event_loop; 43 | pub mod types; 44 | pub mod p2p; 45 | pub mod net; 46 | pub mod protocol; 47 | pub mod config; 48 | pub mod utils; 49 | 50 | pub use p2p::P2P; 51 | pub use event_loop::{event_loop, forever}; 52 | pub use config::Config; 53 | -------------------------------------------------------------------------------- /p2p/src/utils/peerlist.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use std::collections::{HashMap, LinkedList}; 18 | use std::net::SocketAddr; 19 | 20 | use portable_storage_utils::stl::StlLinkedList; 21 | 22 | use types::PeerlistEntry; 23 | 24 | #[derive(Debug)] 25 | pub struct Peerlist { 26 | pub list: HashMap, 27 | } 28 | 29 | impl Peerlist { 30 | pub fn new() -> Peerlist { 31 | Peerlist { list: HashMap::new() } 32 | } 33 | 34 | pub fn insert(&mut self, address: SocketAddr, entry: PeerlistEntry) { 35 | self.list.insert(address, entry); 36 | } 37 | 38 | pub fn remove(&mut self, addr: &SocketAddr) -> Option { 39 | self.list.remove(&addr) 40 | } 41 | 42 | pub fn stl_peerlist(&self) -> StlLinkedList { 43 | let mut ll = LinkedList::new(); 44 | for peer in self.list.iter() { 45 | ll.push_back(peer.1.clone()) 46 | } 47 | 48 | ll.into() 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /levin/src/net/handlers.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use std::sync::Arc; 10 | use std::net::SocketAddr; 11 | 12 | use portable_storage::Section; 13 | 14 | /// A trait that handles notifications. 15 | pub trait NotificationHandler: Send + Sync + 'static { 16 | /// This is the function that handles the notification. 17 | fn call(&self, addr: SocketAddr, request: Section); 18 | } 19 | 20 | impl NotificationHandler for F 21 | where F: Send + Sync + 'static + Fn(SocketAddr, Section) 22 | { 23 | fn call(&self, addr: SocketAddr, request: Section) { 24 | self(addr, request) 25 | } 26 | } 27 | 28 | /// A trait that handles invokations. 29 | pub trait InvokationHandler: Send + Sync + 'static { 30 | /// This handles the invokation. 31 | fn call(&self, addr: SocketAddr, request: Section) -> Result, i32>; 32 | } 33 | 34 | impl InvokationHandler for F 35 | where F: Send + Sync + 'static + Fn(SocketAddr, Section) -> Result, i32> 36 | { 37 | fn call(&self, addr: SocketAddr, request: Section) -> Result, i32> { 38 | self(addr, request) 39 | } 40 | } 41 | 42 | /// A handler for a invokation/notification. 43 | #[allow(missing_debug_implementations)] 44 | #[derive(Clone)] 45 | pub enum RemoteHandler { 46 | /// A notification. 47 | Notification(Arc), 48 | 49 | /// An invokation. 50 | Invokation(Arc), 51 | } 52 | -------------------------------------------------------------------------------- /levin/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | #![deny(anonymous_parameters, missing_debug_implementations, missing_docs, trivial_casts, trivial_numeric_casts, unreachable_pub, unsafe_code, unstable_features, unused_extern_crates, unused_import_braces, unused_qualifications)] 10 | 11 | //! # xmr-levin 12 | //! 13 | //! Rust implementation of the levin protocol used in the Monero cryptocurrency. 14 | //! 15 | //! # Usage: 16 | //! 17 | //! Add it to the dependencies in your `Cargo.toml`: 18 | //! 19 | //! ```toml 20 | //! [dependencies] 21 | //! xmr-levin = { git = "https://www.github.com/xmr-rs/xmr", version = "0.1.0" } 22 | //! ``` 23 | //! 24 | //! And import it in your crate like this: 25 | //! 26 | //! ```rust 27 | //! extern crate xmr_levin; 28 | //! // or if you're using it inside a crate of the xmr project: 29 | //! extern crate xmr_levin as levin; 30 | //! ``` 31 | //! 32 | 33 | #[macro_use] 34 | extern crate futures; 35 | extern crate tokio_core; 36 | extern crate tokio_io; 37 | 38 | extern crate crossbeam; 39 | extern crate parking_lot; 40 | 41 | extern crate bytes; 42 | 43 | #[macro_use] 44 | extern crate failure_derive; 45 | extern crate failure; 46 | 47 | #[macro_use] 48 | extern crate log; 49 | 50 | extern crate xmr_portable_storage as portable_storage; 51 | 52 | pub mod bucket; 53 | pub mod net; 54 | 55 | mod command; 56 | mod error; 57 | 58 | pub use command::{COMMAND_BASE_ID, Command, Id}; 59 | pub use error::{BucketHeadError, Error, Result}; 60 | -------------------------------------------------------------------------------- /storage/src/store.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use std::sync::Arc; 18 | use std::collections::LinkedList; 19 | 20 | use primitives::H256; 21 | use best_block::BestBlock; 22 | use block_chain::BlockChain; 23 | use block_provider::{BlockProvider, IndexedBlockProvider}; 24 | 25 | pub trait CanonStore: Store { 26 | fn as_store(&self) -> &Store; 27 | } 28 | 29 | /// Blockchain storage interface. 30 | pub trait Store: AsSubstore { 31 | /// Get the best block. 32 | fn best_block(&self) -> BestBlock; 33 | 34 | /// Get the blockchain height. 35 | fn height(&self) -> u64; 36 | 37 | fn short_chain_history(&self) -> LinkedList; 38 | } 39 | 40 | /// Allows casting Arc to reference to any substore type 41 | pub trait AsSubstore: BlockChain + IndexedBlockProvider { 42 | fn as_block_provider(&self) -> &BlockProvider; 43 | } 44 | 45 | impl AsSubstore for T 46 | where T: BlockChain + IndexedBlockProvider 47 | { 48 | fn as_block_provider(&self) -> &BlockProvider { 49 | &*self 50 | } 51 | } 52 | 53 | pub type SharedStore = Arc; 54 | -------------------------------------------------------------------------------- /dxmr/peers.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use std::net::{SocketAddr, ToSocketAddrs}; 18 | use network::Network; 19 | 20 | pub fn default_peers(network: Network) -> Vec { 21 | let addrs: &[&'static str] = match network { 22 | Network::Testnet => { 23 | &["212.83.175.67:28080", 24 | "5.9.100.248:28080", 25 | "163.172.182.165:28080", 26 | "195.154.123.123:28080", 27 | "212.83.172.165:28080"] 28 | } 29 | Network::Mainnet => { 30 | &["107.152.130.98:18080", 31 | "212.83.175.67:18080", 32 | "5.9.100.248:18080", 33 | "163.172.182.165:18080", 34 | "161.67.132.39:18080", 35 | "198.74.231.92:18080", 36 | "195.154.123.123:28080", 37 | "212.83.172.165:28080"] 38 | } 39 | }; 40 | 41 | // TODO: use expect instead of unwrap. 42 | addrs 43 | .iter() 44 | .map(|addr| (*addr).to_socket_addrs().unwrap().next().unwrap()) 45 | .collect() 46 | } 47 | 48 | // TODO: Add support for seed nodes 49 | -------------------------------------------------------------------------------- /crypto/sys/mvsc/alloca.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #pragma once 32 | 33 | #define alloca(size) _alloca(size) 34 | -------------------------------------------------------------------------------- /portable-storage-utils/src/blob.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use std::fmt; 10 | 11 | use serde::de::{Deserialize, Deserializer, Error, Visitor}; 12 | use serde::ser::{Serialize, Serializer}; 13 | 14 | #[derive(Debug, Default, Clone, Eq, PartialEq, Hash)] 15 | pub struct Blob(pub Vec); 16 | 17 | impl From> for Blob { 18 | fn from(v: Vec) -> Blob { 19 | Blob(v) 20 | } 21 | } 22 | 23 | impl From<&'static [u8]> for Blob { 24 | fn from(v: &'static [u8]) -> Blob { 25 | Blob(v.to_vec()) 26 | } 27 | } 28 | 29 | impl<'de> Deserialize<'de> for Blob { 30 | fn deserialize(deserializer: D) -> Result 31 | where D: Deserializer<'de> 32 | { 33 | struct BlobVisitor; 34 | 35 | impl<'de> Visitor<'de> for BlobVisitor { 36 | type Value = Blob; 37 | 38 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 39 | write!(formatter, "a binary blob") 40 | } 41 | 42 | fn visit_bytes(self, v: &[u8]) -> Result 43 | where E: Error 44 | { 45 | Ok(Blob(v.to_vec())) 46 | } 47 | } 48 | 49 | deserializer.deserialize_bytes(BlobVisitor) 50 | } 51 | } 52 | 53 | impl Serialize for Blob { 54 | fn serialize(&self, serializer: S) -> Result 55 | where S: Serializer 56 | { 57 | serializer.serialize_bytes(self.0.as_slice()) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /chain/src/transaction/tx_in_to_script.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use primitives::H256; 10 | use format::{Deserialize, DeserializerStream, Error, Serialize, SerializerStream}; 11 | 12 | #[derive(Debug, Clone)] 13 | pub struct TxInToScript { 14 | pub prev: H256, 15 | pub prevout: u64, 16 | pub sigset: Vec, 17 | } 18 | 19 | impl Deserialize for TxInToScript { 20 | fn deserialize(deserializer: &mut DeserializerStream) -> Result { 21 | let prev = deserializer.get_deserializable()?; 22 | let prevout = deserializer.get_u64_varint()?; 23 | 24 | let sigset_length = deserializer.get_u64_varint()? as usize; 25 | let sigset = deserializer.get_blob(sigset_length)?; 26 | 27 | Ok(TxInToScript { 28 | prev, 29 | prevout, 30 | sigset, 31 | }) 32 | } 33 | } 34 | 35 | impl Serialize for TxInToScript { 36 | fn serialize(&self, mut serializer: SerializerStream) { 37 | serializer.put_serializable(&self.prev); 38 | serializer.put_u64_varint(self.prevout); 39 | 40 | serializer.put_u64_varint(self.sigset.len() as u64); 41 | serializer.put_blob(self.sigset.as_slice()); 42 | } 43 | 44 | fn len(&self) -> usize { 45 | use varint; 46 | 47 | let mut sum = 0; 48 | sum += self.prev.len(); 49 | sum += varint::length(self.prevout); 50 | sum += varint::length(self.sigset.len()); 51 | sum += self.sigset.len(); 52 | sum 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /portable-storage-utils/src/stl/element.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use primitives::{H256, H256_LENGTH}; 10 | use bytes::{BytesMut, BufMut, Buf, IntoBuf, LittleEndian}; 11 | 12 | #[derive(Debug, Clone, Fail)] 13 | pub enum Error { 14 | #[fail(display = "invalid length ({})", _0)] 15 | InvalidLength(usize), 16 | } 17 | 18 | /// A stl container element. 19 | pub trait StlElement: Sized { 20 | /// The length in bytes of this element. 21 | const LENGTH: usize; 22 | 23 | // TODO: `v.len()` should always be == to LENGTH 24 | // making Error::InvalidLength. 25 | fn from_bytes(v: &[u8]) -> Result; 26 | fn to_bytes(&self, buf: &mut BytesMut); 27 | } 28 | 29 | impl StlElement for u64 { 30 | const LENGTH: usize = 8; 31 | 32 | fn from_bytes(v: &[u8]) -> Result { 33 | if v.len() != 8 { 34 | return Err(Error::InvalidLength(v.len())); 35 | } 36 | 37 | Ok(v.into_buf().get_u64::()) 38 | } 39 | 40 | fn to_bytes(&self, buf: &mut BytesMut) { 41 | buf.put_u64::(*self) 42 | } 43 | } 44 | 45 | impl StlElement for H256 { 46 | const LENGTH: usize = H256_LENGTH; 47 | 48 | fn from_bytes(v: &[u8]) -> Result { 49 | if v.len() != H256_LENGTH { 50 | return Err(Error::InvalidLength(v.len())); 51 | } 52 | 53 | Ok(H256::from_bytes(v)) 54 | } 55 | 56 | fn to_bytes(&self, buf: &mut BytesMut) { 57 | buf.put(self.as_bytes()) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /portable-storage-utils/src/bytes_uuid.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use std::fmt; 10 | 11 | use uuid; 12 | 13 | use serde::de::{Deserialize, Deserializer, Error, Visitor}; 14 | use serde::ser::{Serialize, Serializer}; 15 | 16 | #[derive(Debug, Default, Clone, Eq, PartialEq, Hash)] 17 | pub struct BytesUuid(pub uuid::Uuid); 18 | 19 | impl From for BytesUuid { 20 | fn from(v: uuid::Uuid) -> BytesUuid { 21 | BytesUuid(v) 22 | } 23 | } 24 | 25 | impl<'de> Deserialize<'de> for BytesUuid { 26 | fn deserialize(deserializer: D) -> Result 27 | where D: Deserializer<'de> 28 | { 29 | struct UuidVisitor; 30 | 31 | impl<'de> Visitor<'de> for UuidVisitor { 32 | type Value = BytesUuid; 33 | 34 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 35 | write!(formatter, "an uuid") 36 | } 37 | 38 | fn visit_bytes(self, v: &[u8]) -> Result 39 | where E: Error 40 | { 41 | uuid::Uuid::from_bytes(v) 42 | .map(BytesUuid::from) 43 | .map_err(E::custom) 44 | } 45 | } 46 | 47 | deserializer.deserialize_bytes(UuidVisitor) 48 | } 49 | } 50 | 51 | impl Serialize for BytesUuid { 52 | fn serialize(&self, serializer: S) -> Result 53 | where S: Serializer 54 | { 55 | serializer.serialize_bytes(self.0.as_bytes()) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /levin/src/error.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use std::result; 10 | 11 | /// A result with a levin error. 12 | pub type Result = result::Result; 13 | 14 | /// A levin error. 15 | #[derive(Debug, Fail)] 16 | pub enum Error { 17 | /// An error when reading `BucketHead`. 18 | #[fail(display = "couldn't parse bucket head: {}", _0)] 19 | BucketHead(#[cause] 20 | BucketHeadError), 21 | 22 | /// The command is invalid. 23 | #[fail(display = "the bucket command id ({}) is invalid", _0)] 24 | InvalidCommandId(u32), 25 | } 26 | 27 | impl From for Error { 28 | fn from(e: BucketHeadError) -> Error { 29 | Error::BucketHead(e) 30 | } 31 | } 32 | 33 | /// An error returned when the data of `BucketHead` is invalid. 34 | #[derive(Debug, Fail)] 35 | pub enum BucketHeadError { 36 | /// The version isn't supported. 37 | #[fail(display = "invalid levin protocol version (provided value: {})", _0)] 38 | InvalidProtocolVersion(u32), 39 | 40 | /// Invalid signature 41 | #[fail(display = "invalid bucket signature (bad signature: {:08X})", _0)] 42 | InvalidSignature(u64), 43 | 44 | /// An error code was returned. 45 | #[fail(display = "the bucket has an error number: {}", _0)] 46 | ReturnCode(i32), 47 | 48 | /// Packet too big. The maximum size of a levin bucket is [this][1] 49 | /// 50 | /// [1]: /bucket/constant.LEVIN_DEFAULT_MAX_PACKET_SIZE.html 51 | #[fail(display = "the bucket size is too big ({} bytes)", _0)] 52 | TooBig(u64), 53 | } 54 | -------------------------------------------------------------------------------- /p2p/src/net/peer_context.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use std::sync::Arc; 18 | use std::net::SocketAddr; 19 | 20 | use levin::Command; 21 | use portable_storage::Section; 22 | 23 | use p2p::Context; 24 | 25 | pub struct PeerContext { 26 | context: Arc, 27 | addr: SocketAddr, 28 | } 29 | 30 | impl PeerContext { 31 | pub fn new(context: Arc, addr: SocketAddr) -> PeerContext { 32 | PeerContext { context, addr } 33 | } 34 | 35 | pub fn notify(&self, request: Section) 36 | where C: Command 37 | { 38 | trace!("peer ({}) context notify - {:?} ", self.addr, request); 39 | 40 | let res = self.context 41 | .command_streams 42 | .read() 43 | .get(&self.addr) 44 | .cloned(); 45 | if let Some(command_stream) = res { 46 | command_stream.notify::(request) 47 | } else { 48 | warn!("couldn't get command stream, closed connection? address {}", 49 | self.addr); 50 | return; 51 | }; 52 | } 53 | 54 | pub fn close(&self) { 55 | Context::close(self.context.clone(), &self.addr); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /sync/src/synchronization_executor.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use p2p::types::cn; 18 | 19 | use types::{PeersRef, PeerIndex}; 20 | 21 | pub trait TaskExecutor: Send + Sync + 'static { 22 | fn execute(&self, task: Task); 23 | } 24 | 25 | pub enum Task { 26 | RequestChain(PeerIndex, cn::cmd::RequestChain), 27 | } 28 | 29 | pub struct LocalSynchronizationTaskExecutor { 30 | peers: PeersRef, 31 | } 32 | 33 | impl LocalSynchronizationTaskExecutor { 34 | pub fn new(peers: PeersRef) -> LocalSynchronizationTaskExecutor { 35 | LocalSynchronizationTaskExecutor { peers } 36 | } 37 | 38 | fn execute_requestchain(&self, peer_index: PeerIndex, request: cn::cmd::RequestChain) { 39 | debug!("Executing RequestChain request for peer #{} - {:?}", 40 | peer_index, 41 | request); 42 | 43 | self.peers 44 | .connection(peer_index) 45 | .map(|connection| { connection.notify_request_chain(&request); }); 46 | } 47 | } 48 | 49 | impl TaskExecutor for LocalSynchronizationTaskExecutor { 50 | fn execute(&self, task: Task) { 51 | match task { 52 | Task::RequestChain(peer_index, req) => self.execute_requestchain(peer_index, req), 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /keys/src/key_image.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use std::fmt::{self, Debug, Formatter}; 10 | 11 | use format::{Deserialize, DeserializerStream, Error, Serialize, SerializerStream}; 12 | 13 | use utils::fmt_byte_slice; 14 | 15 | /// Key image length. 16 | pub const KEY_IMAGE_LENGTH: usize = 32; 17 | 18 | #[derive(Default, Clone)] 19 | pub struct KeyImage(pub [u8; KEY_IMAGE_LENGTH]); 20 | 21 | impl KeyImage { 22 | pub fn new() -> KeyImage { 23 | KeyImage::default() 24 | } 25 | 26 | pub fn from_bytes>(bytes: B) -> KeyImage { 27 | let bytes = bytes.as_ref(); 28 | assert!(bytes.len() == KEY_IMAGE_LENGTH, "invalid key image length"); 29 | 30 | let mut h = Self::new(); 31 | h.0.clone_from_slice(bytes); 32 | h 33 | } 34 | 35 | pub fn as_bytes(&self) -> &[u8] { 36 | &self.0 37 | } 38 | } 39 | 40 | impl AsRef<[u8]> for KeyImage { 41 | fn as_ref(&self) -> &[u8] { 42 | &self.0 43 | } 44 | } 45 | 46 | impl Deserialize for KeyImage { 47 | fn deserialize(deserializer: &mut DeserializerStream) -> Result { 48 | deserializer 49 | .get_blob(KEY_IMAGE_LENGTH) 50 | .map(KeyImage::from_bytes) 51 | } 52 | } 53 | 54 | impl Serialize for KeyImage { 55 | fn serialize(&self, mut serializer: SerializerStream) { 56 | serializer.put_blob(self.as_bytes()) 57 | } 58 | 59 | fn len(&self) -> usize { 60 | KEY_IMAGE_LENGTH 61 | } 62 | } 63 | 64 | impl Debug for KeyImage { 65 | fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { 66 | fmt_byte_slice(&self.0, fmt) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /dxmr/utils.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use std::sync::Arc; 18 | 19 | use app_dirs::{AppDataType, app_dir}; 20 | 21 | use chain::IndexedBlock; 22 | use db::BlockChainDatabase; 23 | use storage::SharedStore; 24 | 25 | use config::Config; 26 | 27 | pub fn open_db() -> SharedStore { 28 | use APP_INFO; 29 | 30 | let path = 31 | app_dir(AppDataType::UserData, &APP_INFO, "db").expect("couldn't get user data location"); 32 | 33 | let db = BlockChainDatabase::open(path).expect("couldn't open blockchain database"); 34 | 35 | Arc::new(db) 36 | } 37 | 38 | pub fn init_db(cfg: &Config) { 39 | let genesis_block: IndexedBlock = cfg.network.genesis_block().into(); 40 | 41 | match cfg.db.block_id(0) { 42 | Some(ref id) => { 43 | if id != genesis_block.id() { 44 | panic!("trying to open database with incompatible genesis block") 45 | } 46 | } 47 | None => { 48 | let id = genesis_block.id().clone(); 49 | cfg.db 50 | .insert(genesis_block) 51 | .expect("couldn't insert genesis block"); 52 | 53 | cfg.db 54 | .canonize(&id) 55 | .expect("couldn't canonize genesis block"); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /p2p/src/types/cn/block_complete_entry.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use portable_storage_utils::Blob; 18 | 19 | #[derive(Debug, Deserialize, Serialize)] 20 | pub struct BlockCompleteEntry { 21 | pub block: Blob, 22 | pub txs: Vec, 23 | } 24 | 25 | #[cfg(test)] 26 | pub mod tests { 27 | use super::*; 28 | use portable_storage::{StorageEntry, to_section}; 29 | 30 | #[test] 31 | fn serialize() { 32 | let b = BlockCompleteEntry { 33 | block: vec![].into(), 34 | txs: vec![vec![0x20].into()], 35 | }; 36 | 37 | let section = to_section(&b).unwrap(); 38 | 39 | match §ion["block"] { 40 | &StorageEntry::Buf(ref buf) => assert_eq!(buf.len(), 0), 41 | entry => panic!("invalid entry: {:?}", entry), 42 | } 43 | 44 | match §ion["txs"] { 45 | &StorageEntry::Array(ref array) => { 46 | assert_eq!(array.len(), 1); 47 | match &array[0] { 48 | &StorageEntry::Buf(ref buf) => assert_eq!(buf[0], 0x20), 49 | entry => panic!("invalid entry: {:?}", entry), 50 | } 51 | } 52 | entry => panic!("invalid entry: {:?}", entry), 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /crypto/sys/hash-extra-blake.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #include 32 | #include 33 | 34 | #include "blake256.h" 35 | 36 | void hash_extra_blake(const void *data, size_t length, char *hash) { 37 | blake256_hash((uint8_t*)hash, data, length); 38 | } 39 | -------------------------------------------------------------------------------- /crypto/sys/hash-extra-groestl.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #include 32 | #include 33 | 34 | #include "groestl.h" 35 | 36 | void hash_extra_groestl(const void *data, size_t length, char *hash) { 37 | groestl(data, length * 8, (uint8_t*)hash); 38 | } 39 | -------------------------------------------------------------------------------- /keys/src/signature.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use std::fmt::{self, Debug, Formatter}; 10 | 11 | use format::{Deserialize, DeserializerStream, Error, Serialize, SerializerStream}; 12 | 13 | use utils::fmt_byte_slice; 14 | 15 | /// Signature lenght. 16 | pub const SIGNATURE_LENGTH: usize = 64; 17 | 18 | pub struct Signature([u8; SIGNATURE_LENGTH]); 19 | 20 | impl Signature { 21 | pub fn new() -> Signature { 22 | Signature([0u8; 64]) 23 | } 24 | 25 | pub fn from_bytes>(bytes: B) -> Signature { 26 | let bytes = bytes.as_ref(); 27 | assert!(bytes.len() == SIGNATURE_LENGTH, "invalid signature length"); 28 | 29 | let mut h = Self::new(); 30 | h.0.clone_from_slice(bytes); 31 | h 32 | } 33 | 34 | pub fn as_bytes(&self) -> &[u8] { 35 | &self.0 36 | } 37 | } 38 | 39 | impl Deserialize for Signature { 40 | fn deserialize(deserializer: &mut DeserializerStream) -> Result { 41 | deserializer 42 | .get_blob(SIGNATURE_LENGTH) 43 | .map(Signature::from_bytes) 44 | } 45 | } 46 | 47 | impl Serialize for Signature { 48 | fn serialize(&self, mut serializer: SerializerStream) { 49 | serializer.put_blob(self.as_bytes()) 50 | } 51 | 52 | fn len(&self) -> usize { 53 | SIGNATURE_LENGTH 54 | } 55 | } 56 | 57 | impl Clone for Signature { 58 | fn clone(&self) -> Signature { 59 | let mut s = Signature::new(); 60 | s.0.copy_from_slice(&self.0); 61 | s 62 | } 63 | } 64 | 65 | impl Debug for Signature { 66 | fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { 67 | fmt_byte_slice(&self.0, fmt) 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /crypto/sys/hash-extra-skein.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #include 32 | #include 33 | 34 | #include "hash-ops.h" 35 | #include "skein.h" 36 | 37 | void hash_extra_skein(const void *data, size_t length, char *hash) { 38 | int r = skein_hash(8 * HASH_SIZE, data, 8 * length, (uint8_t*)hash); 39 | assert(SKEIN_SUCCESS == r); 40 | } 41 | -------------------------------------------------------------------------------- /crypto/sys/skein.h: -------------------------------------------------------------------------------- 1 | #ifndef _SKEIN_H_ 2 | #define _SKEIN_H_ 1 3 | /************************************************************************** 4 | ** 5 | ** Interface declarations and internal definitions for Skein hashing. 6 | ** 7 | ** Source code author: Doug Whiting, 2008. 8 | ** 9 | ** This algorithm and source code is released to the public domain. 10 | ** 11 | *************************************************************************** 12 | ** 13 | ** The following compile-time switches may be defined to control some 14 | ** tradeoffs between speed, code size, error checking, and security. 15 | ** 16 | ** The "default" note explains what happens when the switch is not defined. 17 | ** 18 | ** SKEIN_DEBUG -- make callouts from inside Skein code 19 | ** to examine/display intermediate values. 20 | ** [default: no callouts (no overhead)] 21 | ** 22 | ** SKEIN_ERR_CHECK -- how error checking is handled inside Skein 23 | ** code. If not defined, most error checking 24 | ** is disabled (for performance). Otherwise, 25 | ** the switch value is interpreted as: 26 | ** 0: use assert() to flag errors 27 | ** 1: return SKEIN_FAIL to flag errors 28 | ** 29 | ***************************************************************************/ 30 | #include "skein_port.h" /* get platform-specific definitions */ 31 | 32 | typedef enum 33 | { 34 | SKEIN_SUCCESS = 0, /* return codes from Skein calls */ 35 | SKEIN_FAIL = 1, 36 | SKEIN_BAD_HASHLEN = 2 37 | } 38 | HashReturn; 39 | 40 | typedef size_t DataLength; /* bit count type */ 41 | typedef u08b_t BitSequence; /* bit stream type */ 42 | 43 | /* "all-in-one" call */ 44 | HashReturn skein_hash(int hashbitlen, const BitSequence *data, 45 | DataLength databitlen, BitSequence *hashval); 46 | 47 | #endif /* ifndef _SKEIN_H_ */ 48 | -------------------------------------------------------------------------------- /format/src/ser.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use bytes::{BufMut, Bytes, BytesMut}; 10 | use varint; 11 | 12 | pub fn to_binary(v: &T) -> Bytes { 13 | let mut bytes = BytesMut::new(); 14 | bytes.reserve(v.len()); 15 | v.serialize(SerializerStream::new(&mut bytes)); 16 | bytes.freeze() 17 | } 18 | 19 | pub trait Serialize { 20 | fn serialize(&self, serializer: SerializerStream); 21 | fn len(&self) -> usize; 22 | } 23 | 24 | pub struct SerializerStream<'buf>(&'buf mut BytesMut); 25 | 26 | impl<'buf> SerializerStream<'buf> { 27 | pub fn new(bytes: &'buf mut BytesMut) -> SerializerStream<'buf> { 28 | SerializerStream(bytes) 29 | } 30 | 31 | pub fn put_u8(&mut self, v: u8) { 32 | self.0.put_u8(v); 33 | } 34 | 35 | pub fn put_u32(&mut self, mut v: u32) { 36 | use std::mem::size_of; 37 | 38 | let bytes = size_of::(); 39 | for _ in 0..bytes { 40 | self.0.put_u8((v & 0xff) as u8); 41 | v >>= 8; 42 | } 43 | } 44 | 45 | pub fn put_u64(&mut self, mut v: u64) { 46 | use std::mem::size_of; 47 | 48 | let bytes = size_of::(); 49 | for _ in 0..bytes { 50 | self.0.put_u8((v & 0xff) as u8); 51 | v >>= 8; 52 | } 53 | } 54 | 55 | pub fn put_u8_varint(&mut self, v: u8) { 56 | varint::write(self.0, v) 57 | } 58 | 59 | pub fn put_u64_varint(&mut self, v: u64) { 60 | varint::write(self.0, v) 61 | } 62 | 63 | pub fn put_blob(&mut self, v: &[u8]) { 64 | self.0.put(v) 65 | } 66 | 67 | pub fn put_serializable(&mut self, v: &T) { 68 | v.serialize(SerializerStream::new(self.0)) 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /chain/src/transaction/tx_out_to_script.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use keys::{PublicKey, PUBLIC_KEY_LENGTH}; 10 | use format::{Deserialize, DeserializerStream, Error, Serialize, SerializerStream}; 11 | 12 | #[derive(Debug, Clone)] 13 | pub struct TxOutToScript { 14 | pub keys: Vec, 15 | pub script: Vec, 16 | } 17 | 18 | impl Deserialize for TxOutToScript { 19 | fn deserialize(deserializer: &mut DeserializerStream) -> Result { 20 | let keys_length = deserializer.get_u64_varint()?; 21 | let mut keys = Vec::new(); 22 | keys.reserve(keys_length as usize); 23 | 24 | for _ in 0..keys_length { 25 | let key: PublicKey = deserializer.get_deserializable()?; 26 | keys.push(key); 27 | } 28 | 29 | let script_length = deserializer.get_u64_varint()? as usize; 30 | let script = deserializer.get_blob(script_length)?; 31 | 32 | 33 | Ok(TxOutToScript { keys, script }) 34 | } 35 | } 36 | 37 | 38 | impl Serialize for TxOutToScript { 39 | fn serialize(&self, mut serializer: SerializerStream) { 40 | serializer.put_u64_varint(self.keys.len() as u64); 41 | 42 | for key in self.keys.iter() { 43 | serializer.put_serializable(key); 44 | } 45 | 46 | serializer.put_u64_varint(self.script.len() as u64); 47 | serializer.put_blob(self.script.as_slice()); 48 | } 49 | 50 | fn len(&self) -> usize { 51 | use varint; 52 | 53 | let mut sum = 0usize; 54 | sum += varint::length(self.keys.len()); 55 | sum += self.keys.len() * PUBLIC_KEY_LENGTH; 56 | sum += varint::length(self.script.len()); 57 | sum += self.script.len(); 58 | sum 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /crypto/sys/hash-extra-jh.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "jh.h" 37 | #include "hash-ops.h" 38 | 39 | void hash_extra_jh(const void *data, size_t length, char *hash) { 40 | int r = jh_hash(HASH_SIZE * 8, data, 8 * length, (uint8_t*)hash); 41 | assert(SUCCESS == r); 42 | } 43 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # Based on the "trust" template v0.1.2 2 | # https://github.com/japaric/trust/tree/v0.1.2 3 | 4 | environment: 5 | global: 6 | RUST_VERSION: stable 7 | 8 | CRATE_NAME: xmr 9 | 10 | matrix: 11 | # MinGW 12 | - TARGET: i686-pc-windows-gnu 13 | - TARGET: x86_64-pc-windows-gnu 14 | 15 | # MSVC 16 | - TARGET: i686-pc-windows-msvc 17 | - TARGET: x86_64-pc-windows-msvc 18 | 19 | # Testing other channels 20 | - TARGET: x86_64-pc-windows-gnu 21 | RUST_VERSION: nightly 22 | - TARGET: x86_64-pc-windows-msvc 23 | RUST_VERSION: nightly 24 | 25 | install: 26 | - ps: >- 27 | If ($Env:TARGET -eq 'x86_64-pc-windows-gnu') { 28 | $Env:PATH += ';C:\msys64\mingw64\bin' 29 | } ElseIf ($Env:TARGET -eq 'i686-pc-windows-gnu') { 30 | $Env:PATH += ';C:\msys64\mingw32\bin' 31 | } 32 | - curl -sSf -o rustup-init.exe https://win.rustup.rs/ 33 | - rustup-init.exe -y --default-host %TARGET% --default-toolchain %RUST_VERSION% 34 | - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin 35 | - rustc -Vv 36 | - cargo -V 37 | 38 | test_script: 39 | # we don't run the "test phase" when doing deploys 40 | - if [%APPVEYOR_REPO_TAG%]==[false] ( 41 | cargo build --target %TARGET% && 42 | cargo build --target %TARGET% --release && 43 | cargo test --target %TARGET% && 44 | cargo test --target %TARGET% --release 45 | ) 46 | 47 | before_deploy: 48 | - cargo rustc --target %TARGET% --release -- -C lto 49 | - ps: ci\before_deploy.ps1 50 | 51 | deploy: 52 | artifact: /.*\.zip/ 53 | auth_token: 54 | secure: SztIDq32FeCzIKW6WCfQgpFHg5u9t6sqeiu6ZgkygSyrAAxPxVnFCuAR9mfa9nuV 55 | description: '' 56 | on: 57 | RUST_VERSION: stable 58 | appveyor_repo_tag: true 59 | provider: GitHub 60 | 61 | cache: 62 | - C:\Users\appveyor\.cargo\registry 63 | - target 64 | 65 | branches: 66 | only: 67 | # Release tags 68 | - /^v\d+\.\d+\.\d+.*$/ 69 | - master 70 | 71 | notifications: 72 | - provider: Email 73 | on_build_success: false 74 | 75 | # Building is done in the test phase, so we disable Appveyor's build phase. 76 | build: false 77 | -------------------------------------------------------------------------------- /chain/src/transaction/tx_in_to_script_hash.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use primitives::H256; 10 | use transaction::TxOutToScript; 11 | use format::{Deserialize, DeserializerStream, Error, Serialize, SerializerStream}; 12 | 13 | #[derive(Debug, Clone)] 14 | pub struct TxInToScriptHash { 15 | pub prev: H256, 16 | pub prevout: u64, 17 | pub script: TxOutToScript, 18 | pub sigset: Vec, 19 | } 20 | 21 | impl Deserialize for TxInToScriptHash { 22 | fn deserialize(deserializer: &mut DeserializerStream) -> Result { 23 | let prev = deserializer.get_deserializable()?; 24 | let prevout = deserializer.get_u64_varint()?; 25 | let script = deserializer.get_deserializable()?; 26 | 27 | let sigset_length = deserializer.get_u64_varint()? as usize; 28 | let sigset = deserializer.get_blob(sigset_length)?; 29 | 30 | Ok(TxInToScriptHash { 31 | prev, 32 | prevout, 33 | script, 34 | sigset, 35 | }) 36 | } 37 | } 38 | 39 | impl Serialize for TxInToScriptHash { 40 | fn serialize(&self, mut serializer: SerializerStream) { 41 | serializer.put_serializable(&self.prev); 42 | serializer.put_u64_varint(self.prevout); 43 | serializer.put_serializable(&self.script); 44 | 45 | serializer.put_u64_varint(self.sigset.len() as u64); 46 | serializer.put_blob(self.sigset.as_slice()); 47 | } 48 | 49 | fn len(&self) -> usize { 50 | use varint; 51 | 52 | let mut sum = 0; 53 | sum += self.prev.len(); 54 | sum += varint::length(self.prevout); 55 | sum += self.script.len(); 56 | sum += varint::length(self.sigset.len()); 57 | sum += self.sigset.len(); 58 | sum 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /crypto/sys/oaes_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * --------------------------------------------------------------------------- 3 | * OpenAES License 4 | * --------------------------------------------------------------------------- 5 | * Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * - Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * - Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | * --------------------------------------------------------------------------- 29 | */ 30 | 31 | #ifndef _OAES_CONFIG_H 32 | #define _OAES_CONFIG_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | //#ifndef OAES_HAVE_ISAAC 39 | //#define OAES_HAVE_ISAAC 1 40 | //#endif // OAES_HAVE_ISAAC 41 | 42 | //#ifndef OAES_DEBUG 43 | //#define OAES_DEBUG 0 44 | //#endif // OAES_DEBUG 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif // _OAES_CONFIG_H 51 | -------------------------------------------------------------------------------- /verification/src/pow.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use primitives::H256; 10 | use std::u64; 11 | 12 | #[derive(Debug)] 13 | pub struct Difficulty(pub u64); 14 | 15 | pub fn is_valid_proof_of_work(hash: H256, Difficulty(difficulty): Difficulty) -> bool { 16 | let comps = hash.u64_components(); 17 | 18 | let (top, high0) = mul(comps.3, difficulty); 19 | if high0 != 0 { 20 | return false; 21 | } 22 | let (_low1, high1) = mul(comps.0, difficulty); 23 | let (low2, high2) = mul(comps.1, difficulty); 24 | let (low3, high3) = mul(comps.2, difficulty); 25 | 26 | !cadc(high3, top, cadc(high2, low3, cadd(high1, low2))) 27 | } 28 | 29 | fn cadd(a: u64, b: u64) -> bool { 30 | a + b < a 31 | } 32 | 33 | fn cadc(a: u64, b: u64, c: bool) -> bool { 34 | a + b < a || (c && a + b == u64::MAX) 35 | } 36 | 37 | fn mul(a: u64, b: u64) -> (u64, u64) { 38 | let alow = a & 0xffffffff; 39 | let ahigh = a >> 32; 40 | let blow = b & 0xffffffff; 41 | let bhigh = b >> 32; 42 | 43 | let res = alow * blow; 44 | let lowres1 = res & 0xffffffff; 45 | let carry = res >> 32; 46 | 47 | let res = ahigh * blow + carry; 48 | let highreshigh1 = res >> 32; 49 | let highreslow1 = res & 0xffffffff; 50 | 51 | let res = alow * bhigh; 52 | let lowres2 = res & 0xffffffff; 53 | let carry = res >> 32; 54 | 55 | let res = ahigh * bhigh + carry; 56 | let highreshigh2 = res >> 32; 57 | let highreslow2 = res & 0xffffffff; 58 | 59 | let r = highreslow1 + lowres2; 60 | let carry = r >> 32; 61 | let low = (r << 32) | lowres1; 62 | let r = highreshigh1 + highreslow2 + carry; 63 | let d3 = r & 0xffffffff; 64 | let carry = r >> 32; 65 | let r = highreshigh2 + carry; 66 | let high = d3 | (r << 32); 67 | 68 | (low, high) 69 | } 70 | -------------------------------------------------------------------------------- /chain/src/transaction/tx_in_to_key.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use keys::KeyImage; 10 | use format::{Deserialize, DeserializerStream, Error, Serialize, SerializerStream}; 11 | 12 | #[derive(Debug, Clone)] 13 | pub struct TxInToKey { 14 | pub amount: u64, 15 | pub key_offsets: Vec, 16 | pub k_image: KeyImage, 17 | } 18 | 19 | impl Deserialize for TxInToKey { 20 | fn deserialize(deserializer: &mut DeserializerStream) -> Result { 21 | let amount = deserializer.get_u64_varint()?; 22 | 23 | let key_offsets_length = deserializer.get_u64_varint()? as usize; 24 | let mut key_offsets = Vec::with_capacity(key_offsets_length); 25 | for _ in 0..key_offsets_length { 26 | key_offsets.push(deserializer.get_u64_varint()?); 27 | } 28 | 29 | let k_image = deserializer.get_deserializable()?; 30 | 31 | Ok(TxInToKey { 32 | amount, 33 | key_offsets, 34 | k_image, 35 | }) 36 | } 37 | } 38 | 39 | impl Serialize for TxInToKey { 40 | fn serialize(&self, mut serializer: SerializerStream) { 41 | serializer.put_u64_varint(self.amount); 42 | 43 | serializer.put_u64_varint(self.key_offsets.len() as u64); 44 | for offset in self.key_offsets.iter() { 45 | serializer.put_u64_varint(*offset); 46 | } 47 | 48 | serializer.put_serializable(&self.k_image) 49 | } 50 | 51 | fn len(&self) -> usize { 52 | use varint; 53 | 54 | let mut sum = 0; 55 | sum += varint::length(self.amount); 56 | sum += varint::length(self.key_offsets.len()); 57 | for offset in self.key_offsets.iter() { 58 | sum += varint::length(*offset); 59 | } 60 | sum += self.k_image.len(); 61 | sum 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /portable-storage/src/header.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use bytes::{Buf, BufMut, BytesMut, LittleEndian}; 10 | use {Result, Error}; 11 | 12 | pub const PORTABLE_STORAGE_SIGNATUREA: u32 = 0x01011101; 13 | pub const PORTABLE_STORAGE_SIGNATUREB: u32 = 0x01020101; 14 | pub const PORTABLE_STORAGE_FORMAT_VER: u8 = 1; 15 | pub const PORTABLE_STORAGE_BLOCK_HEADER_LENGTH: usize = 4 + 4 + 1; 16 | 17 | #[derive(Debug)] 18 | pub struct StorageBlockHeader { 19 | pub signature_a: u32, 20 | pub signature_b: u32, 21 | pub version: u8, 22 | } 23 | 24 | impl StorageBlockHeader { 25 | pub fn is_valid_signature_a(&self) -> bool { 26 | self.signature_a == PORTABLE_STORAGE_SIGNATUREA 27 | } 28 | 29 | pub fn is_valid_signature_b(&self) -> bool { 30 | self.signature_a == PORTABLE_STORAGE_SIGNATUREB 31 | } 32 | 33 | pub fn is_valid_version(&self) -> bool { 34 | self.version == PORTABLE_STORAGE_FORMAT_VER 35 | } 36 | 37 | pub fn read(buf: &mut B) -> Result { 38 | ensure_eof!(buf, PORTABLE_STORAGE_BLOCK_HEADER_LENGTH); 39 | 40 | let hdr = StorageBlockHeader { 41 | signature_a: buf.get_u32::(), 42 | signature_b: buf.get_u32::(), 43 | version: buf.get_u8(), 44 | }; 45 | 46 | if (hdr.is_valid_signature_a() || hdr.is_valid_signature_b()) && hdr.is_valid_version() { 47 | Ok(hdr) 48 | } else { 49 | Err(Error::InvalidHeader) 50 | } 51 | } 52 | 53 | pub fn write(buf: &mut BytesMut) { 54 | buf.reserve(PORTABLE_STORAGE_BLOCK_HEADER_LENGTH); 55 | buf.put_u32::(PORTABLE_STORAGE_SIGNATUREA); 56 | buf.put_u32::(PORTABLE_STORAGE_SIGNATUREB); 57 | buf.put_u8(PORTABLE_STORAGE_FORMAT_VER); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /keys/src/public_key.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use std::fmt::{self, Debug, Formatter}; 10 | 11 | use format::{Deserialize, DeserializerStream, Error, Serialize, SerializerStream}; 12 | 13 | use utils::fmt_byte_slice; 14 | 15 | /// Public Key length in bytes. 16 | pub const PUBLIC_KEY_LENGTH: usize = 32; 17 | 18 | #[derive(Default, Clone)] 19 | pub struct PublicKey(pub [u8; PUBLIC_KEY_LENGTH]); 20 | 21 | impl PublicKey { 22 | pub fn new() -> PublicKey { 23 | PublicKey::default() 24 | } 25 | 26 | pub fn from_bytes>(bytes: B) -> PublicKey { 27 | let bytes = bytes.as_ref(); 28 | assert!(bytes.len() == PUBLIC_KEY_LENGTH, 29 | "invalid public key length"); 30 | 31 | let mut h = Self::new(); 32 | h.0.clone_from_slice(bytes); 33 | h 34 | } 35 | 36 | pub fn as_bytes(&self) -> &[u8] { 37 | &self.0 38 | } 39 | } 40 | 41 | impl From<[u8; PUBLIC_KEY_LENGTH]> for PublicKey { 42 | fn from(key: [u8; PUBLIC_KEY_LENGTH]) -> PublicKey { 43 | PublicKey(key) 44 | } 45 | } 46 | 47 | 48 | impl AsRef<[u8]> for PublicKey { 49 | fn as_ref(&self) -> &[u8] { 50 | &self.0 51 | } 52 | } 53 | 54 | impl Deserialize for PublicKey { 55 | fn deserialize(deserializer: &mut DeserializerStream) -> Result { 56 | deserializer 57 | .get_blob(PUBLIC_KEY_LENGTH) 58 | .map(PublicKey::from_bytes) 59 | } 60 | } 61 | 62 | impl Serialize for PublicKey { 63 | fn serialize(&self, mut serializer: SerializerStream) { 64 | serializer.put_blob(self.as_bytes()) 65 | } 66 | 67 | fn len(&self) -> usize { 68 | PUBLIC_KEY_LENGTH 69 | } 70 | } 71 | 72 | impl Debug for PublicKey { 73 | fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { 74 | fmt_byte_slice(&self.0, fmt) 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /sync/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | #[macro_use] 18 | extern crate log; 19 | extern crate parking_lot; 20 | 21 | extern crate xmr_db as db; 22 | extern crate xmr_network as network; 23 | extern crate xmr_p2p as p2p; 24 | extern crate xmr_primitives as primitives; 25 | extern crate xmr_storage as storage; 26 | 27 | mod connection_factory; 28 | mod inbound_connection; 29 | mod local_node; 30 | mod synchronization_chain; 31 | mod synchronization_client; 32 | mod synchronization_client_core; 33 | mod synchronization_executor; 34 | mod synchronization_peers; 35 | mod types; 36 | 37 | pub use connection_factory::ConnectionFactory; 38 | pub use inbound_connection::InboundConnection; 39 | pub use local_node::LocalNode; 40 | pub use synchronization_chain::Chain; 41 | pub use synchronization_client::{Client, SynchronizationClient}; 42 | pub use synchronization_client_core::{ClientCore, SynchronizationClientCore}; 43 | pub use synchronization_executor::{TaskExecutor, LocalSynchronizationTaskExecutor}; 44 | pub use synchronization_peers::{Peers, Peer, PeersImpl}; 45 | pub use types::{LocalNodeRef, ClientRef, ClientCoreRef, ExecutorRef, PeersRef, StorageRef, PeerIndex}; 46 | 47 | pub fn create_local_node(storage: StorageRef, network: network::Network) -> LocalNodeRef { 48 | use std::sync::Arc; 49 | 50 | Arc::new(LocalNode::new(storage, network)) 51 | } 52 | 53 | pub fn create_local_sync_node(local_node: LocalNodeRef) -> p2p::protocol::LocalSyncNodeRef { 54 | ConnectionFactory::new(local_node).boxed() 55 | } 56 | -------------------------------------------------------------------------------- /p2p/src/types/peerlist_entry.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use bytes::{BytesMut, Buf, BufMut, LittleEndian, IntoBuf}; 18 | use portable_storage_utils::stl::{StlElement, Error}; 19 | use types::{Ipv4Address, PeerId}; 20 | use std::cmp::{Eq, PartialEq}; 21 | 22 | #[derive(Debug, Default, Clone)] 23 | pub struct PeerlistEntry { 24 | pub adr: Ipv4Address, 25 | pub id: PeerId, 26 | pub last_seen: i64, 27 | } 28 | 29 | impl PartialEq for PeerlistEntry { 30 | fn eq(&self, other: &PeerlistEntry) -> bool { 31 | self.id == other.id && self.adr == other.adr 32 | } 33 | } 34 | 35 | impl Eq for PeerlistEntry {} 36 | 37 | impl StlElement for PeerlistEntry { 38 | const LENGTH: usize = Ipv4Address::LENGTH + 8 + 8; 39 | 40 | fn from_bytes(v: &[u8]) -> Result { 41 | if v.len() != Self::LENGTH { 42 | return Err(Error::InvalidLength(v.len())); 43 | } 44 | 45 | let adr = Ipv4Address::from_bytes(&v[..Ipv4Address::LENGTH])?; 46 | 47 | let mut buf = (&v[Ipv4Address::LENGTH..]).into_buf(); 48 | 49 | let id = buf.get_u64::().into(); 50 | let last_seen = buf.get_i64::(); 51 | 52 | Ok(PeerlistEntry { adr, id, last_seen }) 53 | } 54 | 55 | fn to_bytes(&self, buf: &mut BytesMut) { 56 | buf.reserve(Self::LENGTH); 57 | 58 | self.adr.to_bytes(buf); 59 | buf.put_u64::(self.id.into()); 60 | buf.put_i64::(self.last_seen); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /sync/src/connection_factory.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use std::sync::Arc; 18 | use std::sync::atomic::{AtomicUsize, Ordering}; 19 | 20 | use p2p::protocol::{LocalSyncNode, LocalSyncNodeRef, OutboundSyncConnectionRef, 21 | InboundSyncConnectionRef}; 22 | use p2p::types::cn::CoreSyncData; 23 | 24 | use inbound_connection::InboundConnection; 25 | use types::{LocalNodeRef, PeersRef}; 26 | 27 | pub struct ConnectionFactory { 28 | peers: PeersRef, 29 | local_node: LocalNodeRef, 30 | counter: AtomicUsize, 31 | } 32 | 33 | impl ConnectionFactory { 34 | pub fn new(local_node: LocalNodeRef) -> ConnectionFactory { 35 | ConnectionFactory { 36 | peers: local_node.peers(), 37 | local_node, 38 | counter: AtomicUsize::new(0), 39 | } 40 | } 41 | 42 | pub fn boxed(self) -> LocalSyncNodeRef { 43 | Box::new(self) 44 | } 45 | } 46 | 47 | impl LocalSyncNode for ConnectionFactory { 48 | fn new_sync_connection(&self, 49 | sync_data: &CoreSyncData, 50 | connection: OutboundSyncConnectionRef) 51 | -> InboundSyncConnectionRef { 52 | let peer_index = self.counter.fetch_add(1, Ordering::SeqCst) + 1; 53 | info!("Connecting with peer #{}", peer_index); 54 | 55 | self.peers.insert(peer_index, sync_data, connection); 56 | self.local_node.on_connect(peer_index); 57 | 58 | Arc::new(InboundConnection::new(peer_index, self.peers.clone(), self.local_node.clone())) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /p2p/src/types/ipv4_address.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use std::net; 18 | use bytes::{BytesMut, Buf, BufMut, IntoBuf, LittleEndian}; 19 | 20 | use portable_storage_utils::stl::{StlElement, Error}; 21 | 22 | /// An IPv4 address 23 | #[derive(Debug, Default, Clone, Eq, PartialEq, Hash)] 24 | pub struct Ipv4Address { 25 | pub ip: u32, 26 | pub port: u16, 27 | } 28 | 29 | impl From for Ipv4Address { 30 | fn from(addr: net::SocketAddrV4) -> Ipv4Address { 31 | Ipv4Address { 32 | ip: addr.ip().clone().into(), 33 | port: addr.port(), 34 | } 35 | } 36 | } 37 | 38 | impl<'a> From<&'a net::SocketAddrV4> for Ipv4Address { 39 | fn from(addr: &'a net::SocketAddrV4) -> Ipv4Address { 40 | Ipv4Address { 41 | ip: addr.ip().clone().into(), 42 | port: addr.port(), 43 | } 44 | } 45 | } 46 | 47 | impl StlElement for Ipv4Address { 48 | const LENGTH: usize = 4 + 2; 49 | 50 | fn from_bytes(v: &[u8]) -> Result { 51 | if v.len() != Self::LENGTH { 52 | return Err(Error::InvalidLength(v.len())); 53 | } 54 | 55 | let mut buf = v.into_buf(); 56 | 57 | Ok(Ipv4Address { 58 | ip: buf.get_u32::(), 59 | port: buf.get_u16::(), 60 | }) 61 | } 62 | 63 | fn to_bytes(&self, buf: &mut BytesMut) { 64 | buf.reserve(Self::LENGTH); 65 | buf.put_u32::(self.ip); 66 | buf.put_u16::(self.port); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /crypto/sys/hash.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include "hash-ops.h" 36 | #include "keccak.h" 37 | 38 | void hash_permutation(union hash_state *state) { 39 | keccakf((uint64_t*)state, 24); 40 | } 41 | 42 | void hash_process(union hash_state *state, const uint8_t *buf, size_t count) { 43 | keccak1600(buf, count, (uint8_t*)state); 44 | } 45 | 46 | void cn_fast_hash(const void *data, size_t length, char *hash) { 47 | union hash_state state; 48 | hash_process(&state, data, length); 49 | memcpy(hash, &state, HASH_SIZE); 50 | } 51 | -------------------------------------------------------------------------------- /portable-storage/src/raw_size.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use bytes::{Buf, BufMut, BytesMut, LittleEndian}; 10 | use Result; 11 | 12 | pub const PORTABLE_RAW_SIZE_MARK_MASK: u8 = 0x03; 13 | pub const PORTABLE_RAW_SIZE_MARK_BYTE: u8 = 0; 14 | pub const PORTABLE_RAW_SIZE_MARK_WORD: u8 = 1; 15 | pub const PORTABLE_RAW_SIZE_MARK_DWORD: u8 = 2; 16 | pub const PORTABLE_RAW_SIZE_MARK_INT64: u8 = 3; 17 | 18 | pub fn read(buf: &mut B) -> Result { 19 | ensure_eof!(buf, 1); 20 | let mark = buf.bytes()[0] & PORTABLE_RAW_SIZE_MARK_MASK; 21 | 22 | match mark { 23 | PORTABLE_RAW_SIZE_MARK_BYTE => Ok((buf.get_u8() >> 2) as usize), 24 | PORTABLE_RAW_SIZE_MARK_WORD => { 25 | ensure_eof!(buf, 2); 26 | Ok((buf.get_u16::() >> 2) as usize) 27 | } 28 | PORTABLE_RAW_SIZE_MARK_DWORD => { 29 | ensure_eof!(buf, 4); 30 | Ok((buf.get_u32::() >> 2) as usize) 31 | } 32 | PORTABLE_RAW_SIZE_MARK_INT64 => { 33 | ensure_eof!(buf, 8); 34 | Ok((buf.get_u64::() >> 2) as usize) 35 | } 36 | _ => unreachable!(), 37 | } 38 | } 39 | 40 | pub fn write(buf: &mut BytesMut, val: usize) { 41 | if val <= 63 { 42 | buf.reserve(1); 43 | buf.put_u8(((val as u8) << 2) | PORTABLE_RAW_SIZE_MARK_BYTE); 44 | } else if val <= 16383 { 45 | buf.reserve(2); 46 | buf.put_u16::(((val as u16) << 2) | PORTABLE_RAW_SIZE_MARK_WORD as u16); 47 | } else if val <= 1073741823 { 48 | buf.reserve(4); 49 | buf.put_u32::(((val as u32) << 2) | PORTABLE_RAW_SIZE_MARK_DWORD as u32); 50 | } else if val as u64 <= 4611686018427387903 { 51 | buf.reserve(8); 52 | buf.put_u64::(((val as u64) << 2) | PORTABLE_RAW_SIZE_MARK_INT64 as u64); 53 | } else { 54 | /// XXX: Hope some day monero never uses a value too large. 55 | panic!("too large"); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /dxmr/config.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use std::net::SocketAddr; 18 | 19 | use clap::ArgMatches; 20 | use failure::Error; 21 | use network::Network; 22 | use peers::default_peers; 23 | use storage::SharedStore; 24 | use utils; 25 | 26 | pub struct Config { 27 | pub network: Network, 28 | pub peers: Vec, 29 | pub threads: usize, 30 | pub listen_port: Option, 31 | pub hide_my_port: bool, 32 | pub out_peers: u32, 33 | pub in_peers: u32, 34 | pub db: SharedStore, 35 | } 36 | 37 | pub fn parse(matches: &ArgMatches) -> Result { 38 | let network = match matches.is_present("testnet") { 39 | true => Network::Testnet, 40 | false => Network::Mainnet, 41 | }; 42 | 43 | let peers = match value_t!(matches.value_of("connect"), SocketAddr) { 44 | Ok(addr) => { 45 | let mut peers = Vec::with_capacity(1); 46 | peers.push(addr); 47 | peers 48 | } 49 | Err(_e) => default_peers(network), 50 | }; 51 | 52 | let threads = value_t!(matches.value_of("threads"), usize).unwrap_or(1); 53 | 54 | let listen_port = value_t!(matches.value_of("listenport"), u16).ok(); 55 | 56 | let hide_my_port = matches.is_present("hidemyport"); 57 | 58 | let out_peers = value_t!(matches.value_of("outpeers"), u32).unwrap_or(10); 59 | let in_peers = value_t!(matches.value_of("inpeers"), u32).unwrap_or(10); 60 | 61 | let db = utils::open_db(); 62 | 63 | Ok(Config { 64 | network, 65 | peers, 66 | threads, 67 | listen_port, 68 | hide_my_port, 69 | out_peers, 70 | in_peers, 71 | db, 72 | }) 73 | } 74 | -------------------------------------------------------------------------------- /chain/src/block_header.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use primitives::H256; 10 | use format::{Deserialize, DeserializerStream, Error, Serialize, SerializerStream}; 11 | 12 | /// The metadata at the beginning of each block. 13 | #[derive(Debug, Default, Clone)] 14 | pub struct BlockHeader { 15 | /// Major block header version. 16 | pub major_version: u8, 17 | /// Minor block header version, now used as a voting mechanism. 18 | pub minor_version: u8, 19 | /// Block creation time (UNIX timestamps). 20 | pub timestamp: u64, 21 | /// Identifier of the previous block. 22 | pub prev_id: H256, 23 | /// Any value which is used in the network consensus algorithm. 24 | pub nonce: u32, 25 | } 26 | 27 | impl Deserialize for BlockHeader { 28 | fn deserialize(deserializer: &mut DeserializerStream) -> Result { 29 | let major_version = deserializer.get_u8_varint()?; 30 | let minor_version = deserializer.get_u8_varint()?; 31 | let timestamp = deserializer.get_u64_varint()?; 32 | let prev_id = deserializer.get_deserializable()?; 33 | let nonce = deserializer.get_u32()?; 34 | 35 | Ok(BlockHeader { 36 | major_version, 37 | minor_version, 38 | timestamp, 39 | prev_id, 40 | nonce, 41 | }) 42 | } 43 | } 44 | 45 | impl Serialize for BlockHeader { 46 | fn serialize(&self, mut serializer: SerializerStream) { 47 | serializer.put_u8_varint(self.major_version); 48 | serializer.put_u8_varint(self.minor_version); 49 | serializer.put_u64_varint(self.timestamp); 50 | serializer.put_serializable(&self.prev_id); 51 | serializer.put_u32(self.nonce) 52 | } 53 | 54 | fn len(&self) -> usize { 55 | use varint; 56 | 57 | let mut sum = 0; 58 | 59 | sum += varint::length(self.major_version); 60 | sum += varint::length(self.minor_version); 61 | sum += varint::length(self.timestamp); 62 | sum += self.prev_id.len(); 63 | sum += 4; 64 | sum 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /levin/src/net/io.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use std::collections::HashMap; 10 | use std::sync::Arc; 11 | 12 | use command::{Id, Command}; 13 | use net::handlers::{NotificationHandler, InvokationHandler, RemoteHandler}; 14 | 15 | /// A reference to an `IoHandler`. 16 | pub type IoHandlerRef = Arc; 17 | 18 | /// Handles external IO. 19 | #[allow(missing_debug_implementations)] 20 | #[derive(Clone)] 21 | pub struct IoHandler { 22 | handlers: HashMap, 23 | } 24 | 25 | impl IoHandler { 26 | /// Creates an empty `IoHandler`. 27 | pub fn new() -> IoHandler { 28 | IoHandler { handlers: HashMap::new() } 29 | } 30 | 31 | /// Creates an `IoHandler` with the given capacity. 32 | pub fn with_capacity(cap: usize) -> IoHandler { 33 | IoHandler { handlers: HashMap::with_capacity(cap) } 34 | } 35 | 36 | /// Add a notification to this handler. 37 | pub fn add_notification(&mut self, handler: F) 38 | where C: Command, 39 | F: NotificationHandler + 'static 40 | { 41 | let result = self.handlers 42 | .insert(C::ID, RemoteHandler::Notification(Arc::new(handler))); 43 | if result.is_some() { 44 | warn!("Command #{} was previosly added.", C::ID); 45 | } 46 | trace!("Adding notification #{}", C::ID); 47 | } 48 | 49 | /// Add a notification to this handler. 50 | pub fn add_invokation(&mut self, handler: F) 51 | where C: Command, 52 | F: InvokationHandler + 'static 53 | { 54 | let result = self.handlers 55 | .insert(C::ID, RemoteHandler::Invokation(Arc::new(handler))); 56 | if result.is_some() { 57 | warn!("Command #{} was previosly added.", C::ID); 58 | } 59 | trace!("Adding invokation #{}", C::ID); 60 | } 61 | 62 | /// Get a handler. 63 | pub(crate) fn get(&self, id: Id) -> Option { 64 | self.handlers.get(&id).cloned() 65 | } 66 | 67 | /// Converts this `IoHandler` to an `IoHandlerRef` 68 | pub fn to_ref(self) -> IoHandlerRef { 69 | Arc::new(self) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /portable-storage-utils/src/stl/vector.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use std::marker::PhantomData; 10 | use std::fmt; 11 | 12 | use serde::de::{Deserialize, Deserializer, Error, Visitor}; 13 | use serde::ser::{Serialize, Serializer}; 14 | 15 | use bytes::BytesMut; 16 | 17 | use stl::StlElement; 18 | 19 | #[derive(Debug, Default, Clone)] 20 | pub struct StlVector(pub Vec); 21 | 22 | impl<'de, T> Deserialize<'de> for StlVector 23 | where T: StlElement 24 | { 25 | fn deserialize(deserializer: D) -> Result 26 | where D: Deserializer<'de> 27 | { 28 | struct VectorVisitor(PhantomData); 29 | 30 | impl<'de, T> Visitor<'de> for VectorVisitor 31 | where T: StlElement 32 | { 33 | type Value = StlVector; 34 | 35 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 36 | write!(formatter, "a stl linked list") 37 | } 38 | 39 | fn visit_bytes(self, v: &[u8]) -> Result 40 | where E: Error 41 | { 42 | let elements = v.len() / T::LENGTH; 43 | let mut vector = Vec::new(); 44 | for i in 0..elements { 45 | let element_slice = &v[i * T::LENGTH..]; 46 | let element_slice = &element_slice[..T::LENGTH]; 47 | 48 | let element = T::from_bytes(element_slice).map_err(E::custom)?; 49 | vector.push(element); 50 | } 51 | 52 | Ok(StlVector(vector)) 53 | } 54 | } 55 | 56 | deserializer.deserialize_bytes(VectorVisitor::(PhantomData)) 57 | } 58 | } 59 | 60 | impl Serialize for StlVector 61 | where T: StlElement 62 | { 63 | fn serialize(&self, serializer: S) -> Result 64 | where S: Serializer 65 | { 66 | let mut buf = BytesMut::with_capacity(T::LENGTH * self.0.len()); 67 | for element in self.0.iter() { 68 | element.to_bytes(&mut buf); 69 | } 70 | 71 | serializer.serialize_bytes(buf.as_ref()) 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /p2p/src/types/peerid.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use std::fmt::{self, Formatter, Debug, Display}; 18 | 19 | use rand::Rng; 20 | 21 | use serde::de::{Deserialize, Deserializer, Error, Visitor}; 22 | use serde::ser::{Serialize, Serializer}; 23 | 24 | #[derive(Default, Clone, Copy, Eq, PartialEq, Hash)] 25 | pub struct PeerId(u64); 26 | 27 | impl PeerId { 28 | pub fn random(rng: &mut R) -> PeerId { 29 | PeerId(rng.next_u64()) 30 | } 31 | } 32 | 33 | impl Into for PeerId { 34 | fn into(self) -> u64 { 35 | self.0 36 | } 37 | } 38 | 39 | impl From for PeerId { 40 | fn from(v: u64) -> PeerId { 41 | PeerId(v) 42 | } 43 | } 44 | 45 | impl<'de> Deserialize<'de> for PeerId { 46 | fn deserialize(deserializer: D) -> Result 47 | where D: Deserializer<'de> 48 | { 49 | struct PeerIdVisitor; 50 | 51 | impl<'de> Visitor<'de> for PeerIdVisitor { 52 | type Value = PeerId; 53 | 54 | fn expecting(&self, formatter: &mut Formatter) -> fmt::Result { 55 | write!(formatter, "a peer id") 56 | } 57 | 58 | fn visit_u64(self, v: u64) -> Result 59 | where E: Error 60 | { 61 | Ok(PeerId(v)) 62 | } 63 | } 64 | 65 | deserializer.deserialize_u64(PeerIdVisitor) 66 | } 67 | } 68 | 69 | impl Serialize for PeerId { 70 | fn serialize(&self, serializer: S) -> Result 71 | where S: Serializer 72 | { 73 | serializer.serialize_u64(self.0) 74 | } 75 | } 76 | 77 | impl Debug for PeerId { 78 | fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { 79 | write!(fmt, "PeerId(0x{:08x})", self.0) 80 | } 81 | } 82 | 83 | impl Display for PeerId { 84 | fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { 85 | write!(fmt, "{:08x}", self.0) 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /portable-storage-utils/src/stl/linked_list.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use std::collections::LinkedList; 10 | use std::marker::PhantomData; 11 | use std::fmt; 12 | 13 | use serde::de::{Deserialize, Deserializer, Error, Visitor}; 14 | use serde::ser::{Serialize, Serializer}; 15 | 16 | use bytes::BytesMut; 17 | 18 | use stl::StlElement; 19 | 20 | #[derive(Debug, Default, Clone)] 21 | pub struct StlLinkedList(pub LinkedList); 22 | 23 | impl StlLinkedList 24 | where T: StlElement 25 | { 26 | pub fn len(&self) -> usize { 27 | self.0.len() 28 | } 29 | } 30 | 31 | impl From> for StlLinkedList 32 | where T: StlElement 33 | { 34 | fn from(ll: LinkedList) -> StlLinkedList { 35 | StlLinkedList(ll) 36 | } 37 | } 38 | 39 | impl<'de, T> Deserialize<'de> for StlLinkedList 40 | where T: StlElement 41 | { 42 | fn deserialize(deserializer: D) -> Result 43 | where D: Deserializer<'de> 44 | { 45 | struct LinkedListVisitor(PhantomData); 46 | 47 | impl<'de, T> Visitor<'de> for LinkedListVisitor 48 | where T: StlElement 49 | { 50 | type Value = StlLinkedList; 51 | 52 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 53 | write!(formatter, "a stl linked list") 54 | } 55 | 56 | fn visit_bytes(self, v: &[u8]) -> Result 57 | where E: Error 58 | { 59 | let elements = v.len() / T::LENGTH; 60 | let mut list = LinkedList::new(); 61 | for i in 0..elements { 62 | let element_slice = &v[i * T::LENGTH..]; 63 | let element_slice = &element_slice[..T::LENGTH]; 64 | 65 | let element = T::from_bytes(element_slice).map_err(E::custom)?; 66 | list.push_front(element); 67 | } 68 | 69 | Ok(StlLinkedList(list)) 70 | } 71 | } 72 | 73 | deserializer.deserialize_bytes(LinkedListVisitor::(PhantomData)) 74 | } 75 | } 76 | 77 | impl Serialize for StlLinkedList 78 | where T: StlElement 79 | { 80 | fn serialize(&self, serializer: S) -> Result 81 | where S: Serializer 82 | { 83 | let mut buf = BytesMut::with_capacity(T::LENGTH * self.0.len()); 84 | for element in self.0.iter() { 85 | element.to_bytes(&mut buf); 86 | } 87 | 88 | serializer.serialize_bytes(buf.as_ref()) 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /crypto/sys/hash-ops.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #ifndef _HASH_OPS_ 32 | #define _HASH_OPS_ 33 | 34 | #if !defined(__cplusplus) 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | static inline void *padd(void *p, size_t i) { 42 | return (char *) p + i; 43 | } 44 | 45 | static inline const void *cpadd(const void *p, size_t i) { 46 | return (const char *) p + i; 47 | } 48 | 49 | #pragma pack(push, 1) 50 | union hash_state { 51 | uint8_t b[200]; 52 | uint64_t w[25]; 53 | }; 54 | #pragma pack(pop) 55 | 56 | void hash_permutation(union hash_state *state); 57 | void hash_process(union hash_state *state, const uint8_t *buf, size_t count); 58 | 59 | #endif 60 | 61 | enum { 62 | HASH_SIZE = 32, 63 | HASH_DATA_AREA = 136 64 | }; 65 | 66 | void cn_fast_hash(const void *data, size_t length, char *hash); 67 | void cn_slow_hash(const void *data, size_t length, char *hash); 68 | 69 | void hash_extra_blake(const void *data, size_t length, char *hash); 70 | void hash_extra_groestl(const void *data, size_t length, char *hash); 71 | void hash_extra_jh(const void *data, size_t length, char *hash); 72 | void hash_extra_skein(const void *data, size_t length, char *hash); 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /chain/src/transaction/tx_out_target.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use transaction::{TxOutToKey, TxOutToScript, TxOutToScriptHash}; 10 | use format::{Deserialize, DeserializerStream, Error, Serialize, SerializerStream}; 11 | 12 | const TO_KEY: u8 = 0x2; 13 | const TO_SCRIPT: u8 = 0x0; 14 | const TO_SCRIPT_HASH: u8 = 0x1; 15 | 16 | /// Transaction output target. 17 | #[derive(Debug, Clone)] 18 | pub enum TxOutTarget { 19 | ToKey(TxOutToKey), 20 | ToScript(TxOutToScript), 21 | ToScriptHash(TxOutToScriptHash), 22 | } 23 | 24 | impl From for TxOutTarget { 25 | fn from(target: TxOutToKey) -> TxOutTarget { 26 | TxOutTarget::ToKey(target) 27 | } 28 | } 29 | 30 | impl From for TxOutTarget { 31 | fn from(target: TxOutToScript) -> TxOutTarget { 32 | TxOutTarget::ToScript(target) 33 | } 34 | } 35 | 36 | impl From for TxOutTarget { 37 | fn from(target: TxOutToScriptHash) -> TxOutTarget { 38 | TxOutTarget::ToScriptHash(target) 39 | } 40 | } 41 | 42 | impl Deserialize for TxOutTarget { 43 | fn deserialize(deserializer: &mut DeserializerStream) -> Result { 44 | let tag = deserializer.get_u8()?; 45 | let target = match tag { 46 | TO_KEY => TxOutTarget::ToKey(deserializer.get_deserializable()?), 47 | TO_SCRIPT => TxOutTarget::ToScript(deserializer.get_deserializable()?), 48 | TO_SCRIPT_HASH => TxOutTarget::ToScriptHash(deserializer.get_deserializable()?), 49 | n => return Err(Error::custom(format!("unknown variant tag: {:X}", n))), 50 | }; 51 | 52 | Ok(target) 53 | } 54 | } 55 | 56 | impl Serialize for TxOutTarget { 57 | fn serialize(&self, mut serializer: SerializerStream) { 58 | match *self { 59 | TxOutTarget::ToKey(ref v) => { 60 | serializer.put_u8(TO_KEY); 61 | serializer.put_serializable(v); 62 | } 63 | TxOutTarget::ToScript(ref v) => { 64 | serializer.put_u8(TO_SCRIPT); 65 | serializer.put_serializable(v); 66 | } 67 | TxOutTarget::ToScriptHash(ref v) => { 68 | serializer.put_u8(TO_SCRIPT_HASH); 69 | serializer.put_serializable(v); 70 | } 71 | } 72 | } 73 | 74 | fn len(&self) -> usize { 75 | let mut sum = 1; 76 | sum += match *self { 77 | TxOutTarget::ToKey(ref v) => v.len(), 78 | TxOutTarget::ToScript(ref v) => v.len(), 79 | TxOutTarget::ToScriptHash(ref v) => v.len(), 80 | }; 81 | sum 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /sync/src/inbound_connection.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use p2p::protocol::InboundSyncConnection; 18 | 19 | use p2p::types::cn::cmd::{NewBlock, NewFluffyBlock, NewTransactions, RequestChain, 20 | RequestFluffyMissingTx, RequestGetObjects, ResponseChainEntry, 21 | ResponseGetObjects}; 22 | 23 | use types::{PeersRef, PeerIndex, LocalNodeRef}; 24 | 25 | pub struct InboundConnection { 26 | peer_index: PeerIndex, 27 | peers: PeersRef, 28 | local_node: LocalNodeRef, 29 | } 30 | 31 | impl InboundConnection { 32 | pub fn new(peer_index: PeerIndex, peers: PeersRef, local_node: LocalNodeRef) -> InboundConnection { 33 | InboundConnection { 34 | peer_index, 35 | peers, 36 | local_node, 37 | } 38 | } 39 | } 40 | 41 | impl InboundSyncConnection for InboundConnection { 42 | fn on_new_block(&self, arg: &NewBlock) { 43 | self.local_node 44 | .on_new_block(self.peer_index, arg); 45 | } 46 | 47 | fn on_new_fluffy_block(&self, arg: &NewFluffyBlock) { 48 | self.local_node 49 | .on_new_fluffy_block(self.peer_index, arg); 50 | } 51 | 52 | fn on_new_transactions(&self, arg: &NewTransactions) { 53 | self.local_node 54 | .on_new_transactions(self.peer_index, arg); 55 | } 56 | 57 | fn on_request_chain(&self, arg: &RequestChain) { 58 | self.local_node 59 | .on_request_chain(self.peer_index, arg); 60 | } 61 | 62 | fn on_request_fluffy_missing_tx(&self, arg: &RequestFluffyMissingTx) { 63 | self.local_node 64 | .on_request_fluffy_missing_tx(self.peer_index, arg); 65 | } 66 | 67 | fn on_request_get_objects(&self, arg: &RequestGetObjects) { 68 | self.local_node 69 | .on_request_get_objects(self.peer_index, arg); 70 | } 71 | 72 | fn on_response_chain_entry(&self, arg: &ResponseChainEntry) { 73 | self.local_node 74 | .on_response_chain_entry(self.peer_index, arg); 75 | } 76 | 77 | fn on_response_get_objects(&self, arg: &ResponseGetObjects) { 78 | self.local_node 79 | .on_response_get_objects(self.peer_index, arg); 80 | } 81 | 82 | fn on_support_flags(&self, arg: u32) { 83 | self.local_node 84 | .on_support_flags(self.peer_index, arg) 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /sync/src/synchronization_peers.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | use std::collections::HashMap; 18 | 19 | use parking_lot::RwLock; 20 | 21 | use p2p::types::cn::CoreSyncData; 22 | use p2p::protocol::OutboundSyncConnectionRef; 23 | 24 | use types::PeerIndex; 25 | 26 | pub trait Peers: Send + Sync { 27 | fn insert(&self, 28 | peer_index: PeerIndex, 29 | sync_data: &CoreSyncData, 30 | connection: OutboundSyncConnectionRef); 31 | fn last_sync_data(&self, peer_index: PeerIndex) -> Option; 32 | fn connection(&self, peer_index: PeerIndex) -> Option; 33 | 34 | fn misbehaving(&self, peer_index: PeerIndex, reason: &str); 35 | } 36 | 37 | pub struct Peer { 38 | connection: OutboundSyncConnectionRef, 39 | last_sync_data: CoreSyncData, 40 | } 41 | 42 | pub struct PeersImpl { 43 | peers: RwLock>, 44 | } 45 | 46 | impl PeersImpl { 47 | pub fn new() -> PeersImpl { 48 | PeersImpl { peers: RwLock::new(HashMap::new()) } 49 | } 50 | } 51 | 52 | impl Peers for PeersImpl { 53 | fn insert(&self, 54 | peer_index: PeerIndex, 55 | sync_data: &CoreSyncData, 56 | connection: OutboundSyncConnectionRef) { 57 | trace!("peer insertion - #{}", peer_index); 58 | trace!("peer insertion - sync data - {:?}", sync_data); 59 | 60 | let peer = Peer { 61 | connection, 62 | last_sync_data: sync_data.clone(), 63 | }; 64 | 65 | self.peers.write().insert(peer_index, peer); 66 | } 67 | 68 | fn last_sync_data(&self, peer_index: PeerIndex) -> Option { 69 | self.peers 70 | .read() 71 | .get(&peer_index) 72 | .map(|peer| peer.last_sync_data.clone()) 73 | } 74 | 75 | fn connection(&self, peer_index: PeerIndex) -> Option { 76 | self.peers 77 | .read() 78 | .get(&peer_index) 79 | .map(|peer| peer.connection.clone()) 80 | } 81 | 82 | fn misbehaving(&self, peer_index: PeerIndex, reason: &str) { 83 | if let Some(peer) = self.peers.write().remove(&peer_index) { 84 | warn!("Disconnecting from peer #{} due to misbehaviour: {}", 85 | peer_index, 86 | reason); 87 | peer.connection.close(); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /crypto/sys/blake256.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers 30 | 31 | #ifndef _BLAKE256_H_ 32 | #define _BLAKE256_H_ 33 | 34 | #include 35 | 36 | typedef struct { 37 | uint32_t h[8], s[4], t[2]; 38 | int buflen, nullt; 39 | uint8_t buf[64]; 40 | } state; 41 | 42 | typedef struct { 43 | state inner; 44 | state outer; 45 | } hmac_state; 46 | 47 | void blake256_init(state *); 48 | void blake224_init(state *); 49 | 50 | void blake256_update(state *, const uint8_t *, uint64_t); 51 | void blake224_update(state *, const uint8_t *, uint64_t); 52 | 53 | void blake256_final(state *, uint8_t *); 54 | void blake224_final(state *, uint8_t *); 55 | 56 | void blake256_hash(uint8_t *, const uint8_t *, uint64_t); 57 | void blake224_hash(uint8_t *, const uint8_t *, uint64_t); 58 | 59 | /* HMAC functions: */ 60 | 61 | void hmac_blake256_init(hmac_state *, const uint8_t *, uint64_t); 62 | void hmac_blake224_init(hmac_state *, const uint8_t *, uint64_t); 63 | 64 | void hmac_blake256_update(hmac_state *, const uint8_t *, uint64_t); 65 | void hmac_blake224_update(hmac_state *, const uint8_t *, uint64_t); 66 | 67 | void hmac_blake256_final(hmac_state *, uint8_t *); 68 | void hmac_blake224_final(hmac_state *, uint8_t *); 69 | 70 | void hmac_blake256_hash(uint8_t *, const uint8_t *, uint64_t, const uint8_t *, uint64_t); 71 | void hmac_blake224_hash(uint8_t *, const uint8_t *, uint64_t, const uint8_t *, uint64_t); 72 | 73 | #endif /* _BLAKE256_H_ */ 74 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Based on the "trust" template v0.1.2 2 | # https://github.com/japaric/trust/tree/v0.1.2 3 | 4 | dist: trusty 5 | language: rust 6 | services: docker 7 | sudo: required 8 | 9 | env: 10 | global: 11 | - CRATE_NAME=xmr 12 | 13 | matrix: 14 | include: 15 | # Android 16 | #- env: TARGET=aarch64-linux-android DISABLE_TESTS=1 17 | #- env: TARGET=arm-linux-androideabi DISABLE_TESTS=1 18 | #- env: TARGET=armv7-linux-androideabi DISABLE_TESTS=1 19 | #- env: TARGET=i686-linux-android DISABLE_TESTS=1 20 | #- env: TARGET=x86_64-linux-android DISABLE_TESTS=1 21 | 22 | # iOS 23 | #- env: TARGET=aarch64-apple-ios DISABLE_TESTS=1 24 | #os: osx 25 | #- env: TARGET=armv7-apple-ios DISABLE_TESTS=1 26 | #os: osx 27 | #- env: TARGET=armv7s-apple-ios DISABLE_TESTS=1 28 | #os: osx 29 | #- env: TARGET=i386-apple-ios DISABLE_TESTS=1 30 | #os: osx 31 | #- env: TARGET=x86_64-apple-ios DISABLE_TESTS=1 32 | #os: osx 33 | 34 | # Linux 35 | - env: TARGET=aarch64-unknown-linux-gnu 36 | #- env: TARGET=arm-unknown-linux-gnueabi 37 | #- env: TARGET=armv7-unknown-linux-gnueabihf 38 | - env: TARGET=i686-unknown-linux-gnu 39 | - env: TARGET=i686-unknown-linux-musl 40 | #- env: TARGET=mips-unknown-linux-gnu 41 | #- env: TARGET=mips64-unknown-linux-gnuabi64 42 | #- env: TARGET=mips64el-unknown-linux-gnuabi64 43 | #- env: TARGET=mipsel-unknown-linux-gnu 44 | #- env: TARGET=powerpc-unknown-linux-gnu 45 | #- env: TARGET=powerpc64-unknown-linux-gnu 46 | #- env: TARGET=powerpc64le-unknown-linux-gnu 47 | #- env: TARGET=s390x-unknown-linux-gnu DISABLE_TESTS=1 48 | - env: TARGET=x86_64-unknown-linux-gnu 49 | - env: TARGET=x86_64-unknown-linux-musl 50 | 51 | # OSX 52 | #- env: TARGET=i686-apple-darwin 53 | # os: osx 54 | #- env: TARGET=x86_64-apple-darwin 55 | # os: osx 56 | 57 | # *BSD 58 | #- env: TARGET=i686-unknown-freebsd DISABLE_TESTS=1 59 | #- env: TARGET=x86_64-unknown-freebsd DISABLE_TESTS=1 60 | #- env: TARGET=x86_64-unknown-netbsd DISABLE_TESTS=1 61 | 62 | # Windows 63 | - env: TARGET=x86_64-pc-windows-gnu 64 | 65 | # Bare metal 66 | # These targets don't support std and as such are likely not suitable for 67 | # most crates. 68 | # - env: TARGET=thumbv6m-none-eabi 69 | # - env: TARGET=thumbv7em-none-eabi 70 | # - env: TARGET=thumbv7em-none-eabihf 71 | # - env: TARGET=thumbv7m-none-eabi 72 | 73 | # Testing other channels 74 | - env: TARGET=x86_64-unknown-linux-gnu 75 | rust: nightly 76 | #- env: TARGET=x86_64-apple-darwin 77 | #os: osx 78 | #rust: nightly 79 | 80 | before_install: 81 | - set -e 82 | - rustup self update 83 | 84 | install: 85 | - sh ci/install.sh 86 | - source ~/.cargo/env || true 87 | 88 | script: 89 | - bash ci/script.sh 90 | 91 | after_script: set +e 92 | 93 | cache: cargo 94 | before_cache: 95 | # Travis can't cache files that are not readable by "others" 96 | - chmod -R a+r $HOME/.cargo 97 | 98 | branches: 99 | only: 100 | # release tags 101 | - /^v\d+\.\d+\.\d+.*$/ 102 | - master 103 | 104 | notifications: 105 | email: 106 | on_success: never 107 | -------------------------------------------------------------------------------- /chain/src/transaction/transaction_prefix.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use transaction::{TxIn, TxOut}; 10 | use primitives::H256; 11 | use format::{Deserialize, DeserializerStream, Error, Serialize, SerializerStream, to_binary}; 12 | 13 | /// Transaction prefix. 14 | #[derive(Debug, Clone)] 15 | pub struct TransactionPrefix { 16 | pub version: u8, 17 | pub unlock_time: u64, 18 | pub vin: Vec, 19 | pub vout: Vec, 20 | pub extra: Vec, 21 | } 22 | 23 | impl TransactionPrefix { 24 | pub fn hash(&self) -> H256 { 25 | H256::fast_hash(to_binary(self)) 26 | } 27 | } 28 | 29 | impl Deserialize for TransactionPrefix { 30 | fn deserialize(deserializer: &mut DeserializerStream) -> Result { 31 | let version = deserializer.get_u8_varint()?; 32 | let unlock_time = deserializer.get_u64_varint()?; 33 | 34 | let vin_length = deserializer.get_u64_varint()? as usize; 35 | let mut vin = Vec::with_capacity(vin_length); 36 | 37 | for _ in 0..vin_length { 38 | vin.push(deserializer.get_deserializable()?); 39 | } 40 | 41 | let vout_length = deserializer.get_u64_varint()? as usize; 42 | let mut vout = Vec::with_capacity(vout_length); 43 | 44 | for _ in 0..vout_length { 45 | vout.push(deserializer.get_deserializable()?); 46 | } 47 | 48 | let extra_length = deserializer.get_u64_varint()? as usize; 49 | let extra = deserializer.get_blob(extra_length)?; 50 | 51 | Ok(TransactionPrefix { 52 | version, 53 | unlock_time, 54 | vin, 55 | vout, 56 | extra, 57 | }) 58 | } 59 | } 60 | 61 | impl Serialize for TransactionPrefix { 62 | fn serialize(&self, mut serializer: SerializerStream) { 63 | serializer.put_u8_varint(self.version); 64 | serializer.put_u64_varint(self.unlock_time); 65 | 66 | serializer.put_u64_varint(self.vin.len() as u64); 67 | for tx in self.vin.iter() { 68 | serializer.put_serializable(tx); 69 | } 70 | 71 | serializer.put_u64_varint(self.vout.len() as u64); 72 | for tx in self.vout.iter() { 73 | serializer.put_serializable(tx); 74 | } 75 | 76 | serializer.put_u64_varint(self.extra.len() as u64); 77 | serializer.put_blob(self.extra.as_slice()); 78 | } 79 | 80 | fn len(&self) -> usize { 81 | use varint; 82 | 83 | let mut sum = 0; 84 | sum += varint::length(self.version); 85 | sum += varint::length(self.unlock_time); 86 | sum += varint::length(self.vin.len()); 87 | for tx in self.vin.iter() { 88 | sum += tx.len(); 89 | } 90 | sum += varint::length(self.vout.len()); 91 | for tx in self.vout.iter() { 92 | sum += tx.len(); 93 | } 94 | sum += varint::length(self.extra.len()); 95 | sum += self.extra.len(); 96 | sum 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /varint/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | //! # varint 10 | //! XZ variable length integers reading/writing 11 | 12 | extern crate bytes; 13 | extern crate num; 14 | 15 | use std::mem::size_of; 16 | 17 | use bytes::{BytesMut, Buf, BufMut}; 18 | use num::cast::ToPrimitive; 19 | 20 | /// An error occurred during reading. 21 | #[derive(Debug, Clone, Copy)] 22 | pub enum ReadError { 23 | /// The integer is too large to fit in the current type. 24 | Overflow, 25 | /// The integer cannot be represented. 26 | Represent, 27 | } 28 | 29 | impl std::fmt::Display for ReadError { 30 | fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result { 31 | match *self { 32 | ReadError::Overflow => write!(fmt, "the integer is too large"), 33 | ReadError::Represent => write!(fmt, "the integer cannot be represented"), 34 | } 35 | } 36 | } 37 | 38 | /// Read a varint. 39 | pub fn read(buf: &mut B) -> Result { 40 | let bits = (size_of::() * 8) as u64; 41 | let mut output = 0u64; 42 | let mut shift = 0u64; 43 | loop { 44 | let byte = buf.get_u8(); 45 | 46 | if shift + 7 >= bits && byte >= 1 << (bits - shift) { 47 | return Err(ReadError::Overflow); 48 | } 49 | 50 | if byte == 0 && shift != 0 { 51 | return Err(ReadError::Represent); 52 | } 53 | 54 | // Does the actualy placing into output, stripping the first bit 55 | output |= ((byte & 0x7f) as u64) << shift; 56 | 57 | /* If there is no next */ 58 | if (byte & 0x80) == 0 { 59 | break; 60 | } 61 | 62 | shift += 7; 63 | } 64 | 65 | Ok(output) 66 | } 67 | 68 | /// Calcuate how many bytes a varint occupies in memory. 69 | pub fn length(i: I) -> usize { 70 | let mut i = i.to_u64().unwrap(); 71 | let mut count = 1; 72 | while i >= 0x80 { 73 | count += 1; 74 | i >>= 7; 75 | } 76 | count 77 | } 78 | 79 | /// Write an integer as a varint. 80 | pub fn write(output: &mut BytesMut, i: I) { 81 | let mut i = i.to_u64().unwrap(); 82 | while i >= 0x80 { 83 | output.put((i & 0x7f) as u8 | 0x80); 84 | i >>= 7; 85 | } 86 | output.put_u8(i as u8); 87 | } 88 | 89 | #[cfg(test)] 90 | pub mod tests { 91 | use super::*; 92 | use std::u16::MAX; 93 | use bytes::{BytesMut, IntoBuf}; 94 | 95 | #[test] 96 | fn read_write_is_equal() { 97 | let mut write_buf = BytesMut::with_capacity(64); 98 | for input in 0..MAX { 99 | write(&mut write_buf, input as u16); 100 | 101 | { 102 | let mut read_buf = write_buf.as_ref().into_buf(); 103 | let output = read(&mut read_buf).expect("reading should be fine") as u16; 104 | assert_eq!(input, output); 105 | } 106 | 107 | write_buf.clear(); 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /dxmr/main.rs: -------------------------------------------------------------------------------- 1 | // Xmr, Monero node. 2 | // Copyright (C) 2018 Jean Pierre Dudey 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | extern crate app_dirs; 18 | #[macro_use] 19 | extern crate clap; 20 | 21 | extern crate env_logger; 22 | extern crate log; 23 | 24 | extern crate failure; 25 | 26 | extern crate rand; 27 | 28 | extern crate xmr_chain as chain; 29 | extern crate xmr_db as db; 30 | extern crate xmr_network as network; 31 | extern crate xmr_p2p as p2p; 32 | extern crate xmr_storage as storage; 33 | extern crate xmr_sync as sync; 34 | 35 | mod config; 36 | mod peers; 37 | mod utils; 38 | 39 | use failure::Error; 40 | use app_dirs::AppInfo; 41 | 42 | pub const APP_INFO: AppInfo = AppInfo { 43 | name: "dxmr", 44 | author: "Jean Pierre Dudey", 45 | }; 46 | 47 | fn main() { 48 | env_logger::init(); 49 | 50 | let matches = clap_app!(dxmr => 51 | (version: "0.1.0") 52 | (author: "Jean Pierre Dudey ") 53 | (about: "Monero client") 54 | (@arg threads: --threads +takes_value "Number of threads") 55 | (@arg testnet: --testnet "Use the test network") 56 | (@arg connect: --connect +takes_value "Connect only to the given peer") 57 | (@arg listenport: --listenport +takes_value ) 58 | (@arg hidemyport: --hidemyport) 59 | (@arg outpeers: --outpeers +takes_value "Maximum of outbound peers") 60 | (@arg inpeers: --inpeers +takes_value "Maximum of outbound peers") 61 | ) 62 | .get_matches(); 63 | 64 | // TODO: no unwrap 65 | let cfg = config::parse(&matches).unwrap(); 66 | 67 | if let Err(e) = start(cfg) { 68 | println!("{}", e); 69 | return; 70 | } 71 | } 72 | 73 | fn start(cfg: config::Config) -> Result<(), Error> { 74 | utils::init_db(&cfg); 75 | 76 | let mut el = p2p::event_loop(); 77 | 78 | let local_node = sync::create_local_node(cfg.db.clone(), cfg.network); 79 | let local_sync_node = sync::create_local_sync_node(local_node.clone()); 80 | 81 | let mut rng = rand::OsRng::new().expect("couldn't open OS random"); 82 | 83 | let config = p2p::Config { 84 | threads: cfg.threads, 85 | network: cfg.network, 86 | peers: cfg.peers, 87 | listen_port: cfg.listen_port, 88 | hide_my_port: cfg.hide_my_port, 89 | out_peers: cfg.out_peers, 90 | in_peers: cfg.in_peers, 91 | peer_id: p2p::types::PeerId::random(&mut rng), 92 | }; 93 | 94 | let p2p = p2p::P2P::new(config, el.handle(), cfg.db.clone(), local_sync_node); 95 | 96 | p2p.run().expect("couldn't start p2p"); 97 | 98 | el.run(p2p::forever()).expect("couldn't run event loop"); 99 | 100 | Ok(()) 101 | } 102 | -------------------------------------------------------------------------------- /crypto/sys/groestl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2018, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef __hash_h 30 | #define __hash_h 31 | /* 32 | #include "crypto_uint8.h" 33 | #include "crypto_uint32.h" 34 | #include "crypto_uint64.h" 35 | #include "crypto_hash.h" 36 | 37 | typedef crypto_uint8 uint8_t; 38 | typedef crypto_uint32 uint32_t; 39 | typedef crypto_uint64 uint64_t; 40 | */ 41 | #include 42 | 43 | /* some sizes (number of bytes) */ 44 | #define ROWS 8 45 | #define LENGTHFIELDLEN ROWS 46 | #define COLS512 8 47 | 48 | #define SIZE512 (ROWS*COLS512) 49 | 50 | #define ROUNDS512 10 51 | #define HASH_BIT_LEN 256 52 | 53 | #define ROTL32(v, n) ((((v)<<(n))|((v)>>(32-(n))))&li_32(ffffffff)) 54 | 55 | 56 | #define li_32(h) 0x##h##u 57 | #define EXT_BYTE(var,n) ((uint8_t)((uint32_t)(var) >> (8*n))) 58 | #define u32BIG(a) \ 59 | ((ROTL32(a,8) & li_32(00FF00FF)) | \ 60 | (ROTL32(a,24) & li_32(FF00FF00))) 61 | 62 | 63 | /* NIST API begin */ 64 | typedef unsigned char BitSequence; 65 | typedef unsigned long long DataLength; 66 | typedef struct { 67 | uint32_t chaining[SIZE512/sizeof(uint32_t)]; /* actual state */ 68 | uint32_t block_counter1, 69 | block_counter2; /* message block counter(s) */ 70 | BitSequence buffer[SIZE512]; /* data buffer */ 71 | int buf_ptr; /* data buffer pointer */ 72 | int bits_in_last_byte; /* no. of message bits in last byte of 73 | data buffer */ 74 | } hashState; 75 | 76 | /*void Init(hashState*); 77 | void Update(hashState*, const BitSequence*, DataLength); 78 | void Final(hashState*, BitSequence*); */ 79 | void groestl(const BitSequence*, DataLength, BitSequence*); 80 | /* NIST API end */ 81 | 82 | /* 83 | int crypto_hash(unsigned char *out, 84 | const unsigned char *in, 85 | unsigned long long len); 86 | */ 87 | 88 | #endif /* __hash_h */ 89 | -------------------------------------------------------------------------------- /chain/src/transaction/tx_in.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Jean Pierre Dudey 2 | // 3 | // Licensed under the Apache License, Version 2.0 or the MIT license 5 | // , at your 6 | // option. This file may not be copied, modified, or distributed 7 | // except according to those terms. 8 | 9 | use transaction::{TxInGen, TxInToKey, TxInToScript, TxInToScriptHash}; 10 | use format::{Deserialize, DeserializerStream, Error, Serialize, SerializerStream}; 11 | 12 | const GEN: u8 = 0xff; 13 | const TO_KEY: u8 = 2; 14 | const TO_SCRIPT: u8 = 0; 15 | const TO_SCRIPT_HASH: u8 = 1; 16 | 17 | /// Transaction input. 18 | #[derive(Debug, Clone)] 19 | pub enum TxIn { 20 | Gen(TxInGen), 21 | ToKey(TxInToKey), 22 | ToScript(TxInToScript), 23 | ToScriptHash(TxInToScriptHash), 24 | } 25 | 26 | impl TxIn { 27 | pub fn signature_size(&self) -> usize { 28 | match *self { 29 | TxIn::Gen(_) => 0, 30 | TxIn::ToKey(ref tx) => tx.key_offsets.len(), 31 | TxIn::ToScript(_) => 0, 32 | TxIn::ToScriptHash(_) => 0, 33 | } 34 | } 35 | } 36 | 37 | impl From for TxIn { 38 | fn from(tx: TxInGen) -> TxIn { 39 | TxIn::Gen(tx) 40 | } 41 | } 42 | 43 | impl From for TxIn { 44 | fn from(tx: TxInToKey) -> TxIn { 45 | TxIn::ToKey(tx) 46 | } 47 | } 48 | 49 | impl From for TxIn { 50 | fn from(tx: TxInToScript) -> TxIn { 51 | TxIn::ToScript(tx) 52 | } 53 | } 54 | 55 | impl From for TxIn { 56 | fn from(tx: TxInToScriptHash) -> TxIn { 57 | TxIn::ToScriptHash(tx) 58 | } 59 | } 60 | 61 | impl Deserialize for TxIn { 62 | fn deserialize(deserializer: &mut DeserializerStream) -> Result { 63 | let tag = deserializer.get_u8()?; 64 | let target = match tag { 65 | GEN => TxIn::Gen(deserializer.get_deserializable()?), 66 | TO_KEY => TxIn::ToKey(deserializer.get_deserializable()?), 67 | TO_SCRIPT => TxIn::ToScript(deserializer.get_deserializable()?), 68 | TO_SCRIPT_HASH => TxIn::ToScriptHash(deserializer.get_deserializable()?), 69 | n => return Err(Error::custom(format!("unknown variant tag: {:X}", n))), 70 | }; 71 | 72 | Ok(target) 73 | } 74 | } 75 | 76 | impl Serialize for TxIn { 77 | fn serialize(&self, mut serializer: SerializerStream) { 78 | match *self { 79 | TxIn::Gen(ref v) => { 80 | serializer.put_u8(GEN); 81 | serializer.put_serializable(v); 82 | } 83 | TxIn::ToKey(ref v) => { 84 | serializer.put_u8(TO_KEY); 85 | serializer.put_serializable(v); 86 | } 87 | TxIn::ToScript(ref v) => { 88 | serializer.put_u8(TO_SCRIPT); 89 | serializer.put_serializable(v); 90 | } 91 | TxIn::ToScriptHash(ref v) => { 92 | serializer.put_u8(TO_SCRIPT_HASH); 93 | serializer.put_serializable(v); 94 | } 95 | } 96 | } 97 | 98 | fn len(&self) -> usize { 99 | let mut sum = 1; 100 | sum += match *self { 101 | TxIn::Gen(ref v) => v.len(), 102 | TxIn::ToKey(ref v) => v.len(), 103 | TxIn::ToScript(ref v) => v.len(), 104 | TxIn::ToScriptHash(ref v) => v.len(), 105 | }; 106 | sum 107 | } 108 | } 109 | --------------------------------------------------------------------------------