CEF changes
This commit is contained in:
BIN
3rd_party/CEF/SFXWiz32.exe
vendored
Normal file
BIN
3rd_party/CEF/SFXWiz32.exe
vendored
Normal file
Binary file not shown.
1057
3rd_party/CEF/automate/automate-git.py
vendored
Normal file
1057
3rd_party/CEF/automate/automate-git.py
vendored
Normal file
File diff suppressed because it is too large
Load Diff
26
3rd_party/CEF/create_common.cmd
vendored
Normal file
26
3rd_party/CEF/create_common.cmd
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
@echo off
|
||||
pushd "%~dp0%"
|
||||
|
||||
mkdir automate
|
||||
mkdir chromium_git
|
||||
mkdir depot_tools
|
||||
|
||||
wget --no-check-certificate https://bitbucket.org/chromiumembedded/cef/raw/master/tools/automate/automate-git.py || goto :ERROR
|
||||
move /y automate-git.py automate\ || goto :ERROR
|
||||
|
||||
wget --no-check-certificate https://storage.googleapis.com/chrome-infra/depot_tools.zip || goto :ERROR
|
||||
unzip -o -q -d depot_tools\ depot_tools.zip || goto :ERROR
|
||||
del /q depot_tools.zip || goto :ERROR
|
||||
pushd depot_tools
|
||||
call update_depot_tools.bat || goto :ERROR
|
||||
popd
|
||||
|
||||
goto :END
|
||||
|
||||
:ERROR
|
||||
pause
|
||||
popd
|
||||
exit 1
|
||||
|
||||
:END
|
||||
popd
|
33
3rd_party/CEF/create_debug.cmd
vendored
Normal file
33
3rd_party/CEF/create_debug.cmd
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
@echo off
|
||||
set ROOT=%~dp0%
|
||||
pushd %ROOT%
|
||||
|
||||
set PATH=%ROOT%\depot_tools;%PATH%
|
||||
call create_common.cmd
|
||||
|
||||
set CEF_USE_GN=1
|
||||
set GN_DEFINES=is_win_fastlink=true
|
||||
set GN_ARGUMENTS=--ide=vs2015 --sln=cef --filters=//cef/*
|
||||
|
||||
pushd chromium_git
|
||||
call python ..\automate\automate-git.py --download-dir=%ROOT%chromium_git --depot-tools-dir=%ROOT%depot_tools --no-distrib --no-build || goto :ERROR
|
||||
popd
|
||||
|
||||
pushd chromium_git\chromium\src\cef
|
||||
call cef_create_projects.bat
|
||||
popd
|
||||
|
||||
pushd chromium_git\chromium\src
|
||||
call ninja -C out\Debug_GN_x64 cef || goto :ERROR
|
||||
popd
|
||||
|
||||
goto :END
|
||||
|
||||
:ERROR
|
||||
pause
|
||||
popd
|
||||
exit 1
|
||||
|
||||
:END
|
||||
popd
|
||||
exit 0
|
32
3rd_party/CEF/create_release.cmd
vendored
Normal file
32
3rd_party/CEF/create_release.cmd
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
@echo off
|
||||
set ROOT=%~dp0%
|
||||
pushd %ROOT%
|
||||
|
||||
set PATH=%ROOT%\depot_tools;%PATH%
|
||||
call create_common.cmd
|
||||
|
||||
set CEF_USE_GN=1
|
||||
set GN_ARGUMENTS=--ide=vs2015 --sln=cef --filters=//cef/*
|
||||
|
||||
pushd chromium_git
|
||||
call python ..\automate\automate-git.py --download-dir=%ROOT%\chromium_git --depot-tools-dir=%ROOT%\depot_tools --no-distrib --no-build || goto :ERROR
|
||||
popd
|
||||
|
||||
pushd chromium_git\chromium\src\cef
|
||||
call cef_create_projects.bat
|
||||
popd
|
||||
|
||||
pushd chromium_git\chromium\src
|
||||
call ninja -C out\Release_GN_x64 cef || goto :ERROR
|
||||
popd
|
||||
|
||||
goto :END
|
||||
|
||||
:ERROR
|
||||
pause
|
||||
popd
|
||||
exit 1
|
||||
|
||||
:END
|
||||
popd
|
||||
exit 0
|
1
3rd_party/CEF/depot_tools
vendored
Submodule
1
3rd_party/CEF/depot_tools
vendored
Submodule
Submodule 3rd_party/CEF/depot_tools added at ecf3dbe49f
BIN
3rd_party/CEF/funzip.exe
vendored
Normal file
BIN
3rd_party/CEF/funzip.exe
vendored
Normal file
Binary file not shown.
BIN
3rd_party/CEF/libeay32.dll
vendored
Normal file
BIN
3rd_party/CEF/libeay32.dll
vendored
Normal file
Binary file not shown.
BIN
3rd_party/CEF/libiconv2.dll
vendored
Normal file
BIN
3rd_party/CEF/libiconv2.dll
vendored
Normal file
Binary file not shown.
BIN
3rd_party/CEF/libintl3.dll
vendored
Normal file
BIN
3rd_party/CEF/libintl3.dll
vendored
Normal file
Binary file not shown.
BIN
3rd_party/CEF/libssl32.dll
vendored
Normal file
BIN
3rd_party/CEF/libssl32.dll
vendored
Normal file
Binary file not shown.
BIN
3rd_party/CEF/unzip.exe
vendored
Normal file
BIN
3rd_party/CEF/unzip.exe
vendored
Normal file
Binary file not shown.
BIN
3rd_party/CEF/unzip32.dll
vendored
Normal file
BIN
3rd_party/CEF/unzip32.dll
vendored
Normal file
Binary file not shown.
BIN
3rd_party/CEF/unzipsfx.exe
vendored
Normal file
BIN
3rd_party/CEF/unzipsfx.exe
vendored
Normal file
Binary file not shown.
BIN
3rd_party/CEF/uzexampl.exe
vendored
Normal file
BIN
3rd_party/CEF/uzexampl.exe
vendored
Normal file
Binary file not shown.
BIN
3rd_party/CEF/wget.exe
vendored
Normal file
BIN
3rd_party/CEF/wget.exe
vendored
Normal file
Binary file not shown.
BIN
3rd_party/CEF/zipinfo.exe
vendored
Normal file
BIN
3rd_party/CEF/zipinfo.exe
vendored
Normal file
Binary file not shown.
5
3rd_party/Dokan Library-1.0.2/README.url
vendored
Normal file
5
3rd_party/Dokan Library-1.0.2/README.url
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
[{000214A0-0000-0000-C000-000000000046}]
|
||||
Prop3=19,11
|
||||
[InternetShortcut]
|
||||
IDList=
|
||||
URL=https://github.com/dokan-dev/dokany/blob/master/README.md
|
BIN
3rd_party/Dokan Library-1.0.2/cygdokanfuse1.dll
vendored
Normal file
BIN
3rd_party/Dokan Library-1.0.2/cygdokanfuse1.dll
vendored
Normal file
Binary file not shown.
BIN
3rd_party/Dokan Library-1.0.2/dokan1.dll
vendored
Normal file
BIN
3rd_party/Dokan Library-1.0.2/dokan1.dll
vendored
Normal file
Binary file not shown.
BIN
3rd_party/Dokan Library-1.0.2/dokanctl.exe
vendored
Normal file
BIN
3rd_party/Dokan Library-1.0.2/dokanctl.exe
vendored
Normal file
Binary file not shown.
BIN
3rd_party/Dokan Library-1.0.2/dokanfuse1.dll
vendored
Normal file
BIN
3rd_party/Dokan Library-1.0.2/dokanfuse1.dll
vendored
Normal file
Binary file not shown.
BIN
3rd_party/Dokan Library-1.0.2/dokannp1.dll
vendored
Normal file
BIN
3rd_party/Dokan Library-1.0.2/dokannp1.dll
vendored
Normal file
Binary file not shown.
50
3rd_party/Dokan Library-1.0.2/driver/dokan.inf
vendored
Normal file
50
3rd_party/Dokan Library-1.0.2/driver/dokan.inf
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
[Version]
|
||||
Signature = "$Windows NT$"
|
||||
Class = DiskDrive
|
||||
ClassGuid = {4d36e967-e325-11ce-bfc1-08002be10318}
|
||||
Provider = %Dokan%
|
||||
DriverVer=01/23/2017,1.0.2.0
|
||||
CatalogFile = %DriverName%.cat
|
||||
DriverPackageType = FileSystem
|
||||
|
||||
[DestinationDirs]
|
||||
DefaultDestDir = 12
|
||||
DokanFileSystem.DriverFiles = 12
|
||||
|
||||
[DefaultInstall]
|
||||
OptionDesc = %ServiceDesc%
|
||||
CopyFiles = DokanFileSystem.DriverFiles
|
||||
|
||||
[DefaultInstall.Services]
|
||||
AddService = %ServiceName%,,DokanFileSystem.Service
|
||||
|
||||
[DefaultUninstall]
|
||||
DelFiles = DokanFileSystem.DriverFiles
|
||||
|
||||
[DefaultUninstall.Services]
|
||||
DelService = %ServiceName%,0x200
|
||||
|
||||
[SourceDisksNames]
|
||||
1 = %Disk1%
|
||||
|
||||
[SourceDisksFiles]
|
||||
dokan1.sys = 1
|
||||
|
||||
[DokanFileSystem.DriverFiles]
|
||||
%DriverName%.sys
|
||||
|
||||
[DokanFileSystem.Service]
|
||||
DisplayName = %ServiceName%
|
||||
Description = %ServiceDesc%
|
||||
ServiceBinary = %12%\%DriverName%.sys
|
||||
ServiceType = 2 ; SERVICE_FILE_SYSTEM_DRIVER
|
||||
StartType = 1 ; SERVICE_SYSTEM_START
|
||||
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
|
||||
LoadOrderGroup = "File System"
|
||||
|
||||
[Strings]
|
||||
Dokan = "Dokan"
|
||||
DriverName = "dokan1"
|
||||
Disk1 = "Dokan installation media"
|
||||
ServiceDesc = "Dokan kernel-mode file system driver."
|
||||
ServiceName = "dokan1"
|
BIN
3rd_party/Dokan Library-1.0.2/driver/dokan1.cat
vendored
Normal file
BIN
3rd_party/Dokan Library-1.0.2/driver/dokan1.cat
vendored
Normal file
Binary file not shown.
BIN
3rd_party/Dokan Library-1.0.2/driver/dokan1.sys
vendored
Normal file
BIN
3rd_party/Dokan Library-1.0.2/driver/dokan1.sys
vendored
Normal file
Binary file not shown.
877
3rd_party/Dokan Library-1.0.2/include/dokan/dokan.h
vendored
Normal file
877
3rd_party/Dokan Library-1.0.2/include/dokan/dokan.h
vendored
Normal file
@@ -0,0 +1,877 @@
|
||||
/*
|
||||
Dokan : user-mode file system library for Windows
|
||||
|
||||
Copyright (C) 2015 - 2017 Adrien J. <liryna.stark@gmail.com> and Maxime C. <maxime@islog.com>
|
||||
Copyright (C) 2007 - 2011 Hiroki Asakawa <info@dokan-dev.net>
|
||||
|
||||
http://dokan-dev.github.io
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DOKAN_H_
|
||||
#define DOKAN_H_
|
||||
|
||||
/** Do not include NTSTATUS. Fix duplicate preprocessor definitions */
|
||||
#define WIN32_NO_STATUS
|
||||
#include <windows.h>
|
||||
#undef WIN32_NO_STATUS
|
||||
#include <ntstatus.h>
|
||||
|
||||
#include "fileinfo.h"
|
||||
#include "public.h"
|
||||
|
||||
#ifdef _EXPORTING
|
||||
/** Export dokan API see also dokan.def for export */
|
||||
#define DOKANAPI __stdcall
|
||||
#else
|
||||
/** Import dokan API */
|
||||
#define DOKANAPI __declspec(dllimport) __stdcall
|
||||
#endif
|
||||
|
||||
/** Change calling convention to standard call */
|
||||
#define DOKAN_CALLBACK __stdcall
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @file */
|
||||
|
||||
/**
|
||||
* \defgroup Dokan Dokan
|
||||
* \brief Dokan Library const and methodes
|
||||
*/
|
||||
/** @{ */
|
||||
|
||||
/** The current Dokan version (ver 1.0.0). \ref DOKAN_OPTIONS.Version */
|
||||
#define DOKAN_VERSION 100
|
||||
/** Minimum Dokan version (ver 1.0.0) accepted. */
|
||||
#define DOKAN_MINIMUM_COMPATIBLE_VERSION 100
|
||||
/** Maximum number of dokan instances.*/
|
||||
#define DOKAN_MAX_INSTANCES 32
|
||||
/** Driver file name including the DOKAN_MAJOR_API_VERSION */
|
||||
#define DOKAN_DRIVER_NAME L"dokan" DOKAN_MAJOR_API_VERSION L".sys"
|
||||
/** Network provider name including the DOKAN_MAJOR_API_VERSION */
|
||||
#define DOKAN_NP_NAME L"Dokan" DOKAN_MAJOR_API_VERSION
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* \defgroup DOKAN_OPTION DOKAN_OPTION
|
||||
* \brief All DOKAN_OPTION flags used in DOKAN_OPTIONS.Options
|
||||
* \see DOKAN_FILE_INFO
|
||||
*/
|
||||
/** @{ */
|
||||
|
||||
/** Enable ouput debug message */
|
||||
#define DOKAN_OPTION_DEBUG 1
|
||||
/** Enable ouput debug message to stderr */
|
||||
#define DOKAN_OPTION_STDERR 2
|
||||
/** Use alternate stream */
|
||||
#define DOKAN_OPTION_ALT_STREAM 4
|
||||
/** Enable mount drive as write-protected */
|
||||
#define DOKAN_OPTION_WRITE_PROTECT 8
|
||||
/** Use network drive - Dokan network provider need to be installed */
|
||||
#define DOKAN_OPTION_NETWORK 16
|
||||
/** Use removable drive */
|
||||
#define DOKAN_OPTION_REMOVABLE 32
|
||||
/** Use mount manager */
|
||||
#define DOKAN_OPTION_MOUNT_MANAGER 64
|
||||
/** Mount the drive on current session only */
|
||||
#define DOKAN_OPTION_CURRENT_SESSION 128
|
||||
/** Enable Lockfile/Unlockfile operations. Otherwise Dokan will take care of it */
|
||||
#define DOKAN_OPTION_FILELOCK_USER_MODE 256
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* \struct DOKAN_OPTIONS
|
||||
* \brief Dokan mount options used to describe dokan device behavior.
|
||||
* \see DokanMain
|
||||
*/
|
||||
typedef struct _DOKAN_OPTIONS {
|
||||
/** Version of the dokan features requested (version "123" is equal to Dokan version 1.2.3). */
|
||||
USHORT Version;
|
||||
/** Number of threads to be used internally by Dokan library. More thread will handle more event at the same time. */
|
||||
USHORT ThreadCount;
|
||||
/** Features enable for the mount. See \ref DOKAN_OPTION. */
|
||||
ULONG Options;
|
||||
/** FileSystem can store anything here. */
|
||||
ULONG64 GlobalContext;
|
||||
/** Mount point. Can be "M:\" (drive letter) or "C:\mount\dokan" (path in NTFS). */
|
||||
LPCWSTR MountPoint;
|
||||
/**
|
||||
* UNC Name for the Network Redirector
|
||||
* \see <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff556761(v=vs.85).aspx">Support for UNC Naming</a>
|
||||
*/
|
||||
LPCWSTR UNCName;
|
||||
/** Max timeout in milliseconds of each request before Dokan give up. */
|
||||
ULONG Timeout;
|
||||
/** Allocation Unit Size of the volume. This will behave on the file size. */
|
||||
ULONG AllocationUnitSize;
|
||||
/** Sector Size of the volume. This will behave on the file size. */
|
||||
ULONG SectorSize;
|
||||
} DOKAN_OPTIONS, *PDOKAN_OPTIONS;
|
||||
|
||||
/**
|
||||
* \struct DOKAN_FILE_INFO
|
||||
* \brief Dokan file information on the current operation.
|
||||
*/
|
||||
typedef struct _DOKAN_FILE_INFO {
|
||||
/**
|
||||
* Context that can be used to carry information between operation.
|
||||
* The Context can carry whatever type like \c HANDLE, struct, int,
|
||||
* internal reference that will help the implementation understand the request context of the event.
|
||||
*/
|
||||
ULONG64 Context;
|
||||
/** Reserved. Used internally by Dokan library. Never modify. */
|
||||
ULONG64 DokanContext;
|
||||
/** A pointer to DOKAN_OPTIONS which was passed to DokanMain. */
|
||||
PDOKAN_OPTIONS DokanOptions;
|
||||
/**
|
||||
* Process id for the thread that originally requested a given I/O operation.
|
||||
*/
|
||||
ULONG ProcessId;
|
||||
/**
|
||||
* Requesting a directory file.
|
||||
* Must be set in \ref DOKAN_OPERATIONS.ZwCreateFile if the file appear to be a folder.
|
||||
*/
|
||||
UCHAR IsDirectory;
|
||||
/** Flag if the file has to be delete during DOKAN_OPERATIONS.Cleanup event. */
|
||||
UCHAR DeleteOnClose;
|
||||
/** Read or write is paging IO. */
|
||||
UCHAR PagingIo;
|
||||
/** Read or write is synchronous IO. */
|
||||
UCHAR SynchronousIo;
|
||||
/** Read or write directly from data source without cache */
|
||||
UCHAR Nocache;
|
||||
/** If \c TRUE, write to the current end of file instead of using the Offset parameter. */
|
||||
UCHAR WriteToEndOfFile;
|
||||
} DOKAN_FILE_INFO, *PDOKAN_FILE_INFO;
|
||||
|
||||
/**
|
||||
* \brief FillFindData Used to add an entry in FindFiles operation
|
||||
* \return 1 if buffer is full, otherwise 0 (currently it never returns 1)
|
||||
*/
|
||||
typedef int(WINAPI *PFillFindData)(PWIN32_FIND_DATAW, PDOKAN_FILE_INFO);
|
||||
|
||||
/**
|
||||
* \brief FillFindStreamData Used to add an entry in FindStreams
|
||||
* \return 1 if buffer is full, otherwise 0 (currently it never returns 1)
|
||||
*/
|
||||
typedef int(WINAPI *PFillFindStreamData)(PWIN32_FIND_STREAM_DATA,
|
||||
PDOKAN_FILE_INFO);
|
||||
|
||||
// clang-format off
|
||||
|
||||
/**
|
||||
* \struct DOKAN_OPERATIONS
|
||||
* \brief Dokan API callbacks interface
|
||||
*
|
||||
* DOKAN_OPERATIONS is a struct of callbacks that describe all Dokan API operation
|
||||
* that will be called when Windows access to the filesystem.
|
||||
*
|
||||
* If an error occurs, return NTSTATUS (https://support.microsoft.com/en-us/kb/113996).
|
||||
* Win32 Error can be converted to \c NTSTATUS with \ref DokanNtStatusFromWin32
|
||||
*
|
||||
* All this callbacks can be set to \c NULL or return \c STATUS_NOT_IMPLEMENTED
|
||||
* if you dont want to support one of them. Be aware that returning such value to important callbacks
|
||||
* such as DOKAN_OPERATIONS.ZwCreateFile / DOKAN_OPERATIONS.ReadFile / ... would make the filesystem not working or unstable.
|
||||
*/
|
||||
typedef struct _DOKAN_OPERATIONS {
|
||||
/**
|
||||
* \brief CreateFile Dokan API callback
|
||||
*
|
||||
* CreateFile is called each time a request is made on a file system object.
|
||||
*
|
||||
* In case \c OPEN_ALWAYS & \c CREATE_ALWAYS are opening successfully a already
|
||||
* existing file, you have to return \c STATUS_OBJECT_NAME_COLLISION instead of \c STATUS_SUCCESS .
|
||||
* This will inform Dokan that the file has been opened and not created during the request.
|
||||
*
|
||||
* If the file is a directory, CreateFile is also called.
|
||||
* In this case, CreateFile should return \c STATUS_SUCCESS when that directory
|
||||
* can be opened and DOKAN_FILE_INFO.IsDirectory has to be set to \c TRUE.
|
||||
*
|
||||
* DOKAN_FILE_INFO.Context can be use to store Data (like \c HANDLE)
|
||||
* that can be retrieved in all other request related to the Context
|
||||
*
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param SecurityContext SecurityContext, see https://msdn.microsoft.com/en-us/library/windows/hardware/ff550613(v=vs.85).aspx
|
||||
* \param DesiredAccess Specifies an <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff540466(v=vs.85).aspx">ACCESS_MASK</a> value that determines the requested access to the object.
|
||||
* \param FileAttributes Specifies one or more FILE_ATTRIBUTE_XXX flags, which represent the file attributes to set if you create or overwrite a file.
|
||||
* \param ShareAccess Type of share access, which is specified as zero or any combination of FILE_SHARE_* flags.
|
||||
* \param CreateDisposition Specifies the action to perform if the file does or does not exist.
|
||||
* \param CreateOptions Specifies the options to apply when the driver creates or opens the file.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
* \see <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff566424(v=vs.85).aspx">See ZwCreateFile for more information about the parameters of this callback (MSDN).</a>
|
||||
* \see DokanMapKernelToUserCreateFileFlags
|
||||
* \see DokanMapStandardToGenericAccess
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *ZwCreateFile)(LPCWSTR FileName,
|
||||
PDOKAN_IO_SECURITY_CONTEXT SecurityContext,
|
||||
ACCESS_MASK DesiredAccess,
|
||||
ULONG FileAttributes,
|
||||
ULONG ShareAccess,
|
||||
ULONG CreateDisposition,
|
||||
ULONG CreateOptions,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief Cleanup Dokan API callback
|
||||
*
|
||||
* Cleanup request before \ref CloseFile is called.
|
||||
*
|
||||
* When DOKAN_FILE_INFO.DeleteOnClose is \c TRUE, you must delete the file in Cleanup.
|
||||
* See DeleteFile documentation for explanation.
|
||||
*
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \see DeleteFile
|
||||
* \see DeleteDirectory
|
||||
*/
|
||||
void(DOKAN_CALLBACK *Cleanup)(LPCWSTR FileName,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief CloseFile Dokan API callback
|
||||
*
|
||||
* Clean remaining Context
|
||||
*
|
||||
* CloseFile is called at the end of the life of the context.
|
||||
* Remainings in \ref DOKAN_FILE_INFO.Context has to be cleared before return.
|
||||
*
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
*/
|
||||
void(DOKAN_CALLBACK *CloseFile)(LPCWSTR FileName,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief ReadFile Dokan API callback
|
||||
*
|
||||
* ReadFile callback on the file previously opened in DOKAN_OPERATIONS.ZwCreateFile.
|
||||
* It can be called by different thread at the same time.
|
||||
* Therefor the read/context has to be thread safe.
|
||||
*
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param Buffer Read buffer that has to be fill with the read result.
|
||||
* \param BufferLength Buffer length and also the read size to proceed.
|
||||
* \param ReadLength Total data size that has been read.
|
||||
* \param Offset Offset from where the read has to be proceed.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
* \see WriteFile
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *ReadFile)(LPCWSTR FileName,
|
||||
LPVOID Buffer,
|
||||
DWORD BufferLength,
|
||||
LPDWORD ReadLength,
|
||||
LONGLONG Offset,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief WriteFile Dokan API callback
|
||||
*
|
||||
* WriteFile callback on the file previously opened in DOKAN_OPERATIONS.ZwCreateFile
|
||||
* It can be called by different thread at the same time.
|
||||
* Therefor the write/context has to be thread safe.
|
||||
*
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param Buffer Data that has to be written.
|
||||
* \param NumberOfBytesToWrite Buffer length and also the write size to proceed.
|
||||
* \param NumberOfBytesWritten Total byte that has been write.
|
||||
* \param Offset Offset from where the write has to be proceed.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
* \see ReadFile
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *WriteFile)(LPCWSTR FileName,
|
||||
LPCVOID Buffer,
|
||||
DWORD NumberOfBytesToWrite,
|
||||
LPDWORD NumberOfBytesWritten,
|
||||
LONGLONG Offset,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief FlushFileBuffers Dokan API callback
|
||||
*
|
||||
* Clears buffers for this context and causes any buffered data to be written to the file.
|
||||
*
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *FlushFileBuffers)(LPCWSTR FileName,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief GetFileInformation Dokan API callback
|
||||
*
|
||||
* Get specific informations on a file.
|
||||
*
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param Buffer BY_HANDLE_FILE_INFORMATION struct to fill.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *GetFileInformation)(LPCWSTR FileName,
|
||||
LPBY_HANDLE_FILE_INFORMATION Buffer,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief FindFiles Dokan API callback
|
||||
*
|
||||
* List all files in the path requested
|
||||
* \ref DOKAN_OPERATIONS.FindFilesWithPattern is checking first. If it is not implemented or
|
||||
* returns \c STATUS_NOT_IMPLEMENTED, then FindFiles is called, if implemented.
|
||||
*
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param FillFindData Callback that has to be called with PWIN32_FIND_DATAW that contain file information.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
* \see FindFilesWithPattern
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *FindFiles)(LPCWSTR FileName,
|
||||
PFillFindData FillFindData,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief FindFilesWithPattern Dokan API callback
|
||||
*
|
||||
* Same as \ref DOKAN_OPERATIONS.FindFiles but with a search pattern.
|
||||
*
|
||||
* \param PathName Path requested by the Kernel on the FileSystem.
|
||||
* \param SearchPattern Search pattern.
|
||||
* \param FillFindData Callback that has to be called with PWIN32_FIND_DATAW that contain file information.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
* \see FindFiles
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *FindFilesWithPattern)(LPCWSTR PathName,
|
||||
LPCWSTR SearchPattern,
|
||||
PFillFindData FillFindData,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief SetFileAttributes Dokan API callback
|
||||
*
|
||||
* Set file attributes on a specific file
|
||||
*
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param FileAttributes FileAttributes to set on file.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *SetFileAttributes)(LPCWSTR FileName,
|
||||
DWORD FileAttributes,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief SetFileTime Dokan API callback
|
||||
*
|
||||
* Set file attributes on a specific file
|
||||
*
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param CreationTime Creation FILETIME.
|
||||
* \param LastAccessTime LastAccess FILETIME.
|
||||
* \param LastWriteTime LastWrite FILETIME.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *SetFileTime)(LPCWSTR FileName,
|
||||
CONST FILETIME *CreationTime,
|
||||
CONST FILETIME *LastAccessTime,
|
||||
CONST FILETIME *LastWriteTime,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief DeleteFile Dokan API callback
|
||||
*
|
||||
* Check if it is possible to delete a file.
|
||||
*
|
||||
* DeleteFile will also be called with DOKAN_FILE_INFO.DeleteOnClose set to \c FALSE
|
||||
* to notify the driver when the file is no longer requested to be deleted.
|
||||
*
|
||||
* You should not delete the file in DeleteFile, but instead
|
||||
* you must only check whether you can delete the file or not,
|
||||
* and return \c STATUS_SUCCESS (when you can delete it) or appropriate error
|
||||
* codes such as \c STATUS_ACCESS_DENIED or \c STATUS_OBJECT_NAME_NOT_FOUND.
|
||||
*
|
||||
* When you return \c STATUS_SUCCESS, you get a Cleanup call afterwards with
|
||||
* DOKAN_FILE_INFO.DeleteOnClose set to \c TRUE and only then you have to actually
|
||||
* delete the file being closed
|
||||
*
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
* \see DeleteDirectory
|
||||
* \see Cleanup
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *DeleteFile)(LPCWSTR FileName,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief DeleteDirectory Dokan API callback
|
||||
*
|
||||
* Check if it is possible to delete a directory.
|
||||
*
|
||||
* DeleteDirectory will also be called with DOKAN_FILE_INFO.DeleteOnClose set to \c FALSE
|
||||
* to notify the driver when the file is no longer requested to be deleted.
|
||||
*
|
||||
* You should not delete the Directory in DeleteDirectory, but instead
|
||||
* you must only check whether you can delete the file or not,
|
||||
* and return \c STATUS_SUCCESS (when you can delete it) or appropriate error
|
||||
* codes such as \c STATUS_ACCESS_DENIED, \c STATUS_OBJECT_PATH_NOT_FOUND,
|
||||
* or \c STATUS_DIRECTORY_NOT_EMPTY.
|
||||
*
|
||||
* When you return \c STATUS_SUCCESS, you get a Cleanup call afterwards with
|
||||
* DOKAN_FILE_INFO.DeleteOnClose set to \c TRUE and only then you have to actually
|
||||
* delete the file being closed
|
||||
*
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or \c NTSTATUS appropriate to the request result.
|
||||
* \ref DeleteFile
|
||||
* \ref Cleanup
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *DeleteDirectory)(LPCWSTR FileName,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief MoveFile Dokan API callback
|
||||
*
|
||||
* Move a file or directory to his new destination
|
||||
*
|
||||
* \param FileName Path to the file to move.
|
||||
* \param NewFileName Path for the new location of the file
|
||||
* \param ReplaceIfExisting Can replace or not if destination already exist.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *MoveFile)(LPCWSTR FileName,
|
||||
LPCWSTR NewFileName,
|
||||
BOOL ReplaceIfExisting,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief SetEndOfFile Dokan API callback
|
||||
*
|
||||
* SetEndOfFile is used to truncate or extend a file (physical file size).
|
||||
*
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param ByteOffset File length to set.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *SetEndOfFile)(LPCWSTR FileName,
|
||||
LONGLONG ByteOffset,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief SetAllocationSize Dokan API callback
|
||||
*
|
||||
* SetAllocationSize is used to truncate or extend a file.
|
||||
*
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param AllocSize File length to set.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *SetAllocationSize)(LPCWSTR FileName,
|
||||
LONGLONG AllocSize,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief LockFile Dokan API callback
|
||||
*
|
||||
* Lock file at a specific offset and data length.
|
||||
* This is only used if \ref DOKAN_OPTION_FILELOCK_USER_MODE is enabled.
|
||||
*
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param ByteOffset Offset from where the lock has to be proceed.
|
||||
* \param Length Data length to lock.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
* \see UnlockFile
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *LockFile)(LPCWSTR FileName,
|
||||
LONGLONG ByteOffset,
|
||||
LONGLONG Length,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief UnlockFile Dokan API callback
|
||||
*
|
||||
* Unlock file at a specific offset and data length.
|
||||
* This is only used if \ref DOKAN_OPTION_FILELOCK_USER_MODE is enabled.
|
||||
*
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param ByteOffset Offset from where the lock has to be proceed.
|
||||
* \param Length Data length to lock.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
* \see LockFile
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *UnlockFile)(LPCWSTR FileName,
|
||||
LONGLONG ByteOffset,
|
||||
LONGLONG Length,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief GetDiskFreeSpace Dokan API callback
|
||||
*
|
||||
* Retrieves information about the amount of space that is available on a disk volume, which is the total amount of space,
|
||||
* the total amount of free space, and the total amount of free space available to the user that is associated with the calling thread.
|
||||
*
|
||||
* Neither GetDiskFreeSpace nor \ref GetVolumeInformation
|
||||
* save the DOKAN_FILE_INFO.Context.
|
||||
* Before these methods are called, \ref ZwCreateFile may not be called.
|
||||
* (ditto \ref CloseFile and \ref Cleanup)
|
||||
*
|
||||
* \param FreeBytesAvailable Amount of available space.
|
||||
* \param TotalNumberOfBytes Total size of storage space
|
||||
* \param TotalNumberOfFreeBytes Amount of free space
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or \c NTSTATUS appropriate to the request result.
|
||||
* \see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa364937(v=vs.85).aspx"> GetDiskFreeSpaceEx function (MSDN)</a>
|
||||
* \see GetVolumeInformation
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *GetDiskFreeSpace)(PULONGLONG FreeBytesAvailable,
|
||||
PULONGLONG TotalNumberOfBytes,
|
||||
PULONGLONG TotalNumberOfFreeBytes,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief GetVolumeInformation Dokan API callback
|
||||
*
|
||||
* Retrieves information about the file system and volume associated with the specified root directory.
|
||||
*
|
||||
* Neither GetVolumeInformation nor GetDiskFreeSpace
|
||||
* save the \ref DOKAN_FILE_INFO#Context.
|
||||
* Before these methods are called, \ref ZwCreateFile may not be called.
|
||||
* (ditto \ref CloseFile and \ref Cleanup)
|
||||
*
|
||||
* \c FILE_READ_ONLY_VOLUME is automatically added to the
|
||||
* FileSystemFlags if \ref DOKAN_OPTION_WRITE_PROTECT was
|
||||
* specified in DOKAN_OPTIONS when the volume was mounted.
|
||||
*
|
||||
* \param VolumeNameBuffer A pointer to a buffer that receives the name of a specified volume.
|
||||
* \param VolumeNameSize The length of a volume name buffer.
|
||||
* \param VolumeSerialNumber A pointer to a variable that receives the volume serial number.
|
||||
* \param MaximumComponentLength A pointer to a variable that receives the maximum length.
|
||||
* \param FileSystemFlags A pointer to a variable that receives flags associated with the specified file system.
|
||||
* \param FileSystemNameBuffer A pointer to a buffer that receives the name of the file system.
|
||||
* \param FileSystemNameSize The length of the file system name buffer.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
* \see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx"> GetVolumeInformation function (MSDN)</a>
|
||||
* \see GetDiskFreeSpace
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *GetVolumeInformation)(LPWSTR VolumeNameBuffer,
|
||||
DWORD VolumeNameSize,
|
||||
LPDWORD VolumeSerialNumber,
|
||||
LPDWORD MaximumComponentLength,
|
||||
LPDWORD FileSystemFlags,
|
||||
LPWSTR FileSystemNameBuffer,
|
||||
DWORD FileSystemNameSize,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief Mounted Dokan API callback
|
||||
*
|
||||
* Is called when Dokan succeed to mount the volume.
|
||||
*
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
* \see Unmounted
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *Mounted)(PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief Unmounted Dokan API callback
|
||||
*
|
||||
* Is called when Dokan is unmounting the volume.
|
||||
*
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or \c NTSTATUS appropriate to the request result.
|
||||
* \see Unmounted
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *Unmounted)(PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief GetFileSecurity Dokan API callback
|
||||
*
|
||||
* Get specified information about the security of a file or directory.
|
||||
*
|
||||
* Return \c STATUS_BUFFER_OVERFLOW if buffer size is too small.
|
||||
*
|
||||
* \since Supported since version 0.6.0. You must specify the version in \ref DOKAN_OPTIONS.Version.
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param SecurityInformation A SECURITY_INFORMATION value that identifies the security information being requested.
|
||||
* \param SecurityDescriptor A pointer to a buffer that receives a copy of the security descriptor of the requested file.
|
||||
* \param BufferLength Specifies the size, in bytes, of the buffer.
|
||||
* \param LengthNeeded A pointer to the variable that receives the number of bytes necessary to store the complete security descriptor.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
* \see SetFileSecurity
|
||||
* \see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa446639(v=vs.85).aspx">GetFileSecurity function (MSDN)</a>
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *GetFileSecurity)(LPCWSTR FileName,
|
||||
PSECURITY_INFORMATION SecurityInformation,
|
||||
PSECURITY_DESCRIPTOR SecurityDescriptor,
|
||||
ULONG BufferLength,
|
||||
PULONG LengthNeeded,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief SetFileSecurity Dokan API callback
|
||||
*
|
||||
* Sets the security of a file or directory object.
|
||||
*
|
||||
* \since Supported since version 0.6.0. You must specify the version in \ref DOKAN_OPTIONS.Version.
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param SecurityInformation Structure that identifies the contents of the security descriptor pointed by \a SecurityDescriptor param.
|
||||
* \param SecurityDescriptor A pointer to a SECURITY_DESCRIPTOR structure.
|
||||
* \param BufferLength Specifies the size, in bytes, of the buffer.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
* \see GetFileSecurity
|
||||
* \see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa379577(v=vs.85).aspx">SetFileSecurity function (MSDN)</a>
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *SetFileSecurity)(LPCWSTR FileName,
|
||||
PSECURITY_INFORMATION SecurityInformation,
|
||||
PSECURITY_DESCRIPTOR SecurityDescriptor,
|
||||
ULONG BufferLength,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief FindStreams Dokan API callback
|
||||
*
|
||||
* Retrieve all NTFS Streams informations on the file.
|
||||
* This is only called if \ref DOKAN_OPTION_ALT_STREAM is enabled.
|
||||
*
|
||||
* \since Supported since version 0.8.0. You must specify the version in \ref DOKAN_OPTIONS.Version.
|
||||
* \param FileName File path requested by the Kernel on the FileSystem.
|
||||
* \param FillFindStreamData Callback that has to be called with PWIN32_FIND_STREAM_DATA that contain stream information.
|
||||
* \param DokanFileInfo Information about the file or directory.
|
||||
* \return \c STATUS_SUCCESS on success or NTSTATUS appropriate to the request result.
|
||||
*/
|
||||
NTSTATUS(DOKAN_CALLBACK *FindStreams)(LPCWSTR FileName,
|
||||
PFillFindStreamData FillFindStreamData,
|
||||
PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
} DOKAN_OPERATIONS, *PDOKAN_OPERATIONS;
|
||||
|
||||
// clang-format on
|
||||
|
||||
/**
|
||||
* \struct DOKAN_CONTROL
|
||||
* \brief Dokan Control
|
||||
*/
|
||||
typedef struct _DOKAN_CONTROL {
|
||||
/** File System Type */
|
||||
ULONG Type;
|
||||
/** Mount point. Can be "M:\" (drive letter) or "C:\mount\dokan" (path in NTFS) */
|
||||
WCHAR MountPoint[MAX_PATH];
|
||||
/** UNC name used for network volume */
|
||||
WCHAR UNCName[64];
|
||||
/** Disk Device Name */
|
||||
WCHAR DeviceName[64];
|
||||
/** Volume Device Object */
|
||||
PVOID DeviceObject;
|
||||
} DOKAN_CONTROL, *PDOKAN_CONTROL;
|
||||
|
||||
/**
|
||||
* \defgroup DokanMainResult DokanMainResult
|
||||
* \brief \ref DokanMain returns error codes
|
||||
*/
|
||||
/** @{ */
|
||||
|
||||
/** Dokan mount succeed. */
|
||||
#define DOKAN_SUCCESS 0
|
||||
/** Dokan mount error. */
|
||||
#define DOKAN_ERROR -1
|
||||
/** Dokan mount failed - Bad drive letter. */
|
||||
#define DOKAN_DRIVE_LETTER_ERROR -2
|
||||
/** Dokan mount failed - Can't install driver. */
|
||||
#define DOKAN_DRIVER_INSTALL_ERROR -3
|
||||
/** Dokan mount failed - Driver answer that something is wrong. */
|
||||
#define DOKAN_START_ERROR -4
|
||||
/**
|
||||
* Dokan mount failed.
|
||||
* Can't assign a drive letter or mount point.
|
||||
* Probably already used by another volume.
|
||||
*/
|
||||
#define DOKAN_MOUNT_ERROR -5
|
||||
/**
|
||||
* Dokan mount failed.
|
||||
* Mount point is invalid.
|
||||
*/
|
||||
#define DOKAN_MOUNT_POINT_ERROR -6
|
||||
/**
|
||||
* Dokan mount failed.
|
||||
* Requested an incompatible version.
|
||||
*/
|
||||
#define DOKAN_VERSION_ERROR -7
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* \defgroup Dokan Dokan
|
||||
*/
|
||||
/** @{ */
|
||||
|
||||
/**
|
||||
* \brief Mount a new Dokan Volume.
|
||||
*
|
||||
* This function block until the device is unmount.
|
||||
* If the mount fail, it will directly return \ref DokanMainResult error.
|
||||
*
|
||||
* \param DokanOptions a \ref DOKAN_OPTIONS that describe the mount.
|
||||
* \param DokanOperations Instance of \ref DOKAN_OPERATIONS that will be called for each request made by the kernel.
|
||||
* \return \ref DokanMainResult status.
|
||||
*/
|
||||
int DOKANAPI DokanMain(PDOKAN_OPTIONS DokanOptions,
|
||||
PDOKAN_OPERATIONS DokanOperations);
|
||||
|
||||
/**
|
||||
* \brief Unmount a dokan device from a driver letter.
|
||||
*
|
||||
* \param DriveLetter Dokan driver letter to unmount.
|
||||
* \return \c TRUE if device was unmount or False in case of failure or device not found.
|
||||
*/
|
||||
BOOL DOKANAPI DokanUnmount(WCHAR DriveLetter);
|
||||
|
||||
/**
|
||||
* \brief Unmount a dokan device from a mount point
|
||||
*
|
||||
* \param MountPoint Mount point to unmount ("Z", "Z:", "Z:\", "Z:\MyMountPoint").
|
||||
* \return \c TRUE if device was unmount or False in case of failure or device not found.
|
||||
*/
|
||||
BOOL DOKANAPI DokanRemoveMountPoint(LPCWSTR MountPoint);
|
||||
|
||||
/**
|
||||
* \brief Unmount a dokan device from a mount point
|
||||
*
|
||||
* Same as \ref DokanRemoveMountPoint
|
||||
* If Safe is \c TRUE, will broadcast to all desktop and Shell
|
||||
* Safe should not be used during DLL_PROCESS_DETACH
|
||||
*
|
||||
* \see DokanRemoveMountPoint
|
||||
*
|
||||
* \param MountPoint Mount point to unmount ("Z", "Z:", "Z:\", "Z:\MyMountPoint").
|
||||
* \param Safe Process is not in DLL_PROCESS_DETACH state.
|
||||
* \return True if device was unmount or False in case of failure or device not found.
|
||||
*/
|
||||
BOOL DOKANAPI DokanRemoveMountPointEx(LPCWSTR MountPoint, BOOL Safe);
|
||||
|
||||
/**
|
||||
* \brief Checks whether Name can match Expression
|
||||
*
|
||||
* \param Expression Expression can contain wildcard characters (? and *)
|
||||
* \param Name Name to check
|
||||
* \param IgnoreCase Case sensitive or not
|
||||
* \return result if name match the expression
|
||||
*/
|
||||
BOOL DOKANAPI DokanIsNameInExpression(LPCWSTR Expression, LPCWSTR Name,
|
||||
BOOL IgnoreCase);
|
||||
|
||||
/**
|
||||
* \brief Get the version of Dokan.
|
||||
* The returned ULONG is the version number without the dots.
|
||||
* \return The version of Dokan
|
||||
*/
|
||||
ULONG DOKANAPI DokanVersion();
|
||||
|
||||
/**
|
||||
* \brief Get the version of the Dokan driver.
|
||||
* The returned ULONG is the version number without the dots.
|
||||
* \return The version of Dokan driver.
|
||||
*/
|
||||
ULONG DOKANAPI DokanDriverVersion();
|
||||
|
||||
/**
|
||||
* \brief Extends the time out of the current IO operation in driver.
|
||||
*
|
||||
* \param Timeout Extended time in milliseconds requested.
|
||||
* \param DokanFileInfo \ref DOKAN_FILE_INFO of the operation to extend.
|
||||
* \return If the operation was successful.
|
||||
*/
|
||||
BOOL DOKANAPI DokanResetTimeout(ULONG Timeout, PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief Get the handle to Access Token.
|
||||
*
|
||||
* This method needs be called in <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx">CreateFile</a> callback.
|
||||
* The caller must call <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx">CloseHandle</a>
|
||||
* for the returned handle.
|
||||
*
|
||||
* \param DokanFileInfo \ref DOKAN_FILE_INFO of the operation to extend.
|
||||
* \return A handle to the account token for the user on whose behalf the code is running.
|
||||
*/
|
||||
HANDLE DOKANAPI DokanOpenRequestorToken(PDOKAN_FILE_INFO DokanFileInfo);
|
||||
|
||||
/**
|
||||
* \brief Get active Dokan mount points.
|
||||
*
|
||||
* \param list Allocate array of DOKAN_CONTROL.
|
||||
* \param length Number of \ref DOKAN_CONTROL instance in list.
|
||||
* \param uncOnly Get only instances that have UNC Name.
|
||||
* \param nbRead Number of instances successfully retrieved.
|
||||
* \return List retrieved or not.
|
||||
*/
|
||||
BOOL DOKANAPI DokanGetMountPointList(PDOKAN_CONTROL list, ULONG length,
|
||||
BOOL uncOnly, PULONG nbRead);
|
||||
|
||||
/**
|
||||
* \brief Convert \ref DOKAN_OPERATIONS.ZwCreateFile parameters to <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx">CreateFile</a> parameters.
|
||||
*
|
||||
* \param FileAttributes FileAttributes from \ref DOKAN_OPERATIONS.ZwCreateFile.
|
||||
* \param CreateOptions CreateOptions from \ref DOKAN_OPERATIONS.ZwCreateFile.
|
||||
* \param CreateDisposition CreateDisposition from \ref DOKAN_OPERATIONS.ZwCreateFile.
|
||||
* \param outFileAttributesAndFlags New <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx">CreateFile</a> dwFlagsAndAttributes.
|
||||
* \param outCreationDisposition New <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx">CreateFile</a> dwCreationDisposition.
|
||||
* \see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx">CreateFile function (MSDN)</a>
|
||||
*/
|
||||
void DOKANAPI DokanMapKernelToUserCreateFileFlags(
|
||||
ULONG FileAttributes, ULONG CreateOptions, ULONG CreateDisposition,
|
||||
DWORD *outFileAttributesAndFlags, DWORD *outCreationDisposition);
|
||||
|
||||
/**
|
||||
* \brief Convert IRP_MJ_CREATE DesiredAccess to generic rights.
|
||||
*
|
||||
* \param DesiredAccess Standard rights to convert
|
||||
* \return New DesiredAccess with generic rights.
|
||||
* \see <a href="https://msdn.microsoft.com/windows/hardware/drivers/ifs/access-mask">Access Mask (MSDN)</a>
|
||||
*/
|
||||
ACCESS_MASK DOKANAPI DokanMapStandardToGenericAccess(ACCESS_MASK DesiredAccess);
|
||||
|
||||
/**
|
||||
* \brief Convert WIN32 error to NTSTATUS
|
||||
*
|
||||
* https://support.microsoft.com/en-us/kb/113996
|
||||
*
|
||||
* \param Error Win32 Error to convert
|
||||
* \return NTSTATUS associate to the ERROR.
|
||||
*/
|
||||
NTSTATUS DOKANAPI DokanNtStatusFromWin32(DWORD Error);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // DOKAN_H_
|
1236
3rd_party/Dokan Library-1.0.2/include/dokan/fileinfo.h
vendored
Normal file
1236
3rd_party/Dokan Library-1.0.2/include/dokan/fileinfo.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
372
3rd_party/Dokan Library-1.0.2/include/dokan/public.h
vendored
Normal file
372
3rd_party/Dokan Library-1.0.2/include/dokan/public.h
vendored
Normal file
@@ -0,0 +1,372 @@
|
||||
/*
|
||||
Dokan : user-mode file system library for Windows
|
||||
|
||||
Copyright (C) 2015 - 2017 Adrien J. <liryna.stark@gmail.com> and Maxime C. <maxime@islog.com>
|
||||
Copyright (C) 2007 - 2011 Hiroki Asakawa <info@dokan-dev.net>
|
||||
|
||||
http://dokan-dev.github.io
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation; either version 3 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PUBLIC_H_
|
||||
#define PUBLIC_H_
|
||||
|
||||
#ifndef DOKAN_MAJOR_API_VERSION
|
||||
#define DOKAN_MAJOR_API_VERSION L"1"
|
||||
#endif
|
||||
|
||||
#define DOKAN_DRIVER_VERSION 0x0000190
|
||||
|
||||
#define EVENT_CONTEXT_MAX_SIZE (1024 * 32)
|
||||
|
||||
#define IOCTL_TEST \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define IOCTL_SET_DEBUG_MODE \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x801, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define IOCTL_EVENT_WAIT \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x802, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define IOCTL_EVENT_INFO \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x803, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define IOCTL_EVENT_RELEASE \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x804, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define IOCTL_EVENT_START \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x805, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define IOCTL_EVENT_WRITE \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x806, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
|
||||
|
||||
#define IOCTL_KEEPALIVE \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x809, METHOD_NEITHER, FILE_ANY_ACCESS)
|
||||
|
||||
#define IOCTL_SERVICE_WAIT \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x80A, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define IOCTL_RESET_TIMEOUT \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x80B, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define IOCTL_GET_ACCESS_TOKEN \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x80C, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define IOCTL_EVENT_MOUNTPOINT_LIST \
|
||||
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x80D, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define DRIVER_FUNC_INSTALL 0x01
|
||||
#define DRIVER_FUNC_REMOVE 0x02
|
||||
|
||||
#define DOKAN_MOUNTED 1
|
||||
#define DOKAN_USED 2
|
||||
#define DOKAN_START_FAILED 3
|
||||
|
||||
#define DOKAN_DEVICE_MAX 10
|
||||
|
||||
#define DOKAN_DEFAULT_SECTOR_SIZE 512
|
||||
#define DOKAN_DEFAULT_ALLOCATION_UNIT_SIZE 512
|
||||
#define DOKAN_DEFAULT_DISK_SIZE 1024 * 1024 * 1024
|
||||
|
||||
// used in CCB->Flags and FCB->Flags
|
||||
#define DOKAN_FILE_DIRECTORY 1
|
||||
#define DOKAN_FILE_DELETED 2
|
||||
#define DOKAN_FILE_OPENED 4
|
||||
#define DOKAN_DIR_MATCH_ALL 8
|
||||
#define DOKAN_DELETE_ON_CLOSE 16
|
||||
#define DOKAN_PAGING_IO 32
|
||||
#define DOKAN_SYNCHRONOUS_IO 64
|
||||
#define DOKAN_WRITE_TO_END_OF_FILE 128
|
||||
#define DOKAN_NOCACHE 256
|
||||
|
||||
// used in DOKAN_START->DeviceType
|
||||
#define DOKAN_DISK_FILE_SYSTEM 0
|
||||
#define DOKAN_NETWORK_FILE_SYSTEM 1
|
||||
|
||||
/*
|
||||
* This structure is used for copying UNICODE_STRING from the kernel mode driver
|
||||
* into the user mode driver.
|
||||
* https://msdn.microsoft.com/en-us/library/windows/hardware/ff564879(v=vs.85).aspx
|
||||
*/
|
||||
typedef struct _DOKAN_UNICODE_STRING_INTERMEDIATE {
|
||||
USHORT Length;
|
||||
USHORT MaximumLength;
|
||||
WCHAR Buffer[1];
|
||||
} DOKAN_UNICODE_STRING_INTERMEDIATE, *PDOKAN_UNICODE_STRING_INTERMEDIATE;
|
||||
|
||||
/*
|
||||
* This structure is used for copying ACCESS_STATE from the kernel mode driver
|
||||
* into the user mode driver.
|
||||
* https://msdn.microsoft.com/en-us/library/windows/hardware/ff538840(v=vs.85).aspx
|
||||
*/
|
||||
typedef struct _DOKAN_ACCESS_STATE_INTERMEDIATE {
|
||||
BOOLEAN SecurityEvaluated;
|
||||
BOOLEAN GenerateAudit;
|
||||
BOOLEAN GenerateOnClose;
|
||||
BOOLEAN AuditPrivileges;
|
||||
ULONG Flags;
|
||||
ACCESS_MASK RemainingDesiredAccess;
|
||||
ACCESS_MASK PreviouslyGrantedAccess;
|
||||
ACCESS_MASK OriginalDesiredAccess;
|
||||
|
||||
// Offset from the beginning of this structure to a SECURITY_DESCRIPTOR
|
||||
// if 0 that means there is no security descriptor
|
||||
ULONG SecurityDescriptorOffset;
|
||||
|
||||
// Offset from the beginning of this structure to a
|
||||
// DOKAN_UNICODE_STRING_INTERMEDIATE
|
||||
ULONG UnicodeStringObjectNameOffset;
|
||||
|
||||
// Offset from the beginning of this structure to a
|
||||
// DOKAN_UNICODE_STRING_INTERMEDIATE
|
||||
ULONG UnicodeStringObjectTypeOffset;
|
||||
} DOKAN_ACCESS_STATE_INTERMEDIATE, *PDOKAN_ACCESS_STATE_INTERMEDIATE;
|
||||
|
||||
typedef struct _DOKAN_ACCESS_STATE {
|
||||
BOOLEAN SecurityEvaluated;
|
||||
BOOLEAN GenerateAudit;
|
||||
BOOLEAN GenerateOnClose;
|
||||
BOOLEAN AuditPrivileges;
|
||||
ULONG Flags;
|
||||
ACCESS_MASK RemainingDesiredAccess;
|
||||
ACCESS_MASK PreviouslyGrantedAccess;
|
||||
ACCESS_MASK OriginalDesiredAccess;
|
||||
PSECURITY_DESCRIPTOR SecurityDescriptor;
|
||||
UNICODE_STRING ObjectName;
|
||||
UNICODE_STRING ObjectType;
|
||||
} DOKAN_ACCESS_STATE, *PDOKAN_ACCESS_STATE;
|
||||
|
||||
/*
|
||||
* This structure is used for copying IO_SECURITY_CONTEXT from the kernel mode
|
||||
* driver into the user mode driver.
|
||||
* https://msdn.microsoft.com/en-us/library/windows/hardware/ff550613(v=vs.85).aspx
|
||||
*/
|
||||
typedef struct _DOKAN_IO_SECURITY_CONTEXT_INTERMEDIATE {
|
||||
DOKAN_ACCESS_STATE_INTERMEDIATE AccessState;
|
||||
ACCESS_MASK DesiredAccess;
|
||||
} DOKAN_IO_SECURITY_CONTEXT_INTERMEDIATE,
|
||||
*PDOKAN_IO_SECURITY_CONTEXT_INTERMEDIATE;
|
||||
|
||||
typedef struct _DOKAN_IO_SECURITY_CONTEXT {
|
||||
DOKAN_ACCESS_STATE AccessState;
|
||||
ACCESS_MASK DesiredAccess;
|
||||
} DOKAN_IO_SECURITY_CONTEXT, *PDOKAN_IO_SECURITY_CONTEXT;
|
||||
|
||||
typedef struct _CREATE_CONTEXT {
|
||||
DOKAN_IO_SECURITY_CONTEXT_INTERMEDIATE SecurityContext;
|
||||
ULONG FileAttributes;
|
||||
ULONG CreateOptions;
|
||||
ULONG ShareAccess;
|
||||
ULONG FileNameLength;
|
||||
|
||||
// Offset from the beginning of this structure to the string
|
||||
ULONG FileNameOffset;
|
||||
} CREATE_CONTEXT, *PCREATE_CONTEXT;
|
||||
|
||||
typedef struct _CLEANUP_CONTEXT {
|
||||
ULONG FileNameLength;
|
||||
WCHAR FileName[1];
|
||||
|
||||
} CLEANUP_CONTEXT, *PCLEANUP_CONTEXT;
|
||||
|
||||
typedef struct _CLOSE_CONTEXT {
|
||||
ULONG FileNameLength;
|
||||
WCHAR FileName[1];
|
||||
|
||||
} CLOSE_CONTEXT, *PCLOSE_CONTEXT;
|
||||
|
||||
typedef struct _DIRECTORY_CONTEXT {
|
||||
ULONG FileInformationClass;
|
||||
ULONG FileIndex;
|
||||
ULONG BufferLength;
|
||||
ULONG DirectoryNameLength;
|
||||
ULONG SearchPatternLength;
|
||||
ULONG SearchPatternOffset;
|
||||
WCHAR DirectoryName[1];
|
||||
WCHAR SearchPatternBase[1];
|
||||
|
||||
} DIRECTORY_CONTEXT, *PDIRECTORY_CONTEXT;
|
||||
|
||||
typedef struct _READ_CONTEXT {
|
||||
LARGE_INTEGER ByteOffset;
|
||||
ULONG BufferLength;
|
||||
ULONG FileNameLength;
|
||||
WCHAR FileName[1];
|
||||
} READ_CONTEXT, *PREAD_CONTEXT;
|
||||
|
||||
typedef struct _WRITE_CONTEXT {
|
||||
LARGE_INTEGER ByteOffset;
|
||||
ULONG BufferLength;
|
||||
ULONG BufferOffset;
|
||||
ULONG RequestLength;
|
||||
ULONG FileNameLength;
|
||||
WCHAR FileName[2];
|
||||
// "2" means to keep last null of contents to write
|
||||
} WRITE_CONTEXT, *PWRITE_CONTEXT;
|
||||
|
||||
typedef struct _FILEINFO_CONTEXT {
|
||||
ULONG FileInformationClass;
|
||||
ULONG BufferLength;
|
||||
ULONG FileNameLength;
|
||||
WCHAR FileName[1];
|
||||
} FILEINFO_CONTEXT, *PFILEINFO_CONTEXT;
|
||||
|
||||
typedef struct _SETFILE_CONTEXT {
|
||||
ULONG FileInformationClass;
|
||||
ULONG BufferLength;
|
||||
ULONG BufferOffset;
|
||||
ULONG FileNameLength;
|
||||
WCHAR FileName[1];
|
||||
} SETFILE_CONTEXT, *PSETFILE_CONTEXT;
|
||||
|
||||
typedef struct _VOLUME_CONTEXT {
|
||||
ULONG FsInformationClass;
|
||||
ULONG BufferLength;
|
||||
} VOLUME_CONTEXT, *PVOLUME_CONTEXT;
|
||||
|
||||
typedef struct _LOCK_CONTEXT {
|
||||
LARGE_INTEGER ByteOffset;
|
||||
LARGE_INTEGER Length;
|
||||
ULONG Key;
|
||||
ULONG FileNameLength;
|
||||
WCHAR FileName[1];
|
||||
} LOCK_CONTEXT, *PLOCK_CONTEXT;
|
||||
|
||||
typedef struct _FLUSH_CONTEXT {
|
||||
ULONG FileNameLength;
|
||||
WCHAR FileName[1];
|
||||
} FLUSH_CONTEXT, *PFLUSH_CONTEXT;
|
||||
|
||||
typedef struct _UNMOUNT_CONTEXT {
|
||||
WCHAR DeviceName[64];
|
||||
ULONG Option;
|
||||
} UNMOUNT_CONTEXT, *PUNMOUNT_CONTEXT;
|
||||
|
||||
typedef struct _SECURITY_CONTEXT {
|
||||
SECURITY_INFORMATION SecurityInformation;
|
||||
ULONG BufferLength;
|
||||
ULONG FileNameLength;
|
||||
WCHAR FileName[1];
|
||||
} SECURITY_CONTEXT, *PSECURITY_CONTEXT;
|
||||
|
||||
typedef struct _SET_SECURITY_CONTEXT {
|
||||
SECURITY_INFORMATION SecurityInformation;
|
||||
ULONG BufferLength;
|
||||
ULONG BufferOffset;
|
||||
ULONG FileNameLength;
|
||||
WCHAR FileName[1];
|
||||
} SET_SECURITY_CONTEXT, *PSET_SECURITY_CONTEXT;
|
||||
|
||||
typedef struct _EVENT_CONTEXT {
|
||||
ULONG Length;
|
||||
ULONG MountId;
|
||||
ULONG SerialNumber;
|
||||
ULONG ProcessId;
|
||||
UCHAR MajorFunction;
|
||||
UCHAR MinorFunction;
|
||||
ULONG Flags;
|
||||
ULONG FileFlags;
|
||||
ULONG64 Context;
|
||||
union {
|
||||
DIRECTORY_CONTEXT Directory;
|
||||
READ_CONTEXT Read;
|
||||
WRITE_CONTEXT Write;
|
||||
FILEINFO_CONTEXT File;
|
||||
CREATE_CONTEXT Create;
|
||||
CLOSE_CONTEXT Close;
|
||||
SETFILE_CONTEXT SetFile;
|
||||
CLEANUP_CONTEXT Cleanup;
|
||||
LOCK_CONTEXT Lock;
|
||||
VOLUME_CONTEXT Volume;
|
||||
FLUSH_CONTEXT Flush;
|
||||
UNMOUNT_CONTEXT Unmount;
|
||||
SECURITY_CONTEXT Security;
|
||||
SET_SECURITY_CONTEXT SetSecurity;
|
||||
} Operation;
|
||||
} EVENT_CONTEXT, *PEVENT_CONTEXT;
|
||||
|
||||
#define WRITE_MAX_SIZE \
|
||||
(EVENT_CONTEXT_MAX_SIZE - sizeof(EVENT_CONTEXT) - 256 * sizeof(WCHAR))
|
||||
|
||||
typedef struct _EVENT_INFORMATION {
|
||||
ULONG SerialNumber;
|
||||
NTSTATUS Status;
|
||||
ULONG Flags;
|
||||
union {
|
||||
struct {
|
||||
ULONG Index;
|
||||
} Directory;
|
||||
struct {
|
||||
ULONG Flags;
|
||||
ULONG Information;
|
||||
} Create;
|
||||
struct {
|
||||
LARGE_INTEGER CurrentByteOffset;
|
||||
} Read;
|
||||
struct {
|
||||
LARGE_INTEGER CurrentByteOffset;
|
||||
} Write;
|
||||
struct {
|
||||
UCHAR DeleteOnClose;
|
||||
} Delete;
|
||||
struct {
|
||||
ULONG Timeout;
|
||||
} ResetTimeout;
|
||||
struct {
|
||||
HANDLE Handle;
|
||||
} AccessToken;
|
||||
} Operation;
|
||||
ULONG64 Context;
|
||||
ULONG BufferLength;
|
||||
UCHAR Buffer[8];
|
||||
|
||||
} EVENT_INFORMATION, *PEVENT_INFORMATION;
|
||||
|
||||
#define DOKAN_EVENT_ALTERNATIVE_STREAM_ON 1
|
||||
#define DOKAN_EVENT_WRITE_PROTECT 2
|
||||
#define DOKAN_EVENT_REMOVABLE 4
|
||||
#define DOKAN_EVENT_MOUNT_MANAGER 8
|
||||
#define DOKAN_EVENT_CURRENT_SESSION 16
|
||||
#define DOKAN_EVENT_FILELOCK_USER_MODE 32
|
||||
|
||||
typedef struct _EVENT_DRIVER_INFO {
|
||||
ULONG DriverVersion;
|
||||
ULONG Status;
|
||||
ULONG DeviceNumber;
|
||||
ULONG MountId;
|
||||
WCHAR DeviceName[64];
|
||||
} EVENT_DRIVER_INFO, *PEVENT_DRIVER_INFO;
|
||||
|
||||
typedef struct _EVENT_START {
|
||||
ULONG UserVersion;
|
||||
ULONG DeviceType;
|
||||
ULONG Flags;
|
||||
WCHAR MountPoint[260];
|
||||
WCHAR UNCName[64];
|
||||
ULONG IrpTimeout;
|
||||
} EVENT_START, *PEVENT_START;
|
||||
|
||||
typedef struct _DOKAN_RENAME_INFORMATION {
|
||||
BOOLEAN ReplaceIfExists;
|
||||
ULONG FileNameLength;
|
||||
WCHAR FileName[1];
|
||||
} DOKAN_RENAME_INFORMATION, *PDOKAN_RENAME_INFORMATION;
|
||||
|
||||
typedef struct _DOKAN_LINK_INFORMATION {
|
||||
BOOLEAN ReplaceIfExists;
|
||||
ULONG FileNameLength;
|
||||
WCHAR FileName[1];
|
||||
} DOKAN_LINK_INFORMATION, *PDOKAN_LINK_INFORMATION;
|
||||
|
||||
#endif // PUBLIC_H_
|
9
3rd_party/Dokan Library-1.0.2/include/fuse.h
vendored
Normal file
9
3rd_party/Dokan Library-1.0.2/include/fuse.h
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
This header is for compatibility with older software using FUSE.
|
||||
|
||||
Please use 'pkg-config --cflags fuse' to set include path. The
|
||||
correct usage is still '#include <fuse.h>', not '#include
|
||||
<fuse/fuse.h>'.
|
||||
*/
|
||||
|
||||
#include "fuse/fuse.h"
|
853
3rd_party/Dokan Library-1.0.2/include/fuse/fuse.h
vendored
Normal file
853
3rd_party/Dokan Library-1.0.2/include/fuse/fuse.h
vendored
Normal file
@@ -0,0 +1,853 @@
|
||||
/*
|
||||
FUSE: Filesystem in Userspace
|
||||
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
|
||||
|
||||
This program can be distributed under the terms of the GNU LGPLv2.
|
||||
See the file COPYING.LIB.
|
||||
*/
|
||||
|
||||
#ifndef FUSE_H_
|
||||
#define FUSE_H_
|
||||
|
||||
/* Include Windows compatibility stuff early*/
|
||||
#ifdef _WIN32
|
||||
#include "fuse_win.h"
|
||||
typedef struct _FILETIME FILETIME;
|
||||
#else
|
||||
#define FUSE_OFF_T off_t
|
||||
#define FUSE_STAT stat
|
||||
#endif
|
||||
|
||||
/* Add semaphore fix for Cygwin. TODO: think of a better workaround? */
|
||||
#ifdef __CYGWIN__
|
||||
#ifndef NO_CYGWIN_SEM_FIX
|
||||
#include "fuse_sem_fix.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** @file
|
||||
*
|
||||
* This file defines the library interface of FUSE
|
||||
*
|
||||
* IMPORTANT: you should define FUSE_USE_VERSION before including this
|
||||
* header. To use the newest API define it to 26 (recommended for any
|
||||
* new application), to use the old API define it to 21 (default) 22
|
||||
* or 25, to use the even older 1.X API define it to 11.
|
||||
* NOTE: Windows port always uses the latest FUSE version.
|
||||
*/
|
||||
|
||||
#ifndef FUSE_USE_VERSION
|
||||
#define FUSE_USE_VERSION 27
|
||||
#endif
|
||||
|
||||
#include "fuse_common.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if defined(__CYGWIN__) || defined(__MINGW32__)
|
||||
|
||||
#include <utime.h>
|
||||
#endif
|
||||
#if defined(__CYGWIN__)
|
||||
#include <sys/statvfs.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* ----------------------------------------------------------- *
|
||||
* Basic FUSE API *
|
||||
* ----------------------------------------------------------- */
|
||||
|
||||
/** Handle for a FUSE filesystem */
|
||||
struct fuse;
|
||||
|
||||
/** Structure containing a raw command */
|
||||
struct fuse_cmd;
|
||||
|
||||
/** Function to add an entry in a readdir() operation
|
||||
*
|
||||
* @param buf the buffer passed to the readdir() operation
|
||||
* @param name the file name of the directory entry
|
||||
* @param stbuf file attributes, can be NULL
|
||||
* @param off offset of the next entry or zero
|
||||
* @return 1 if buffer is full, zero otherwise
|
||||
*/
|
||||
typedef int (*fuse_fill_dir_t) (void *buf, const char *name,
|
||||
const struct FUSE_STAT *stbuf, FUSE_OFF_T off);
|
||||
|
||||
/* Used by deprecated getdir() method */
|
||||
typedef struct fuse_dirhandle *fuse_dirh_t;
|
||||
typedef int (*fuse_dirfil_t) (fuse_dirh_t h, const char *name, int type,
|
||||
ino_t ino);
|
||||
|
||||
/**
|
||||
* The file system operations:
|
||||
*
|
||||
* Most of these should work very similarly to the well known UNIX
|
||||
* file system operations.
|
||||
*
|
||||
* All methods are optional, but some are essential for a useful
|
||||
* filesystem (e.g. getattr). Open, flush, release, fsync, opendir,
|
||||
* releasedir, fsyncdir, access, create, ftruncate, fgetattr, lock,
|
||||
* init and destroy are special purpose methods, without which a full
|
||||
* featured filesystem can still be implemented.
|
||||
*/
|
||||
struct fuse_operations {
|
||||
/** Get file attributes.
|
||||
*
|
||||
* Similar to stat(). The 'st_dev' and 'st_blksize' fields are
|
||||
* ignored. The 'st_ino' field is ignored except if the 'use_ino'
|
||||
* mount option is given.
|
||||
*/
|
||||
int (*getattr) (const char *, struct FUSE_STAT *);
|
||||
|
||||
/** Read the target of a symbolic link
|
||||
*
|
||||
* The buffer should be filled with a null terminated string. The
|
||||
* buffer size argument includes the space for the terminating
|
||||
* null character. If the linkname is too long to fit in the
|
||||
* buffer, it should be truncated. The return value should be 0
|
||||
* for success.
|
||||
*/
|
||||
int (*readlink) (const char *, char *, size_t);
|
||||
|
||||
/* Deprecated, use readdir() instead */
|
||||
int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
|
||||
|
||||
/** Create a file node
|
||||
*
|
||||
* This is called for creation of all non-directory, non-symlink
|
||||
* nodes. If the filesystem defines a create() method, then for
|
||||
* regular files that will be called instead.
|
||||
*/
|
||||
int (*mknod) (const char *, mode_t, dev_t);
|
||||
|
||||
/** Create a directory */
|
||||
int (*mkdir) (const char *, mode_t);
|
||||
|
||||
/** Remove a file */
|
||||
int (*unlink) (const char *);
|
||||
|
||||
/** Remove a directory */
|
||||
int (*rmdir) (const char *);
|
||||
|
||||
/** Create a symbolic link */
|
||||
int (*symlink) (const char *, const char *);
|
||||
|
||||
/** Rename a file */
|
||||
int (*rename) (const char *, const char *);
|
||||
|
||||
/** Create a hard link to a file */
|
||||
int (*link) (const char *, const char *);
|
||||
|
||||
/** Change the permission bits of a file */
|
||||
int (*chmod) (const char *, mode_t);
|
||||
|
||||
/** Change the owner and group of a file */
|
||||
int (*chown) (const char *, uid_t, gid_t);
|
||||
|
||||
/** Change the size of a file */
|
||||
int (*truncate) (const char *, FUSE_OFF_T);
|
||||
|
||||
/** Change the access and/or modification times of a file
|
||||
*
|
||||
* Deprecated, use utimens() instead.
|
||||
*/
|
||||
int (*utime) (const char *, struct utimbuf *);
|
||||
|
||||
/** File open operation
|
||||
*
|
||||
* No creation, or truncation flags (O_CREAT, O_EXCL, O_TRUNC)
|
||||
* will be passed to open(). Open should check if the operation
|
||||
* is permitted for the given flags. Optionally open may also
|
||||
* return an arbitrary filehandle in the fuse_file_info structure,
|
||||
* which will be passed to all file operations.
|
||||
*
|
||||
* Changed in version 2.2
|
||||
*/
|
||||
int (*open) (const char *, struct fuse_file_info *);
|
||||
|
||||
/** Read data from an open file
|
||||
*
|
||||
* Read should return exactly the number of bytes requested except
|
||||
* on EOF or error, otherwise the rest of the data will be
|
||||
* substituted with zeroes. An exception to this is when the
|
||||
* 'direct_io' mount option is specified, in which case the return
|
||||
* value of the read system call will reflect the return value of
|
||||
* this operation.
|
||||
*
|
||||
* Changed in version 2.2
|
||||
*/
|
||||
int (*read) (const char *, char *, size_t, FUSE_OFF_T,
|
||||
struct fuse_file_info *);
|
||||
|
||||
/** Write data to an open file
|
||||
*
|
||||
* Write should return exactly the number of bytes requested
|
||||
* except on error. An exception to this is when the 'direct_io'
|
||||
* mount option is specified (see read operation).
|
||||
*
|
||||
* Changed in version 2.2
|
||||
*/
|
||||
int (*write) (const char *, const char *, size_t, FUSE_OFF_T,
|
||||
struct fuse_file_info *);
|
||||
|
||||
/** Get file system statistics
|
||||
*
|
||||
* The 'f_frsize', 'f_favail', 'f_fsid' and 'f_flag' fields are ignored
|
||||
*
|
||||
* Replaced 'struct statfs' parameter with 'struct statvfs' in
|
||||
* version 2.5
|
||||
*/
|
||||
int (*statfs) (const char *, struct statvfs *);
|
||||
|
||||
/** Possibly flush cached data
|
||||
*
|
||||
* BIG NOTE: This is not equivalent to fsync(). It's not a
|
||||
* request to sync dirty data.
|
||||
*
|
||||
* Flush is called on each close() of a file descriptor. So if a
|
||||
* filesystem wants to return write errors in close() and the file
|
||||
* has cached dirty data, this is a good place to write back data
|
||||
* and return any errors. Since many applications ignore close()
|
||||
* errors this is not always useful.
|
||||
*
|
||||
* NOTE: The flush() method may be called more than once for each
|
||||
* open(). This happens if more than one file descriptor refers
|
||||
* to an opened file due to dup(), dup2() or fork() calls. It is
|
||||
* not possible to determine if a flush is final, so each flush
|
||||
* should be treated equally. Multiple write-flush sequences are
|
||||
* relatively rare, so this shouldn't be a problem.
|
||||
*
|
||||
* Filesystems shouldn't assume that flush will always be called
|
||||
* after some writes, or that if will be called at all.
|
||||
*
|
||||
* Changed in version 2.2
|
||||
*/
|
||||
int (*flush) (const char *, struct fuse_file_info *);
|
||||
|
||||
/** Release an open file
|
||||
*
|
||||
* Release is called when there are no more references to an open
|
||||
* file: all file descriptors are closed and all memory mappings
|
||||
* are unmapped.
|
||||
*
|
||||
* For every open() call there will be exactly one release() call
|
||||
* with the same flags and file descriptor. It is possible to
|
||||
* have a file opened more than once, in which case only the last
|
||||
* release will mean, that no more reads/writes will happen on the
|
||||
* file. The return value of release is ignored.
|
||||
*
|
||||
* Changed in version 2.2
|
||||
*/
|
||||
int (*release) (const char *, struct fuse_file_info *);
|
||||
|
||||
/** Synchronize file contents
|
||||
*
|
||||
* If the datasync parameter is non-zero, then only the user data
|
||||
* should be flushed, not the meta data.
|
||||
*
|
||||
* Changed in version 2.2
|
||||
*/
|
||||
int (*fsync) (const char *, int, struct fuse_file_info *);
|
||||
|
||||
/** Set extended attributes */
|
||||
int (*setxattr) (const char *, const char *, const char *, size_t, int);
|
||||
|
||||
/** Get extended attributes */
|
||||
int (*getxattr) (const char *, const char *, char *, size_t);
|
||||
|
||||
/** List extended attributes */
|
||||
int (*listxattr) (const char *, char *, size_t);
|
||||
|
||||
/** Remove extended attributes */
|
||||
int (*removexattr) (const char *, const char *);
|
||||
|
||||
/** Open directory
|
||||
*
|
||||
* This method should check if the open operation is permitted for
|
||||
* this directory
|
||||
*
|
||||
* Introduced in version 2.3
|
||||
*/
|
||||
int (*opendir) (const char *, struct fuse_file_info *);
|
||||
|
||||
/** Read directory
|
||||
*
|
||||
* This supersedes the old getdir() interface. New applications
|
||||
* should use this.
|
||||
*
|
||||
* The filesystem may choose between two modes of operation:
|
||||
*
|
||||
* 1) The readdir implementation ignores the offset parameter, and
|
||||
* passes zero to the filler function's offset. The filler
|
||||
* function will not return '1' (unless an error happens), so the
|
||||
* whole directory is read in a single readdir operation. This
|
||||
* works just like the old getdir() method.
|
||||
*
|
||||
* 2) The readdir implementation keeps track of the offsets of the
|
||||
* directory entries. It uses the offset parameter and always
|
||||
* passes non-zero offset to the filler function. When the buffer
|
||||
* is full (or an error happens) the filler function will return
|
||||
* '1'.
|
||||
*
|
||||
* Introduced in version 2.3
|
||||
*/
|
||||
int (*readdir) (const char *, void *, fuse_fill_dir_t, FUSE_OFF_T,
|
||||
struct fuse_file_info *);
|
||||
|
||||
/** Release directory
|
||||
*
|
||||
* Introduced in version 2.3
|
||||
*/
|
||||
int (*releasedir) (const char *, struct fuse_file_info *);
|
||||
|
||||
/** Synchronize directory contents
|
||||
*
|
||||
* If the datasync parameter is non-zero, then only the user data
|
||||
* should be flushed, not the meta data
|
||||
*
|
||||
* Introduced in version 2.3
|
||||
*/
|
||||
int (*fsyncdir) (const char *, int, struct fuse_file_info *);
|
||||
|
||||
/**
|
||||
* Initialize filesystem
|
||||
*
|
||||
* The return value will passed in the private_data field of
|
||||
* fuse_context to all file operations and as a parameter to the
|
||||
* destroy() method.
|
||||
*
|
||||
* Introduced in version 2.3
|
||||
* Changed in version 2.6
|
||||
*/
|
||||
void *(*init) (struct fuse_conn_info *conn);
|
||||
|
||||
/**
|
||||
* Clean up filesystem
|
||||
*
|
||||
* Called on filesystem exit.
|
||||
*
|
||||
* Introduced in version 2.3
|
||||
*/
|
||||
void (*destroy) (void *);
|
||||
|
||||
/**
|
||||
* Check file access permissions
|
||||
*
|
||||
* This will be called for the access() system call. If the
|
||||
* 'default_permissions' mount option is given, this method is not
|
||||
* called.
|
||||
*
|
||||
* This method is not called under Linux kernel versions 2.4.x
|
||||
*
|
||||
* Introduced in version 2.5
|
||||
*/
|
||||
int (*access) (const char *, int);
|
||||
|
||||
/**
|
||||
* Create and open a file
|
||||
*
|
||||
* If the file does not exist, first create it with the specified
|
||||
* mode, and then open it.
|
||||
*
|
||||
* If this method is not implemented or under Linux kernel
|
||||
* versions earlier than 2.6.15, the mknod() and open() methods
|
||||
* will be called instead.
|
||||
*
|
||||
* Introduced in version 2.5
|
||||
*/
|
||||
int (*create) (const char *, mode_t, struct fuse_file_info *);
|
||||
|
||||
/**
|
||||
* Change the size of an open file
|
||||
*
|
||||
* This method is called instead of the truncate() method if the
|
||||
* truncation was invoked from an ftruncate() system call.
|
||||
*
|
||||
* If this method is not implemented or under Linux kernel
|
||||
* versions earlier than 2.6.15, the truncate() method will be
|
||||
* called instead.
|
||||
*
|
||||
* Introduced in version 2.5
|
||||
*/
|
||||
int (*ftruncate) (const char *, FUSE_OFF_T, struct fuse_file_info *);
|
||||
|
||||
/**
|
||||
* Get attributes from an open file
|
||||
*
|
||||
* This method is called instead of the getattr() method if the
|
||||
* file information is available.
|
||||
*
|
||||
* Currently this is only called after the create() method if that
|
||||
* is implemented (see above). Later it may be called for
|
||||
* invocations of fstat() too.
|
||||
*
|
||||
* Introduced in version 2.5
|
||||
*/
|
||||
int (*fgetattr) (const char *, struct FUSE_STAT *, struct fuse_file_info *);
|
||||
|
||||
/**
|
||||
* Perform POSIX file locking operation
|
||||
*
|
||||
* The cmd argument will be either F_GETLK, F_SETLK or F_SETLKW.
|
||||
*
|
||||
* For the meaning of fields in 'struct flock' see the man page
|
||||
* for fcntl(2). The l_whence field will always be set to
|
||||
* SEEK_SET.
|
||||
*
|
||||
* For checking lock ownership, the 'fuse_file_info->owner'
|
||||
* argument must be used.
|
||||
*
|
||||
* For F_GETLK operation, the library will first check currently
|
||||
* held locks, and if a conflicting lock is found it will return
|
||||
* information without calling this method. This ensures, that
|
||||
* for local locks the l_pid field is correctly filled in. The
|
||||
* results may not be accurate in case of race conditions and in
|
||||
* the presence of hard links, but it's unlikly that an
|
||||
* application would rely on accurate GETLK results in these
|
||||
* cases. If a conflicting lock is not found, this method will be
|
||||
* called, and the filesystem may fill out l_pid by a meaningful
|
||||
* value, or it may leave this field zero.
|
||||
*
|
||||
* For F_SETLK and F_SETLKW the l_pid field will be set to the pid
|
||||
* of the process performing the locking operation.
|
||||
*
|
||||
* Note: if this method is not implemented, the kernel will still
|
||||
* allow file locking to work locally. Hence it is only
|
||||
* interesting for network filesystems and similar.
|
||||
*
|
||||
* Introduced in version 2.6
|
||||
*/
|
||||
int (*lock) (const char *, struct fuse_file_info *, int cmd,
|
||||
struct flock *);
|
||||
|
||||
/**
|
||||
* Change the access and modification times of a file with
|
||||
* nanosecond resolution
|
||||
*
|
||||
* Introduced in version 2.6
|
||||
*/
|
||||
int (*utimens) (const char *, const struct timespec tv[2]);
|
||||
|
||||
/**
|
||||
* Map block index within file to block index within device
|
||||
*
|
||||
* Note: This makes sense only for block device backed filesystems
|
||||
* mounted with the 'blkdev' option
|
||||
*
|
||||
* Introduced in version 2.6
|
||||
*/
|
||||
int (*bmap) (const char *, size_t blocksize, uint64_t *idx);
|
||||
|
||||
#ifdef _WIN32
|
||||
/* these to support extented windows calls */
|
||||
uint32_t (*win_get_attributes) (const char *fn);
|
||||
int (*win_set_attributes) (const char *fn, uint32_t attr);
|
||||
int (*win_set_times) (const char *fn, struct fuse_file_info *, const FILETIME *create, const FILETIME *access, const FILETIME *modified);
|
||||
#endif
|
||||
};
|
||||
|
||||
/** Extra context that may be needed by some filesystems
|
||||
*
|
||||
* The uid, gid and pid fields are not filled in case of a writepage
|
||||
* operation.
|
||||
*/
|
||||
struct fuse_context {
|
||||
/** Pointer to the fuse object */
|
||||
struct fuse *fuse;
|
||||
|
||||
/** User ID of the calling process */
|
||||
uid_t uid;
|
||||
|
||||
/** Group ID of the calling process */
|
||||
gid_t gid;
|
||||
|
||||
/** Thread ID of the calling process */
|
||||
pid_t pid;
|
||||
|
||||
/** Private filesystem data */
|
||||
void *private_data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Main function of FUSE.
|
||||
*
|
||||
* This is for the lazy. This is all that has to be called from the
|
||||
* main() function.
|
||||
*
|
||||
* This function does the following:
|
||||
* - parses command line options (-d -s and -h)
|
||||
* - passes relevant mount options to the fuse_mount()
|
||||
* - installs signal handlers for INT, HUP, TERM and PIPE
|
||||
* - registers an exit handler to unmount the filesystem on program exit
|
||||
* - creates a fuse handle
|
||||
* - registers the operations
|
||||
* - calls either the single-threaded or the multi-threaded event loop
|
||||
*
|
||||
* Note: this is currently implemented as a macro.
|
||||
*
|
||||
* @param argc the argument counter passed to the main() function
|
||||
* @param argv the argument vector passed to the main() function
|
||||
* @param op the file system operation
|
||||
* @param user_data user data supplied in the context during the init() method
|
||||
* @return 0 on success, nonzero on failure
|
||||
*/
|
||||
/*
|
||||
int fuse_main(int argc, char *argv[], const struct fuse_operations *op,
|
||||
void *user_data);
|
||||
*/
|
||||
#define fuse_main(argc, argv, op, user_data) \
|
||||
fuse_main_real(argc, argv, op, sizeof(*(op)), user_data)
|
||||
|
||||
/* ----------------------------------------------------------- *
|
||||
* More detailed API *
|
||||
* ----------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Create a new FUSE filesystem.
|
||||
*
|
||||
* @param ch the communication channel
|
||||
* @param args argument vector
|
||||
* @param op the filesystem operations
|
||||
* @param op_size the size of the fuse_operations structure
|
||||
* @param user_data user data supplied in the context during the init() method
|
||||
* @return the created FUSE handle
|
||||
*/
|
||||
struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args,
|
||||
const struct fuse_operations *op, size_t op_size,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* Destroy the FUSE handle.
|
||||
*
|
||||
* The communication channel attached to the handle is also destroyed.
|
||||
*
|
||||
* NOTE: This function does not unmount the filesystem. If this is
|
||||
* needed, call fuse_unmount() before calling this function.
|
||||
*
|
||||
* @param f the FUSE handle
|
||||
*/
|
||||
void fuse_destroy(struct fuse *f);
|
||||
|
||||
/**
|
||||
* FUSE event loop.
|
||||
*
|
||||
* Requests from the kernel are processed, and the appropriate
|
||||
* operations are called.
|
||||
*
|
||||
* @param f the FUSE handle
|
||||
* @return 0 if no error occurred, -1 otherwise
|
||||
*/
|
||||
int fuse_loop(struct fuse *f);
|
||||
|
||||
/**
|
||||
* Exit from event loop
|
||||
*
|
||||
* @param f the FUSE handle
|
||||
*/
|
||||
void fuse_exit(struct fuse *f);
|
||||
|
||||
/**
|
||||
* FUSE event loop with multiple threads
|
||||
*
|
||||
* Requests from the kernel are processed, and the appropriate
|
||||
* operations are called. Request are processed in parallel by
|
||||
* distributing them between multiple threads.
|
||||
*
|
||||
* Calling this function requires the pthreads library to be linked to
|
||||
* the application.
|
||||
*
|
||||
* @param f the FUSE handle
|
||||
* @return 0 if no error occurred, -1 otherwise
|
||||
*/
|
||||
int fuse_loop_mt(struct fuse *f);
|
||||
|
||||
/**
|
||||
* Get the current context
|
||||
*
|
||||
* The context is only valid for the duration of a filesystem
|
||||
* operation, and thus must not be stored and used later.
|
||||
*
|
||||
* @return the context
|
||||
*/
|
||||
struct fuse_context *fuse_get_context(void);
|
||||
|
||||
/**
|
||||
* Check if a request has already been interrupted
|
||||
*
|
||||
* @return 1 if the request has been interrupted, 0 otherwise
|
||||
*/
|
||||
int fuse_interrupted(void);
|
||||
|
||||
/**
|
||||
* Obsolete, doesn't do anything
|
||||
*
|
||||
* @return -EINVAL
|
||||
*/
|
||||
int fuse_invalidate(struct fuse *f, const char *path);
|
||||
|
||||
/* Deprecated, don't use */
|
||||
int fuse_is_lib_option(const char *opt);
|
||||
|
||||
/**
|
||||
* The real main function
|
||||
*
|
||||
* Do not call this directly, use fuse_main()
|
||||
*/
|
||||
int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
|
||||
size_t op_size, void *user_data);
|
||||
|
||||
/*
|
||||
* Stacking API
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fuse filesystem object
|
||||
*
|
||||
* This is opaque object represents a filesystem layer
|
||||
*/
|
||||
struct fuse_fs;
|
||||
|
||||
/*
|
||||
* These functions call the relevant filesystem operation, and return
|
||||
* the result.
|
||||
*
|
||||
* If the operation is not defined, they return -ENOSYS, with the
|
||||
* exception of fuse_fs_open, fuse_fs_release, fuse_fs_opendir,
|
||||
* fuse_fs_releasedir and fuse_fs_statfs, which return 0.
|
||||
*/
|
||||
|
||||
int fuse_fs_getattr(struct fuse_fs *fs, const char *path, struct FUSE_STAT *buf);
|
||||
int fuse_fs_fgetattr(struct fuse_fs *fs, const char *path, struct FUSE_STAT *buf,
|
||||
struct fuse_file_info *fi);
|
||||
int fuse_fs_rename(struct fuse_fs *fs, const char *oldpath,
|
||||
const char *newpath);
|
||||
int fuse_fs_unlink(struct fuse_fs *fs, const char *path);
|
||||
int fuse_fs_rmdir(struct fuse_fs *fs, const char *path);
|
||||
int fuse_fs_symlink(struct fuse_fs *fs, const char *linkname,
|
||||
const char *path);
|
||||
int fuse_fs_link(struct fuse_fs *fs, const char *oldpath, const char *newpath);
|
||||
int fuse_fs_release(struct fuse_fs *fs, const char *path,
|
||||
struct fuse_file_info *fi);
|
||||
int fuse_fs_open(struct fuse_fs *fs, const char *path,
|
||||
struct fuse_file_info *fi);
|
||||
int fuse_fs_read(struct fuse_fs *fs, const char *path, char *buf, size_t size,
|
||||
FUSE_OFF_T off, struct fuse_file_info *fi);
|
||||
int fuse_fs_write(struct fuse_fs *fs, const char *path, const char *buf,
|
||||
size_t size, FUSE_OFF_T off, struct fuse_file_info *fi);
|
||||
int fuse_fs_fsync(struct fuse_fs *fs, const char *path, int datasync,
|
||||
struct fuse_file_info *fi);
|
||||
int fuse_fs_flush(struct fuse_fs *fs, const char *path,
|
||||
struct fuse_file_info *fi);
|
||||
int fuse_fs_statfs(struct fuse_fs *fs, const char *path, struct statvfs *buf);
|
||||
int fuse_fs_opendir(struct fuse_fs *fs, const char *path,
|
||||
struct fuse_file_info *fi);
|
||||
int fuse_fs_readdir(struct fuse_fs *fs, const char *path, void *buf,
|
||||
fuse_fill_dir_t filler, FUSE_OFF_T off,
|
||||
struct fuse_file_info *fi);
|
||||
int fuse_fs_fsyncdir(struct fuse_fs *fs, const char *path, int datasync,
|
||||
struct fuse_file_info *fi);
|
||||
int fuse_fs_releasedir(struct fuse_fs *fs, const char *path,
|
||||
struct fuse_file_info *fi);
|
||||
int fuse_fs_create(struct fuse_fs *fs, const char *path, mode_t mode,
|
||||
struct fuse_file_info *fi);
|
||||
int fuse_fs_lock(struct fuse_fs *fs, const char *path,
|
||||
struct fuse_file_info *fi, int cmd, struct flock *lock);
|
||||
int fuse_fs_chmod(struct fuse_fs *fs, const char *path, mode_t mode);
|
||||
int fuse_fs_chown(struct fuse_fs *fs, const char *path, uid_t uid, gid_t gid);
|
||||
int fuse_fs_truncate(struct fuse_fs *fs, const char *path, FUSE_OFF_T size);
|
||||
int fuse_fs_ftruncate(struct fuse_fs *fs, const char *path, FUSE_OFF_T size,
|
||||
struct fuse_file_info *fi);
|
||||
int fuse_fs_utimens(struct fuse_fs *fs, const char *path,
|
||||
const struct timespec tv[2]);
|
||||
int fuse_fs_access(struct fuse_fs *fs, const char *path, int mask);
|
||||
int fuse_fs_readlink(struct fuse_fs *fs, const char *path, char *buf,
|
||||
size_t len);
|
||||
int fuse_fs_mknod(struct fuse_fs *fs, const char *path, mode_t mode,
|
||||
dev_t rdev);
|
||||
int fuse_fs_mkdir(struct fuse_fs *fs, const char *path, mode_t mode);
|
||||
int fuse_fs_setxattr(struct fuse_fs *fs, const char *path, const char *name,
|
||||
const char *value, size_t size, int flags);
|
||||
int fuse_fs_getxattr(struct fuse_fs *fs, const char *path, const char *name,
|
||||
char *value, size_t size);
|
||||
int fuse_fs_listxattr(struct fuse_fs *fs, const char *path, char *list,
|
||||
size_t size);
|
||||
int fuse_fs_removexattr(struct fuse_fs *fs, const char *path,
|
||||
const char *name);
|
||||
int fuse_fs_bmap(struct fuse_fs *fs, const char *path, size_t blocksize,
|
||||
uint64_t *idx);
|
||||
void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn);
|
||||
void fuse_fs_destroy(struct fuse_fs *fs);
|
||||
|
||||
/**
|
||||
* Create a new fuse filesystem object
|
||||
*
|
||||
* This is usually called from the factory of a fuse module to create
|
||||
* a new instance of a filesystem.
|
||||
*
|
||||
* @param op the filesystem operations
|
||||
* @param op_size the size of the fuse_operations structure
|
||||
* @param user_data user data supplied in the context during the init() method
|
||||
* @return a new filesystem object
|
||||
*/
|
||||
struct fuse_fs *fuse_fs_new(const struct fuse_operations *op, size_t op_size,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* Filesystem module
|
||||
*
|
||||
* Filesystem modules are registered with the FUSE_REGISTER_MODULE()
|
||||
* macro.
|
||||
*
|
||||
* If the "-omodules=modname:..." option is present, filesystem
|
||||
* objects are created and pushed onto the stack with the 'factory'
|
||||
* function.
|
||||
*/
|
||||
struct fuse_module {
|
||||
/**
|
||||
* Name of filesystem
|
||||
*/
|
||||
const char *name;
|
||||
|
||||
/**
|
||||
* Factory for creating filesystem objects
|
||||
*
|
||||
* The function may use and remove options from 'args' that belong
|
||||
* to this module.
|
||||
*
|
||||
* For now the 'fs' vector always contains exactly one filesystem.
|
||||
* This is the filesystem which will be below the newly created
|
||||
* filesystem in the stack.
|
||||
*
|
||||
* @param args the command line arguments
|
||||
* @param fs NULL terminated filesystem object vector
|
||||
* @return the new filesystem object
|
||||
*/
|
||||
struct fuse_fs *(*factory)(struct fuse_args *args,
|
||||
struct fuse_fs *fs[]);
|
||||
|
||||
struct fuse_module *next;
|
||||
struct fusemod_so *so;
|
||||
int ctr;
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a filesystem module
|
||||
*
|
||||
* This function is used by FUSE_REGISTER_MODULE and there's usually
|
||||
* no need to call it directly
|
||||
*/
|
||||
void fuse_register_module(struct fuse_module *mod);
|
||||
|
||||
/**
|
||||
* Register filesystem module
|
||||
*
|
||||
* For the parameters, see description of the fields in 'struct
|
||||
* fuse_module'
|
||||
*/
|
||||
#define FUSE_REGISTER_MODULE(name_, factory_) \
|
||||
static __attribute__((constructor)) void name_ ## _register(void) \
|
||||
{ \
|
||||
static struct fuse_module mod = \
|
||||
{ #name_, factory_, NULL, NULL, 0 }; \
|
||||
fuse_register_module(&mod); \
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------- *
|
||||
* Advanced API for event handling, don't worry about this... *
|
||||
* ----------------------------------------------------------- */
|
||||
|
||||
/* NOTE: the following functions are deprecated, and will be removed
|
||||
from the 3.0 API. Use the lowlevel session functions instead */
|
||||
|
||||
/** Function type used to process commands */
|
||||
typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
|
||||
|
||||
/** This is the part of fuse_main() before the event loop */
|
||||
struct fuse *fuse_setup(int argc, char *argv[],
|
||||
const struct fuse_operations *op, size_t op_size,
|
||||
char **mountpoint, int *multithreaded,
|
||||
void *user_data);
|
||||
|
||||
/** This is the part of fuse_main() after the event loop */
|
||||
void fuse_teardown(struct fuse *fuse, char *mountpoint);
|
||||
|
||||
/** Read a single command. If none are read, return NULL */
|
||||
struct fuse_cmd *fuse_read_cmd(struct fuse *f);
|
||||
|
||||
/** Process a single command */
|
||||
void fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd);
|
||||
|
||||
/** Multi threaded event loop, which calls the custom command
|
||||
processor function */
|
||||
int fuse_loop_mt_proc(struct fuse *f, fuse_processor_t proc, void *data);
|
||||
|
||||
/** Return the exited flag, which indicates if fuse_exit() has been
|
||||
called */
|
||||
int fuse_exited(struct fuse *f);
|
||||
|
||||
/** This function is obsolete and implemented as a no-op */
|
||||
void fuse_set_getcontext_func(struct fuse_context *(*func)(void));
|
||||
|
||||
/** Get session from fuse object */
|
||||
struct fuse_session *fuse_get_session(struct fuse *f);
|
||||
|
||||
/* ----------------------------------------------------------- *
|
||||
* Compatibility stuff *
|
||||
* ----------------------------------------------------------- */
|
||||
|
||||
#if FUSE_USE_VERSION < 26
|
||||
# include "fuse_compat.h"
|
||||
# undef fuse_main
|
||||
# if FUSE_USE_VERSION == 25
|
||||
# define fuse_main(argc, argv, op) \
|
||||
fuse_main_real_compat25(argc, argv, op, sizeof(*(op)))
|
||||
# define fuse_new fuse_new_compat25
|
||||
# define fuse_setup fuse_setup_compat25
|
||||
# define fuse_teardown fuse_teardown_compat22
|
||||
# define fuse_operations fuse_operations_compat25
|
||||
# elif FUSE_USE_VERSION == 22
|
||||
# define fuse_main(argc, argv, op) \
|
||||
fuse_main_real_compat22(argc, argv, op, sizeof(*(op)))
|
||||
# define fuse_new fuse_new_compat22
|
||||
# define fuse_setup fuse_setup_compat22
|
||||
# define fuse_teardown fuse_teardown_compat22
|
||||
# define fuse_operations fuse_operations_compat22
|
||||
# define fuse_file_info fuse_file_info_compat
|
||||
# elif FUSE_USE_VERSION == 24
|
||||
# error Compatibility with high-level API version 24 not supported
|
||||
# else
|
||||
# define fuse_dirfil_t fuse_dirfil_t_compat
|
||||
# define __fuse_read_cmd fuse_read_cmd
|
||||
# define __fuse_process_cmd fuse_process_cmd
|
||||
# define __fuse_loop_mt fuse_loop_mt_proc
|
||||
# if FUSE_USE_VERSION == 21
|
||||
# define fuse_operations fuse_operations_compat2
|
||||
# define fuse_main fuse_main_compat2
|
||||
# define fuse_new fuse_new_compat2
|
||||
# define __fuse_setup fuse_setup_compat2
|
||||
# define __fuse_teardown fuse_teardown_compat22
|
||||
# define __fuse_exited fuse_exited
|
||||
# define __fuse_set_getcontext_func fuse_set_getcontext_func
|
||||
# else
|
||||
# define fuse_statfs fuse_statfs_compat1
|
||||
# define fuse_operations fuse_operations_compat1
|
||||
# define fuse_main fuse_main_compat1
|
||||
# define fuse_new fuse_new_compat1
|
||||
# define FUSE_DEBUG FUSE_DEBUG_COMPAT1
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* FUSE_H_ */
|
249
3rd_party/Dokan Library-1.0.2/include/fuse/fuse_common.h
vendored
Normal file
249
3rd_party/Dokan Library-1.0.2/include/fuse/fuse_common.h
vendored
Normal file
@@ -0,0 +1,249 @@
|
||||
/*
|
||||
FUSE: Filesystem in Userspace
|
||||
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
|
||||
|
||||
This program can be distributed under the terms of the GNU LGPLv2.
|
||||
See the file COPYING.LIB.
|
||||
*/
|
||||
|
||||
/** @file */
|
||||
|
||||
#if !defined(FUSE_H_) && !defined(FUSE_LOWLEVEL_H_)
|
||||
#error "Never include <fuse_common.h> directly; use <fuse.h> or <fuse_lowlevel.h> instead."
|
||||
#endif
|
||||
|
||||
#ifndef FUSE_COMMON_H_
|
||||
#define FUSE_COMMON_H_
|
||||
|
||||
#include "fuse_opt.h"
|
||||
#ifndef _MSC_VER
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
/** Major version of FUSE library interface */
|
||||
#define FUSE_MAJOR_VERSION 2
|
||||
|
||||
/** Minor version of FUSE library interface */
|
||||
#define FUSE_MINOR_VERSION 7
|
||||
|
||||
#define FUSE_MAKE_VERSION(maj, min) ((maj) * 10 + (min))
|
||||
#define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION)
|
||||
|
||||
/* This interface uses 64 bit off_t, except on Windows where it's
|
||||
possible to use 32-bit filelengths for compatibility with MSVC CRT */
|
||||
#ifndef _MSC_VER
|
||||
/* This interface uses 64 bit off_t */
|
||||
#if _FILE_OFFSET_BITS != 64
|
||||
#error Please add -D_FILE_OFFSET_BITS=64 to your compile flags!
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Information about open files
|
||||
*
|
||||
* Changed in version 2.5
|
||||
*/
|
||||
struct fuse_file_info {
|
||||
/** Open flags. Available in open() and release() */
|
||||
int flags;
|
||||
|
||||
/** Old file handle, don't use */
|
||||
unsigned long fh_old;
|
||||
|
||||
/** In case of a write operation indicates if this was caused by a
|
||||
writepage */
|
||||
int writepage;
|
||||
|
||||
/** Can be filled in by open, to use direct I/O on this file.
|
||||
Introduced in version 2.4 */
|
||||
unsigned int direct_io : 1;
|
||||
|
||||
/** Can be filled in by open, to indicate, that cached file data
|
||||
need not be invalidated. Introduced in version 2.4 */
|
||||
unsigned int keep_cache : 1;
|
||||
|
||||
/** Indicates a flush operation. Set in flush operation, also
|
||||
maybe set in highlevel lock operation and lowlevel release
|
||||
operation. Introduced in version 2.6 */
|
||||
unsigned int flush : 1;
|
||||
|
||||
/** Padding. Do not use*/
|
||||
unsigned int padding : 29;
|
||||
|
||||
/** File handle. May be filled in by filesystem in open().
|
||||
Available in all other file operations */
|
||||
uint64_t fh;
|
||||
|
||||
/** Lock owner id. Available in locking operations and flush */
|
||||
uint64_t lock_owner;
|
||||
};
|
||||
|
||||
/**
|
||||
* Connection information, passed to the ->init() method
|
||||
*
|
||||
* Some of the elements are read-write, these can be changed to
|
||||
* indicate the value requested by the filesystem. The requested
|
||||
* value must usually be smaller than the indicated value.
|
||||
*/
|
||||
struct fuse_conn_info {
|
||||
/**
|
||||
* Major version of the protocol (read-only)
|
||||
*/
|
||||
unsigned proto_major;
|
||||
|
||||
/**
|
||||
* Minor version of the protocol (read-only)
|
||||
*/
|
||||
unsigned proto_minor;
|
||||
|
||||
/**
|
||||
* Is asynchronous read supported (read-write)
|
||||
*/
|
||||
unsigned async_read;
|
||||
|
||||
/**
|
||||
* Maximum size of the write buffer
|
||||
*/
|
||||
unsigned max_write;
|
||||
|
||||
/**
|
||||
* Maximum readahead
|
||||
*/
|
||||
unsigned max_readahead;
|
||||
|
||||
/**
|
||||
* For future use.
|
||||
*/
|
||||
unsigned reserved[27];
|
||||
};
|
||||
|
||||
struct fuse_session;
|
||||
struct fuse_chan;
|
||||
|
||||
/**
|
||||
* Create a FUSE mountpoint
|
||||
*
|
||||
* Returns a control file descriptor suitable for passing to
|
||||
* fuse_new()
|
||||
*
|
||||
* @param mountpoint the mount point path
|
||||
* @param args argument vector
|
||||
* @return the communication channel on success, NULL on failure
|
||||
*/
|
||||
struct fuse_chan *fuse_mount(const char *mountpoint, struct fuse_args *args);
|
||||
|
||||
/**
|
||||
* Umount a FUSE mountpoint
|
||||
*
|
||||
* @param mountpoint the mount point path
|
||||
* @param ch the communication channel
|
||||
*/
|
||||
void fuse_unmount(const char *mountpoint, struct fuse_chan *ch);
|
||||
|
||||
/**
|
||||
* Parse common options
|
||||
*
|
||||
* The following options are parsed:
|
||||
*
|
||||
* '-f' foreground
|
||||
* '-d' '-odebug' foreground, but keep the debug option
|
||||
* '-s' single threaded
|
||||
* '-h' '--help' help
|
||||
* '-ho' help without header
|
||||
* '-ofsname=..' file system name, if not present, then set to the program
|
||||
* name
|
||||
*
|
||||
* All parameters may be NULL
|
||||
*
|
||||
* @param args argument vector
|
||||
* @param mountpoint the returned mountpoint, should be freed after use
|
||||
* @param multithreaded set to 1 unless the '-s' option is present
|
||||
* @param foreground set to 1 if one of the relevant options is present
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
int fuse_parse_cmdline(struct fuse_args *args, char **mountpoint,
|
||||
int *multithreaded, int *foreground);
|
||||
|
||||
/**
|
||||
* Go into the background
|
||||
*
|
||||
* @param foreground if true, stay in the foreground
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
int fuse_daemonize(int foreground);
|
||||
|
||||
/**
|
||||
* Get the version of the library
|
||||
*
|
||||
* @return the version
|
||||
*/
|
||||
int fuse_version(void);
|
||||
|
||||
/* ----------------------------------------------------------- *
|
||||
* Signal handling *
|
||||
* ----------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Exit session on HUP, TERM and INT signals and ignore PIPE signal
|
||||
*
|
||||
* Stores session in a global variable. May only be called once per
|
||||
* process until fuse_remove_signal_handlers() is called.
|
||||
*
|
||||
* @param se the session to exit
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
int fuse_set_signal_handlers(struct fuse_session *se);
|
||||
|
||||
/**
|
||||
* Restore default signal handlers
|
||||
*
|
||||
* Resets global session. After this fuse_set_signal_handlers() may
|
||||
* be called again.
|
||||
*
|
||||
* @param se the same session as given in fuse_set_signal_handlers()
|
||||
*/
|
||||
void fuse_remove_signal_handlers(struct fuse_session *se);
|
||||
|
||||
/* ----------------------------------------------------------- *
|
||||
* Compatibility stuff *
|
||||
* ----------------------------------------------------------- */
|
||||
|
||||
#if FUSE_USE_VERSION < 26
|
||||
# ifdef __FreeBSD__
|
||||
# if FUSE_USE_VERSION < 25
|
||||
# error On FreeBSD API version 25 or greater must be used
|
||||
# endif
|
||||
# endif
|
||||
# include "fuse_common_compat.h"
|
||||
# undef FUSE_MINOR_VERSION
|
||||
# undef fuse_main
|
||||
# define fuse_unmount fuse_unmount_compat22
|
||||
# if FUSE_USE_VERSION == 25
|
||||
# define FUSE_MINOR_VERSION 5
|
||||
# define fuse_mount fuse_mount_compat25
|
||||
# elif FUSE_USE_VERSION == 24 || FUSE_USE_VERSION == 22
|
||||
# define FUSE_MINOR_VERSION 4
|
||||
# define fuse_mount fuse_mount_compat22
|
||||
# elif FUSE_USE_VERSION == 21
|
||||
# define FUSE_MINOR_VERSION 1
|
||||
# define fuse_mount fuse_mount_compat22
|
||||
# elif FUSE_USE_VERSION == 11
|
||||
# warning Compatibility with API version 11 is deprecated
|
||||
# undef FUSE_MAJOR_VERSION
|
||||
# define FUSE_MAJOR_VERSION 1
|
||||
# define FUSE_MINOR_VERSION 1
|
||||
# define fuse_mount fuse_mount_compat1
|
||||
# else
|
||||
# error Compatibility with API version other than 21, 22, 24, 25 and 11 not supported
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* FUSE_COMMON_H_ */
|
267
3rd_party/Dokan Library-1.0.2/include/fuse/fuse_opt.h
vendored
Normal file
267
3rd_party/Dokan Library-1.0.2/include/fuse/fuse_opt.h
vendored
Normal file
@@ -0,0 +1,267 @@
|
||||
/*
|
||||
FUSE: Filesystem in Userspace
|
||||
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
|
||||
|
||||
This program can be distributed under the terms of the GNU LGPLv2.
|
||||
See the file COPYING.LIB.
|
||||
*/
|
||||
|
||||
#ifndef FUSE_OPT_H_
|
||||
#define FUSE_OPT_H_
|
||||
|
||||
/** @file
|
||||
*
|
||||
* This file defines the option parsing interface of FUSE
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define STRDUP _strdup
|
||||
#else
|
||||
#define STRDUP strdup
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Option description
|
||||
*
|
||||
* This structure describes a single option, and and action associated
|
||||
* with it, in case it matches.
|
||||
*
|
||||
* More than one such match may occur, in which case the action for
|
||||
* each match is executed.
|
||||
*
|
||||
* There are three possible actions in case of a match:
|
||||
*
|
||||
* i) An integer (int or unsigned) variable determined by 'offset' is
|
||||
* set to 'value'
|
||||
*
|
||||
* ii) The processing function is called, with 'value' as the key
|
||||
*
|
||||
* iii) An integer (any) or string (char *) variable determined by
|
||||
* 'offset' is set to the value of an option parameter
|
||||
*
|
||||
* 'offset' should normally be either set to
|
||||
*
|
||||
* - 'offsetof(struct foo, member)' actions i) and iii)
|
||||
*
|
||||
* - -1 action ii)
|
||||
*
|
||||
* The 'offsetof()' macro is defined in the <stddef.h> header.
|
||||
*
|
||||
* The template determines which options match, and also have an
|
||||
* effect on the action. Normally the action is either i) or ii), but
|
||||
* if a format is present in the template, then action iii) is
|
||||
* performed.
|
||||
*
|
||||
* The types of templates are:
|
||||
*
|
||||
* 1) "-x", "-foo", "--foo", "--foo-bar", etc. These match only
|
||||
* themselves. Invalid values are "--" and anything beginning
|
||||
* with "-o"
|
||||
*
|
||||
* 2) "foo", "foo-bar", etc. These match "-ofoo", "-ofoo-bar" or
|
||||
* the relevant option in a comma separated option list
|
||||
*
|
||||
* 3) "bar=", "--foo=", etc. These are variations of 1) and 2)
|
||||
* which have a parameter
|
||||
*
|
||||
* 4) "bar=%s", "--foo=%lu", etc. Same matching as above but perform
|
||||
* action iii).
|
||||
*
|
||||
* 5) "-x ", etc. Matches either "-xparam" or "-x param" as
|
||||
* two separate arguments
|
||||
*
|
||||
* 6) "-x %s", etc. Combination of 4) and 5)
|
||||
*
|
||||
* If the format is "%s", memory is allocated for the string unlike
|
||||
* with scanf().
|
||||
*/
|
||||
struct fuse_opt {
|
||||
/** Matching template and optional parameter formatting */
|
||||
const char *templ;
|
||||
|
||||
/**
|
||||
* Offset of variable within 'data' parameter of fuse_opt_parse()
|
||||
* or -1
|
||||
*/
|
||||
unsigned long offset;
|
||||
|
||||
/**
|
||||
* Value to set the variable to, or to be passed as 'key' to the
|
||||
* processing function. Ignored if template has a format
|
||||
*/
|
||||
int value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Key option. In case of a match, the processing function will be
|
||||
* called with the specified key.
|
||||
*/
|
||||
#define FUSE_OPT_KEY(templ, key) { templ, (unsigned long)(-1), key }
|
||||
|
||||
/**
|
||||
* Last option. An array of 'struct fuse_opt' must end with a NULL
|
||||
* template value
|
||||
*/
|
||||
#define FUSE_OPT_END { NULL }
|
||||
|
||||
/**
|
||||
* Argument list
|
||||
*/
|
||||
struct fuse_args {
|
||||
/** Argument count */
|
||||
int argc;
|
||||
|
||||
/** Argument vector. NULL terminated */
|
||||
char **argv;
|
||||
|
||||
/** Is 'argv' allocated? */
|
||||
int allocated;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializer for 'struct fuse_args'
|
||||
*/
|
||||
#define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }
|
||||
|
||||
/**
|
||||
* Key value passed to the processing function if an option did not
|
||||
* match any template
|
||||
*/
|
||||
#define FUSE_OPT_KEY_OPT -1
|
||||
|
||||
/**
|
||||
* Key value passed to the processing function for all non-options
|
||||
*
|
||||
* Non-options are the arguments beginning with a charater other than
|
||||
* '-' or all arguments after the special '--' option
|
||||
*/
|
||||
#define FUSE_OPT_KEY_NONOPT -2
|
||||
|
||||
/**
|
||||
* Special key value for options to keep
|
||||
*
|
||||
* Argument is not passed to processing function, but behave as if the
|
||||
* processing function returned 1
|
||||
*/
|
||||
#define FUSE_OPT_KEY_KEEP -3
|
||||
|
||||
/**
|
||||
* Special key value for options to discard
|
||||
*
|
||||
* Argument is not passed to processing function, but behave as if the
|
||||
* processing function returned zero
|
||||
*/
|
||||
#define FUSE_OPT_KEY_DISCARD -4
|
||||
|
||||
/**
|
||||
* Processing function
|
||||
*
|
||||
* This function is called if
|
||||
* - option did not match any 'struct fuse_opt'
|
||||
* - argument is a non-option
|
||||
* - option did match and offset was set to -1
|
||||
*
|
||||
* The 'arg' parameter will always contain the whole argument or
|
||||
* option including the parameter if exists. A two-argument option
|
||||
* ("-x foo") is always converted to single arguemnt option of the
|
||||
* form "-xfoo" before this function is called.
|
||||
*
|
||||
* Options of the form '-ofoo' are passed to this function without the
|
||||
* '-o' prefix.
|
||||
*
|
||||
* The return value of this function determines whether this argument
|
||||
* is to be inserted into the output argument vector, or discarded.
|
||||
*
|
||||
* @param data is the user data passed to the fuse_opt_parse() function
|
||||
* @param arg is the whole argument or option
|
||||
* @param key determines why the processing function was called
|
||||
* @param outargs the current output argument list
|
||||
* @return -1 on error, 0 if arg is to be discarded, 1 if arg should be kept
|
||||
*/
|
||||
typedef int (*fuse_opt_proc_t)(void *data, const char *arg, int key,
|
||||
struct fuse_args *outargs);
|
||||
|
||||
/**
|
||||
* Option parsing function
|
||||
*
|
||||
* If 'args' was returned from a previous call to fuse_opt_parse() or
|
||||
* it was constructed from
|
||||
*
|
||||
* A NULL 'args' is equivalent to an empty argument vector
|
||||
*
|
||||
* A NULL 'opts' is equivalent to an 'opts' array containing a single
|
||||
* end marker
|
||||
*
|
||||
* A NULL 'proc' is equivalent to a processing function always
|
||||
* returning '1'
|
||||
*
|
||||
* @param args is the input and output argument list
|
||||
* @param data is the user data
|
||||
* @param opts is the option description array
|
||||
* @param proc is the processing function
|
||||
* @return -1 on error, 0 on success
|
||||
*/
|
||||
int fuse_opt_parse(struct fuse_args *args, void *data,
|
||||
const struct fuse_opt opts[], fuse_opt_proc_t proc);
|
||||
|
||||
/**
|
||||
* Add an option to a comma separated option list
|
||||
*
|
||||
* @param opts is a pointer to an option list, may point to a NULL value
|
||||
* @param opt is the option to add
|
||||
* @return -1 on allocation error, 0 on success
|
||||
*/
|
||||
int fuse_opt_add_opt(char **opts, const char *opt);
|
||||
|
||||
/**
|
||||
* Add an argument to a NULL terminated argument vector
|
||||
*
|
||||
* @param args is the structure containing the current argument list
|
||||
* @param arg is the new argument to add
|
||||
* @return -1 on allocation error, 0 on success
|
||||
*/
|
||||
int fuse_opt_add_arg(struct fuse_args *args, const char *arg);
|
||||
|
||||
/**
|
||||
* Add an argument at the specified position in a NULL terminated
|
||||
* argument vector
|
||||
*
|
||||
* Adds the argument to the N-th position. This is useful for adding
|
||||
* options at the beggining of the array which must not come after the
|
||||
* special '--' option.
|
||||
*
|
||||
* @param args is the structure containing the current argument list
|
||||
* @param pos is the position at which to add the argument
|
||||
* @param arg is the new argument to add
|
||||
* @return -1 on allocation error, 0 on success
|
||||
*/
|
||||
int fuse_opt_insert_arg(struct fuse_args *args, int pos, const char *arg);
|
||||
|
||||
/**
|
||||
* Free the contents of argument list
|
||||
*
|
||||
* The structure itself is not freed
|
||||
*
|
||||
* @param args is the structure containing the argument list
|
||||
*/
|
||||
void fuse_opt_free_args(struct fuse_args *args);
|
||||
|
||||
|
||||
/**
|
||||
* Check if an option matches
|
||||
*
|
||||
* @param opts is the option description array
|
||||
* @param opt is the option to match
|
||||
* @return 1 if a match is found, 0 if not
|
||||
*/
|
||||
int fuse_opt_match(const struct fuse_opt opts[], const char *opt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* FUSE_OPT_H_ */
|
27
3rd_party/Dokan Library-1.0.2/include/fuse/fuse_sem_fix.h
vendored
Normal file
27
3rd_party/Dokan Library-1.0.2/include/fuse/fuse_sem_fix.h
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef FUSE_SEM_FIX_H_
|
||||
#define FUSE_SEM_FIX_H_
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
#include <semaphore.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int my_sem_init(sem_t *sem, int pshared, int initial);
|
||||
int my_sem_destroy(sem_t *sem);
|
||||
int my_sem_post (sem_t * sem);
|
||||
int my_sem_wait (sem_t * sem);
|
||||
#define sem_init my_sem_init
|
||||
#define sem_destroy my_sem_destroy
|
||||
#define sem_wait my_sem_wait
|
||||
#define sem_post my_sem_post
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#endif //FUSE_SEM_FIX_H_
|
221
3rd_party/Dokan Library-1.0.2/include/fuse/fuse_win.h
vendored
Normal file
221
3rd_party/Dokan Library-1.0.2/include/fuse/fuse_win.h
vendored
Normal file
@@ -0,0 +1,221 @@
|
||||
/* ----------------------------------------------------------- *
|
||||
* Win32 helper functions *
|
||||
* Compilation on MSVC requires /Zc:wchar_t compiler option *
|
||||
* ----------------------------------------------------------- */
|
||||
#ifndef FUSE_WIN_H_
|
||||
#define FUSE_WIN_H_
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define WIN32_NO_STATUS
|
||||
#include <windows.h>
|
||||
#undef WIN32_NO_STATUS
|
||||
#endif
|
||||
|
||||
/** Only use the latest version on Windows */
|
||||
#ifndef FUSE_USE_VERSION
|
||||
#define FUSE_USE_VERSION 27
|
||||
#endif
|
||||
|
||||
#ifndef DEFAULT_FUSE_VOLUME_NAME
|
||||
#define DEFAULT_FUSE_VOLUME_NAME "DOKAN"
|
||||
#endif
|
||||
|
||||
#ifndef DEFAULT_FUSE_FILESYSTEM_NAME
|
||||
#define DEFAULT_FUSE_FILESYSTEM_NAME "Dokan user-level file system"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
int ntstatus_error_to_errno(int win_res);
|
||||
int errno_to_ntstatus_error(int err);
|
||||
|
||||
//This stuff is useful only on Windows in MSVC
|
||||
#ifdef _MSC_VER
|
||||
char** convert_args(int argc, wchar_t* argv[]);
|
||||
void free_converted_args(int argc, char **argv);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
extern wchar_t* Dokan_filesystem_name;
|
||||
extern wchar_t* Dokan_volume_name;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
////// Type definitions for MINGW32
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
#if defined(__MINGW32__) && !defined(UID_GID_DEF)
|
||||
typedef unsigned int gid_t;
|
||||
typedef unsigned int uid_t;
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_STRUCT_TIMESPEC) && !defined(__CYGWIN__) && !defined(_TIMESPEC_DEFINED) && defined(_CRT_NO_TIME_T) /* win32 pthread.h time.h defines it */
|
||||
/* POSIX.1b structure for a time value. This is like a `struct timeval' but
|
||||
has nanoseconds instead of microseconds. */
|
||||
#define HAVE_STRUCT_TIMESPEC 1
|
||||
#define _TIMESPEC_DEFINED
|
||||
struct timespec
|
||||
{
|
||||
time_t tv_sec; /* Seconds. */
|
||||
long int tv_nsec; /* Nanoseconds. */
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(__MINGW32__)
|
||||
/** Use 64 bit offsets */
|
||||
#define __USE_FILE_OFFSET64
|
||||
//Block sizes
|
||||
typedef unsigned __int64 fsfilcnt64_t;
|
||||
typedef unsigned __int64 fsblkcnt64_t;
|
||||
typedef struct timespec timestruc_t;
|
||||
typedef unsigned short nlink_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
typedef unsigned int blksize_t;
|
||||
typedef unsigned __int64 blkcnt_t;
|
||||
|
||||
/** Transplanted from <sys/statvfs.h>*/
|
||||
struct statvfs
|
||||
{
|
||||
unsigned long int f_bsize;
|
||||
unsigned long int f_frsize;
|
||||
fsblkcnt64_t f_blocks;
|
||||
fsblkcnt64_t f_bfree;
|
||||
fsblkcnt64_t f_bavail;
|
||||
fsfilcnt64_t f_files;
|
||||
fsfilcnt64_t f_ffree;
|
||||
fsfilcnt64_t f_favail;
|
||||
unsigned long int f_fsid;
|
||||
unsigned long int f_flag;
|
||||
unsigned long int f_namemax;
|
||||
};
|
||||
struct flock {
|
||||
short l_type;
|
||||
short l_whence;
|
||||
off_t l_start;
|
||||
off_t l_len;
|
||||
pid_t l_pid;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
////// Type definitions for MSVC
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
#if defined(_MSC_VER)
|
||||
//UNIX compatibility
|
||||
typedef struct timespec timestruc_t;
|
||||
typedef unsigned int mode_t;
|
||||
typedef unsigned short nlink_t;
|
||||
typedef unsigned int pid_t;
|
||||
typedef unsigned int gid_t;
|
||||
typedef unsigned int uid_t;
|
||||
typedef unsigned int blksize_t;
|
||||
typedef unsigned __int64 blkcnt_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
typedef __int64 int64_t;
|
||||
|
||||
|
||||
//OCTAL constants!
|
||||
#define S_IFLNK 0120000
|
||||
#define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK)
|
||||
|
||||
/** Use 64 bit offsets */
|
||||
#define __USE_FILE_OFFSET64
|
||||
//Block sizes
|
||||
typedef unsigned __int64 fsfilcnt64_t;
|
||||
typedef unsigned __int64 fsblkcnt64_t;
|
||||
|
||||
/** Transplanted from <sys/statvfs.h>*/
|
||||
struct statvfs
|
||||
{
|
||||
unsigned long int f_bsize;
|
||||
unsigned long int f_frsize;
|
||||
fsblkcnt64_t f_blocks;
|
||||
fsblkcnt64_t f_bfree;
|
||||
fsblkcnt64_t f_bavail;
|
||||
fsfilcnt64_t f_files;
|
||||
fsfilcnt64_t f_ffree;
|
||||
fsfilcnt64_t f_favail;
|
||||
unsigned long int f_fsid;
|
||||
unsigned long int f_flag;
|
||||
unsigned long int f_namemax;
|
||||
};
|
||||
|
||||
struct flock {
|
||||
short l_type;
|
||||
short l_whence;
|
||||
__int64 l_start;
|
||||
__int64 l_len;
|
||||
pid_t l_pid;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
//We have a choice between CRT-compatible 32-bit off_t definition
|
||||
//and a custom 64-bit definition
|
||||
#define WIDE_OFF_T 1
|
||||
#ifndef WIDE_OFF_T
|
||||
#define FUSE_OFF_T off_t
|
||||
#define FUSE_STAT stat
|
||||
|
||||
#else
|
||||
#define FUSE_OFF_T __int64
|
||||
// #define FUSE_STAT _stati64
|
||||
// use stat from cygwin instead for having more members and
|
||||
// being more compatible
|
||||
// stat ported from cygwin sys/stat.h
|
||||
struct stat64_cygwin
|
||||
{
|
||||
dev_t st_dev;
|
||||
uint64_t st_ino;
|
||||
mode_t st_mode;
|
||||
nlink_t st_nlink;
|
||||
uid_t st_uid;
|
||||
gid_t st_gid;
|
||||
dev_t st_rdev;
|
||||
FUSE_OFF_T st_size;
|
||||
timestruc_t st_atim;
|
||||
timestruc_t st_mtim;
|
||||
timestruc_t st_ctim;
|
||||
blksize_t st_blksize;
|
||||
blkcnt_t st_blocks;
|
||||
timestruc_t st_birthtim;
|
||||
};
|
||||
/* The following breaks struct stat definiton in native Windows stats.h
|
||||
* So whenever referencing st_atime|st_ctime|st_mtime, replacing is needed.
|
||||
*/
|
||||
/*
|
||||
#define st_atime st_atim.tv_sec
|
||||
#define st_ctime st_ctim.tv_sec
|
||||
#define st_mtime st_mtim.tv_sec
|
||||
*/
|
||||
#define FUSE_STAT stat64_cygwin
|
||||
#if 0
|
||||
struct stat64 {
|
||||
dev_t st_dev;
|
||||
ino_t st_ino;
|
||||
unsigned short st_mode;
|
||||
short st_nlink;
|
||||
short st_uid;
|
||||
short st_gid;
|
||||
dev_t st_rdev;
|
||||
FUSE_OFF_T st_size;
|
||||
time_t st_atime;
|
||||
time_t st_mtime;
|
||||
time_t st_ctime;
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#define F_WRLCK 1
|
||||
#define F_UNLCK 2
|
||||
#define F_SETLK 6
|
||||
|
||||
#endif // FUSE_WIN_H_
|
64
3rd_party/Dokan Library-1.0.2/include/fuse/utils.h
vendored
Normal file
64
3rd_party/Dokan Library-1.0.2/include/fuse/utils.h
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef UTILS_H_
|
||||
#define UTILS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <string>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#include "fuse.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void utf8_to_wchar_buf_old(const char *src, wchar_t *res, int maxlen);
|
||||
void utf8_to_wchar_buf(const char *src, wchar_t *res, int maxlen);
|
||||
|
||||
FILETIME unixTimeToFiletime(time_t t);
|
||||
time_t filetimeToUnixTime(const FILETIME *ft);
|
||||
bool is_filetime_set(const FILETIME *ft);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
|
||||
std::string wchar_to_utf8_cstr(const wchar_t *str);
|
||||
|
||||
std::string unixify(const std::string &str);
|
||||
std::string extract_file_name(const std::string &str);
|
||||
std::string extract_dir_name(const std::string &str);
|
||||
|
||||
template<class T> void convertStatlikeBuf(const struct FUSE_STAT *stbuf, const std::string &name,
|
||||
T * find_data)
|
||||
{
|
||||
if (stbuf==nullptr) return;
|
||||
|
||||
if ((stbuf->st_mode&S_IFDIR)==S_IFDIR)
|
||||
find_data->dwFileAttributes=FILE_ATTRIBUTE_DIRECTORY;
|
||||
else
|
||||
find_data->dwFileAttributes=FILE_ATTRIBUTE_NORMAL;
|
||||
|
||||
#ifndef WIDE_OFF_T
|
||||
find_data->nFileSizeLow=stbuf->st_size;
|
||||
#else
|
||||
//Support 64 sizes
|
||||
find_data->nFileSizeLow=static_cast<DWORD>(stbuf->st_size);
|
||||
find_data->nFileSizeHigh=stbuf->st_size>>32;
|
||||
#endif
|
||||
if (stbuf->st_ctim.tv_sec!=0)
|
||||
find_data->ftCreationTime=unixTimeToFiletime(stbuf->st_ctim.tv_sec);
|
||||
if (stbuf->st_atim.tv_sec!=0)
|
||||
find_data->ftLastAccessTime=unixTimeToFiletime(stbuf->st_atim.tv_sec);
|
||||
if (stbuf->st_mtim.tv_sec!=0)
|
||||
find_data->ftLastWriteTime=unixTimeToFiletime(stbuf->st_mtim.tv_sec);
|
||||
|
||||
//Partial support for read-only files - currently done for a files without write permission only
|
||||
if (!(stbuf->st_mode&0222))
|
||||
find_data->dwFileAttributes|=FILE_ATTRIBUTE_READONLY;
|
||||
//TODO: add full support for read-only files - try to derive it from file's owner?
|
||||
std::string fname=extract_file_name(name);
|
||||
if (!fname.empty() && fname.at(0)=='.') //UNIX hidden files
|
||||
find_data->dwFileAttributes|=FILE_ATTRIBUTE_HIDDEN;
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
#endif // UTILS_H_
|
BIN
3rd_party/Dokan Library-1.0.2/lib/dokan1.lib
vendored
Normal file
BIN
3rd_party/Dokan Library-1.0.2/lib/dokan1.lib
vendored
Normal file
Binary file not shown.
BIN
3rd_party/Dokan Library-1.0.2/lib/dokanfuse1.lib
vendored
Normal file
BIN
3rd_party/Dokan Library-1.0.2/lib/dokanfuse1.lib
vendored
Normal file
Binary file not shown.
BIN
3rd_party/Dokan Library-1.0.2/lib/dokannp1.lib
vendored
Normal file
BIN
3rd_party/Dokan Library-1.0.2/lib/dokannp1.lib
vendored
Normal file
Binary file not shown.
BIN
3rd_party/Dokan Library-1.0.2/libdokanfuse1.dll
vendored
Normal file
BIN
3rd_party/Dokan Library-1.0.2/libdokanfuse1.dll
vendored
Normal file
Binary file not shown.
165
3rd_party/Dokan Library-1.0.2/license.lgpl.txt
vendored
Normal file
165
3rd_party/Dokan Library-1.0.2/license.lgpl.txt
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
20
3rd_party/Dokan Library-1.0.2/license.mit.txt
vendored
Normal file
20
3rd_party/Dokan Library-1.0.2/license.mit.txt
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
Copyright (C) 2015 - 2017 Adrien J. <liryna.stark@gmail.com> and Maxime C. <maxime@islog.com>
|
||||
Copyright (C) 2007 - 2011 Hiroki Asakawa <info@dokan-dev.net>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
BIN
3rd_party/Dokan Library-1.0.2/sample/fuse_mirror/cygdokanfuse1.dll
vendored
Normal file
BIN
3rd_party/Dokan Library-1.0.2/sample/fuse_mirror/cygdokanfuse1.dll
vendored
Normal file
Binary file not shown.
BIN
3rd_party/Dokan Library-1.0.2/sample/fuse_mirror/dokan1.dll
vendored
Normal file
BIN
3rd_party/Dokan Library-1.0.2/sample/fuse_mirror/dokan1.dll
vendored
Normal file
Binary file not shown.
424
3rd_party/Dokan Library-1.0.2/sample/fuse_mirror/fusexmp.c
vendored
Normal file
424
3rd_party/Dokan Library-1.0.2/sample/fuse_mirror/fusexmp.c
vendored
Normal file
@@ -0,0 +1,424 @@
|
||||
/*
|
||||
FUSE: Filesystem in Userspace
|
||||
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
|
||||
Copyright (C) 2011 Sebastian Pipping <sebastian@pipping.org>
|
||||
|
||||
This program can be distributed under the terms of the GNU GPL.
|
||||
See the file COPYING.
|
||||
*/
|
||||
|
||||
/** @file
|
||||
* @tableofcontents
|
||||
*
|
||||
* fusexmp.c - FUSE: Filesystem in Userspace
|
||||
*
|
||||
* \section section_compile compiling this example
|
||||
*
|
||||
* gcc -Wall fusexmp.c `pkg-config fuse3 --cflags --libs` -o fusexmp
|
||||
*
|
||||
* \section section_source the complete source
|
||||
* \include fusexmp.c
|
||||
*/
|
||||
|
||||
|
||||
#define FUSE_USE_VERSION 30
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef linux
|
||||
/* For pread()/pwrite()/utimensat() */
|
||||
#define _XOPEN_SOURCE 700
|
||||
#endif
|
||||
|
||||
#include <fuse.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#ifdef HAVE_SETXATTR
|
||||
#include <sys/xattr.h>
|
||||
#endif
|
||||
|
||||
static int xmp_getattr(const char *path, struct stat *stbuf)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = lstat(path, stbuf);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xmp_access(const char *path, int mask)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = access(path, mask);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xmp_readlink(const char *path, char *buf, size_t size)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = readlink(path, buf, size - 1);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
|
||||
buf[res] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
|
||||
off_t offset, struct fuse_file_info *fi)
|
||||
{
|
||||
DIR *dp;
|
||||
struct dirent *de;
|
||||
|
||||
(void) offset;
|
||||
(void) fi;
|
||||
|
||||
dp = opendir(path);
|
||||
if (dp == NULL)
|
||||
return -errno;
|
||||
|
||||
while ((de = readdir(dp)) != NULL) {
|
||||
struct stat st;
|
||||
memset(&st, 0, sizeof(st));
|
||||
st.st_ino = de->d_ino;
|
||||
st.st_mode = de->d_type << 12;
|
||||
if (filler(buf, de->d_name, &st, 0))
|
||||
break;
|
||||
}
|
||||
|
||||
closedir(dp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xmp_mknod(const char *path, mode_t mode, dev_t rdev)
|
||||
{
|
||||
int res;
|
||||
|
||||
/* On Linux this could just be 'mknod(path, mode, rdev)' but this
|
||||
is more portable */
|
||||
if (S_ISREG(mode)) {
|
||||
res = open(path, O_CREAT | O_EXCL | O_WRONLY, mode);
|
||||
if (res >= 0)
|
||||
res = close(res);
|
||||
} else if (S_ISFIFO(mode))
|
||||
res = mkfifo(path, mode);
|
||||
else
|
||||
res = mknod(path, mode, rdev);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xmp_mkdir(const char *path, mode_t mode)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = mkdir(path, mode);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xmp_unlink(const char *path)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = unlink(path);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xmp_rmdir(const char *path)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = rmdir(path);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xmp_symlink(const char *from, const char *to)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = symlink(from, to);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xmp_rename(const char *from, const char *to)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = rename(from, to);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xmp_link(const char *from, const char *to)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = link(from, to);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xmp_chmod(const char *path, mode_t mode)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = chmod(path, mode);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xmp_chown(const char *path, uid_t uid, gid_t gid)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = lchown(path, uid, gid);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xmp_truncate(const char *path, off_t size)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = truncate(path, size);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_UTIMENSAT
|
||||
static int xmp_utimens(const char *path, const struct timespec ts[2])
|
||||
{
|
||||
int res;
|
||||
|
||||
/* don't use utime/utimes since they follow symlinks */
|
||||
res = utimensat(0, path, ts, AT_SYMLINK_NOFOLLOW);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int xmp_open(const char *path, struct fuse_file_info *fi)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = open(path, fi->flags);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
|
||||
close(res);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xmp_read(const char *path, char *buf, size_t size, off_t offset,
|
||||
struct fuse_file_info *fi)
|
||||
{
|
||||
int fd;
|
||||
int res;
|
||||
|
||||
(void) fi;
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return -errno;
|
||||
|
||||
res = pread(fd, buf, size, offset);
|
||||
if (res == -1)
|
||||
res = -errno;
|
||||
|
||||
close(fd);
|
||||
return res;
|
||||
}
|
||||
|
||||
static int xmp_write(const char *path, const char *buf, size_t size,
|
||||
off_t offset, struct fuse_file_info *fi)
|
||||
{
|
||||
int fd;
|
||||
int res;
|
||||
|
||||
(void) fi;
|
||||
fd = open(path, O_WRONLY);
|
||||
if (fd == -1)
|
||||
return -errno;
|
||||
|
||||
res = pwrite(fd, buf, size, offset);
|
||||
if (res == -1)
|
||||
res = -errno;
|
||||
|
||||
close(fd);
|
||||
return res;
|
||||
}
|
||||
|
||||
static int xmp_statfs(const char *path, struct statvfs *stbuf)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = statvfs(path, stbuf);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xmp_release(const char *path, struct fuse_file_info *fi)
|
||||
{
|
||||
/* Just a stub. This method is optional and can safely be left
|
||||
unimplemented */
|
||||
|
||||
(void) path;
|
||||
(void) fi;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xmp_fsync(const char *path, int isdatasync,
|
||||
struct fuse_file_info *fi)
|
||||
{
|
||||
/* Just a stub. This method is optional and can safely be left
|
||||
unimplemented */
|
||||
|
||||
(void) path;
|
||||
(void) isdatasync;
|
||||
(void) fi;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_POSIX_FALLOCATE
|
||||
static int xmp_fallocate(const char *path, int mode,
|
||||
off_t offset, off_t length, struct fuse_file_info *fi)
|
||||
{
|
||||
int fd;
|
||||
int res;
|
||||
|
||||
(void) fi;
|
||||
|
||||
if (mode)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
fd = open(path, O_WRONLY);
|
||||
if (fd == -1)
|
||||
return -errno;
|
||||
|
||||
res = -posix_fallocate(fd, offset, length);
|
||||
|
||||
close(fd);
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SETXATTR
|
||||
/* xattr operations are optional and can safely be left unimplemented */
|
||||
static int xmp_setxattr(const char *path, const char *name, const char *value,
|
||||
size_t size, int flags)
|
||||
{
|
||||
int res = lsetxattr(path, name, value, size, flags);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xmp_getxattr(const char *path, const char *name, char *value,
|
||||
size_t size)
|
||||
{
|
||||
int res = lgetxattr(path, name, value, size);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int xmp_listxattr(const char *path, char *list, size_t size)
|
||||
{
|
||||
int res = llistxattr(path, list, size);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int xmp_removexattr(const char *path, const char *name)
|
||||
{
|
||||
int res = lremovexattr(path, name);
|
||||
if (res == -1)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
#endif /* HAVE_SETXATTR */
|
||||
|
||||
static struct fuse_operations xmp_oper = {
|
||||
.getattr = xmp_getattr,
|
||||
.access = xmp_access,
|
||||
.readlink = xmp_readlink,
|
||||
.readdir = xmp_readdir,
|
||||
.mknod = xmp_mknod,
|
||||
.mkdir = xmp_mkdir,
|
||||
.symlink = xmp_symlink,
|
||||
.unlink = xmp_unlink,
|
||||
.rmdir = xmp_rmdir,
|
||||
.rename = xmp_rename,
|
||||
.link = xmp_link,
|
||||
.chmod = xmp_chmod,
|
||||
.chown = xmp_chown,
|
||||
.truncate = xmp_truncate,
|
||||
#ifdef HAVE_UTIMENSAT
|
||||
.utimens = xmp_utimens,
|
||||
#endif
|
||||
.open = xmp_open,
|
||||
.read = xmp_read,
|
||||
.write = xmp_write,
|
||||
.statfs = xmp_statfs,
|
||||
.release = xmp_release,
|
||||
.fsync = xmp_fsync,
|
||||
#ifdef HAVE_POSIX_FALLOCATE
|
||||
.fallocate = xmp_fallocate,
|
||||
#endif
|
||||
#ifdef HAVE_SETXATTR
|
||||
.setxattr = xmp_setxattr,
|
||||
.getxattr = xmp_getxattr,
|
||||
.listxattr = xmp_listxattr,
|
||||
.removexattr = xmp_removexattr,
|
||||
#endif
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
umask(0);
|
||||
return fuse_main(argc, argv, &xmp_oper, NULL);
|
||||
}
|
BIN
3rd_party/Dokan Library-1.0.2/sample/fuse_mirror/mirror.exe
vendored
Normal file
BIN
3rd_party/Dokan Library-1.0.2/sample/fuse_mirror/mirror.exe
vendored
Normal file
Binary file not shown.
BIN
3rd_party/Dokan Library-1.0.2/sample/mirror/dokan1.dll
vendored
Normal file
BIN
3rd_party/Dokan Library-1.0.2/sample/mirror/dokan1.dll
vendored
Normal file
Binary file not shown.
28
3rd_party/Dokan Library-1.0.2/sample/mirror/dokan_mirror.sln
vendored
Normal file
28
3rd_party/Dokan Library-1.0.2/sample/mirror/dokan_mirror.sln
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dokan_mirror", "dokan_mirror.vcxproj", "{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}.Debug|x64.Build.0 = Debug|x64
|
||||
{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}.Debug|x86.Build.0 = Debug|Win32
|
||||
{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}.Release|x64.ActiveCfg = Release|x64
|
||||
{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}.Release|x64.Build.0 = Release|x64
|
||||
{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}.Release|x86.ActiveCfg = Release|Win32
|
||||
{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
179
3rd_party/Dokan Library-1.0.2/sample/mirror/dokan_mirror.vcxproj
vendored
Normal file
179
3rd_party/Dokan Library-1.0.2/sample/mirror/dokan_mirror.vcxproj
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{DADCBCAD-4429-422E-9FA9-D8E538D0EF94}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>mirror</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<TargetName>mirror</TargetName>
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<TargetName>mirror</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<TargetName>mirror</TargetName>
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(Platform)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<TargetName>mirror</TargetName>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<AdditionalIncludeDirectories>../../sys;</AdditionalIncludeDirectories>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>../debug</AdditionalLibraryDirectories>
|
||||
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
|
||||
<AdditionalDependencies>ntdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<AdditionalIncludeDirectories>../../sys;</AdditionalIncludeDirectories>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>../debug</AdditionalLibraryDirectories>
|
||||
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
|
||||
<AdditionalDependencies>ntdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>../../sys;</AdditionalIncludeDirectories>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
|
||||
<AdditionalDependencies>ntdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>../../sys;</AdditionalIncludeDirectories>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
|
||||
<AdditionalDependencies>ntdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="mirror.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\dokan\dokan.vcxproj">
|
||||
<Project>{f25ba22f-2ab8-4859-9b89-8fe1e774b472}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
1557
3rd_party/Dokan Library-1.0.2/sample/mirror/mirror.c
vendored
Normal file
1557
3rd_party/Dokan Library-1.0.2/sample/mirror/mirror.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
3rd_party/Dokan Library-1.0.2/sample/mirror/mirror.exe
vendored
Normal file
BIN
3rd_party/Dokan Library-1.0.2/sample/mirror/mirror.exe
vendored
Normal file
Binary file not shown.
4
3rd_party/Sia-v1.1.1-windows-amd64/01 - siad test.cmd
vendored
Normal file
4
3rd_party/Sia-v1.1.1-windows-amd64/01 - siad test.cmd
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
@echo off
|
||||
pushd "%~dp0%"
|
||||
|
||||
siad -d .\data
|
21
3rd_party/Sia-v1.1.1-windows-amd64/LICENSE
vendored
Normal file
21
3rd_party/Sia-v1.1.1-windows-amd64/LICENSE
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Nebulous Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
108
3rd_party/Sia-v1.1.1-windows-amd64/README.md
vendored
Normal file
108
3rd_party/Sia-v1.1.1-windows-amd64/README.md
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
# [](http://sia.tech) v1.1.1 (Andromeda)
|
||||
=========
|
||||
|
||||
[](https://travis-ci.org/NebulousLabs/Sia)
|
||||
[](https://godoc.org/github.com/NebulousLabs/Sia)
|
||||
[](https://goreportcard.com/report/github.com/NebulousLabs/Sia)
|
||||
|
||||
Sia is a new decentralized cloud storage platform that radically alters the
|
||||
landscape of cloud storage. By leveraging smart contracts, client-side
|
||||
encryption, and sophisticated redundancy (via Reed-Solomon codes), Sia allows
|
||||
users to safely store their data with hosts that they do not know or trust.
|
||||
The result is a cloud storage marketplace where hosts compete to offer the
|
||||
best service at the lowest price. And since there is no barrier to entry for
|
||||
hosts, anyone with spare storage capacity can join the network and start
|
||||
making money.
|
||||
|
||||

|
||||
|
||||
Traditional cloud storage has a number of shortcomings. Users are limited to a
|
||||
few big-name offerings: Google, Microsoft, Amazon. These companies have little
|
||||
incentive to encrypt your data or make it easy to switch services later. Their
|
||||
code is closed-source, and they can lock you out of your account at any time.
|
||||
|
||||
We believe that users should own their data. Sia achieves this by replacing
|
||||
the traditional monolithic cloud storage provider with a blockchain and a
|
||||
swarm of hosts, each of which stores an encrypted fragment of your data. Since
|
||||
the fragments are redundant, no single host can hold your data hostage: if
|
||||
they jack up their price or go offline, you can simply download from a
|
||||
different host. In other words, trust is removed from the equation, and
|
||||
switching to a different host is painless. Stripped of these unfair
|
||||
advantages, hosts must compete solely on the quality and price of the storage
|
||||
they provide.
|
||||
|
||||
Sia can serve as a replacement for personal backups, bulk archiving, content
|
||||
distribution, and more. For developers, Sia is a low-cost alternative to
|
||||
Amazon S3. Storage on Sia is a full order of magnitude cheaper than on S3,
|
||||
with comparable bandwidth, latency, and durability. Sia works best for static
|
||||
content, especially media like videos, music, and photos.
|
||||
|
||||
Distributing data across many hosts automatically confers several advantages.
|
||||
The most obvious is that, just like BitTorrent, uploads and downloads are
|
||||
highly parallel. Given enough hosts, Sia can saturate your bandwidth. Another
|
||||
advantage is that your data is spread across a wide geographic area, reducing
|
||||
latency and safeguarding your data against a range of attacks.
|
||||
|
||||
It is important to note that users have full control over which hosts they
|
||||
use. You can tailor your host set for minimum latency, lowest price, widest
|
||||
geographic coverage, or even a strict whitelist of IP addresses or public
|
||||
keys.
|
||||
|
||||
At the core of Sia is a blockchain that closely resembles Bitcoin.
|
||||
Transactions are conducted in Siacoin, a cryptocurrency. The blockchain is
|
||||
what allows Sia to enforce its smart contracts without relying on centralized
|
||||
authority. To acquire siacoins, use an exchange such as [Poloniex](https://poloniex.com), [Yunbi](https://yunbi.com), or
|
||||
[Bitsquare](https://bitsquare.io).
|
||||
|
||||
To get started with Sia, check out the guides below:
|
||||
|
||||
- [How to Store Data on Sia](https://blog.sia.tech/getting-started-with-private-decentralized-cloud-storage-c9565dc8c854)
|
||||
- [How to Become a Sia Host](https://blog.sia.tech/how-to-run-a-host-on-sia-2159ebc4725)
|
||||
- [Using the Sia API](https://blog.sia.tech/api-quickstart-guide-f1d160c05235)
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
Sia is ready for use with small sums of money and non-critical files, but
|
||||
until the network has a more proven track record, we advise against using it
|
||||
as a sole means of storing important data.
|
||||
|
||||
This release comes with 2 binaries, siad and siac. siad is a background
|
||||
service, or "daemon," that runs the Sia protocol and exposes an HTTP API on
|
||||
port 9980. siac is a command-line client that can be used to interact with
|
||||
siad in a user-friendly way. There is also a graphical client, [Sia-UI](https://github.com/NebulousLabs/Sia-UI), which
|
||||
is the preferred way of using Sia for most users. For interested developers,
|
||||
the siad API is documented [here](doc/API.md).
|
||||
|
||||
siad and siac are run via command prompt. On Windows, you can just double-
|
||||
click siad.exe if you don't need to specify any command-line arguments.
|
||||
Otherwise, navigate to its containing folder and click File->Open command
|
||||
prompt. Then, start the siad service by entering `siad` and pressing Enter.
|
||||
The command prompt may appear to freeze; this means siad is waiting for
|
||||
requests. Windows users may see a warning from the Windows Firewall; be sure
|
||||
to check both boxes ("Private networks" and "Public networks") and click
|
||||
"Allow access." You can now run `siac` (in a separate command prompt) or Sia-
|
||||
UI to interact with siad. From here, you can send money, upload and download
|
||||
files, and advertise yourself as a host.
|
||||
|
||||
Building From Source
|
||||
--------------------
|
||||
|
||||
To build from source, [Go 1.7 must be installed](https://golang.org/doc/install)
|
||||
on the system. Then simply use `go get`:
|
||||
|
||||
```
|
||||
go get -u github.com/NebulousLabs/Sia/...
|
||||
```
|
||||
|
||||
This will download the Sia repo to your `$GOPATH/src` folder, and install the
|
||||
`siad` and `siac` binaries in your `$GOPATH/bin` folder.
|
||||
|
||||
To stay up-to-date, run the previous `go get` command again. Alternatively, you
|
||||
can use the Makefile provided in this repo. Run `git pull origin master` to
|
||||
pull the latest changes, and `make release-std` to build the new binaries. You
|
||||
can also run `make test` and `make test-long` to run the short and full test
|
||||
suites, respectively. Finally, `make cover` will generate code coverage reports
|
||||
for each package; they are stored in the `cover` folder and can be viewed in
|
||||
your browser.
|
1217
3rd_party/Sia-v1.1.1-windows-amd64/doc/API.md
vendored
Normal file
1217
3rd_party/Sia-v1.1.1-windows-amd64/doc/API.md
vendored
Normal file
File diff suppressed because it is too large
Load Diff
399
3rd_party/Sia-v1.1.1-windows-amd64/doc/Consensus.md
vendored
Normal file
399
3rd_party/Sia-v1.1.1-windows-amd64/doc/Consensus.md
vendored
Normal file
@@ -0,0 +1,399 @@
|
||||
Consensus Rules
|
||||
===============
|
||||
|
||||
This document is meant to provide a good high level overview of the Sia
|
||||
cryptosystem, but does not fully explain all of the small details. The most
|
||||
accurate explanation of the consensus rules is the consensus package (and all
|
||||
dependencies).
|
||||
|
||||
This document will be more understandable if you have a general understanding
|
||||
of proof of work blockchains, and does not try to build up from first
|
||||
principles.
|
||||
|
||||
Cryptographic Algorithms
|
||||
------------------------
|
||||
|
||||
Sia uses cryptographic hashing and cryptographic signing, each of which has
|
||||
many potentially secure algorithms that can be used. We acknowledge our
|
||||
inexperience, and that we have chosen these algorithms not because of our own
|
||||
confidence in their properties, but because other people seem confident in
|
||||
their properties.
|
||||
|
||||
For hashing, our primary goal is to use an algorithm that cannot be merge mined
|
||||
with Bitcoin, even partially. A secondary goal is hashing speed on consumer
|
||||
hardware, including phones and other low power devices.
|
||||
|
||||
For signing, our primary goal is verification speed. A secondary goal is an
|
||||
algorithm that supports HD keys. A tertiary goal is an algorithm that supports
|
||||
threshold signatures.
|
||||
|
||||
#### Hashing: blake2b
|
||||
|
||||
[blake2b](http://en.wikipedia.org/wiki/BLAKE_%28hash_function%29#BLAKE2 "Wiki page") has been chosen as a hashing algorithm because it is fast, it has had
|
||||
substantial review, and it has invulnerability to length extension attacks.
|
||||
Another particularly important feature of BLAKE2b is that it is not SHA-2. We
|
||||
wish to avoid merge mining with Bitcoin, because that may result in many
|
||||
apathetic Bitcoin miners mining on our blockchain, which may make soft forks
|
||||
harder to coordinate.
|
||||
|
||||
#### Signatures: variable type signatures
|
||||
|
||||
Each public key will have an specifier (a 16 byte array) and a byte slice
|
||||
containing an encoding of the public key. The specifier will tell the
|
||||
signature verification which signing algorithm to use when verifying a
|
||||
signature. Each signature will be a byte slice, the encoding can be
|
||||
determined by looking at the specifier of the corresponding public key.
|
||||
|
||||
This method allows new signature types to be easily added to the currency in
|
||||
a way that does not invalidate existing outputs and keys. Adding a new
|
||||
signature type requires a hard fork, but allows easy protection against
|
||||
cryptographic breaks, and easy migration to new cryptography if there are any
|
||||
breakthroughs in areas like verification speed, ring signatures, etc.
|
||||
|
||||
Allowed algorithms:
|
||||
|
||||
ed25519: The specifier must match the string "ed25519". The public key
|
||||
must be encoded into 32 bytes. Signatures and public keys will need to
|
||||
follow the ed25519 specification. More information can be found at
|
||||
ed25519.cr.yp.to
|
||||
|
||||
entropy: The specifier must match the string "entropy". The signature will
|
||||
always be invalid. This provides a way to add entropy buffers to
|
||||
SpendCondition objects to protect low entropy information, while being able
|
||||
to prove that the entropy buffers are invalid public keys.
|
||||
|
||||
There are plans to also add ECDSA secp256k1 and Schnorr secp256k1. New
|
||||
signing algorithms can be added to Sia through a soft fork, because
|
||||
unrecognized algorithm types are always considered to have valid signatures.
|
||||
|
||||
Currency
|
||||
--------
|
||||
|
||||
The Sia cryptosystem has two types of currency. The first is the Siacoin.
|
||||
Siacoins are generated every block and distributed to the miners. These miners
|
||||
can then use the siacoins to fund file contracts, or can send the siacoins to
|
||||
other parties. The siacoin is represented by an infinite precision unsigned
|
||||
integer.
|
||||
|
||||
The second currency in the Sia cryptosystem is the Siafund, which is a special
|
||||
asset limited to 10,000 indivisible units. Each time a file contract payout is
|
||||
made, 3.9% of the payout is put into the siafund pool. The number of siacoins
|
||||
in the siafund pool must always be divisible by 10,000; the number of coins
|
||||
taken from the payout is rounded down to the nearest 10,000. The siafund is
|
||||
also represented by an infinite precision unsigned integer.
|
||||
|
||||
Siafund owners can collect the siacoins in the siafund pool. For every 10,000
|
||||
siacoins added to the siafund pool, a siafund owner can withdraw 1 siacoin.
|
||||
Approx. 8790 siafunds are owned by Nebulous Inc. The remaining siafunds are
|
||||
owned by early backers of the Sia project.
|
||||
|
||||
There are future plans to enable sidechain compatibility with Sia. This would
|
||||
allow other currencies such as Bitcoin to be spent in all the same places that
|
||||
the Siacoin can be spent.
|
||||
|
||||
Marshalling
|
||||
-----------
|
||||
|
||||
Many of the Sia types need to be hashed at some point, which requires having a
|
||||
consistent algorithm for marshalling types into a set of bytes that can be
|
||||
hashed. The following rules are used for hashing:
|
||||
|
||||
- Integers are little-endian, and are always encoded as 8 bytes.
|
||||
- Bools are encoded as one byte, where zero is false and one is true.
|
||||
- Variable length types such as strings are prefaced by 8 bytes containing
|
||||
their length.
|
||||
- Arrays and structs are encoded as their individual elements concatenated
|
||||
together. The ordering of the struct is determined by the struct definition.
|
||||
There is only one way to encode each struct.
|
||||
- The Currency type (an infinite precision integer) is encoded in big endian
|
||||
using as many bytes as necessary to represent the underlying number. As it
|
||||
is a variable length type, it is prefixed by 8 bytes containing the length.
|
||||
|
||||
Block Size
|
||||
----------
|
||||
|
||||
The maximum block size is 2e6 bytes. There is no limit on transaction size,
|
||||
though it must fit inside of the block. Most miners enforce a size limit of
|
||||
16e3 bytes per transaction.
|
||||
|
||||
Block Timestamps
|
||||
----------------
|
||||
|
||||
Each block has a minimum allowed timestamp. The minimum timestamp is found by
|
||||
taking the median timestamp of the previous 11 blocks. If there are not 11
|
||||
previous blocks, the genesis timestamp is used repeatedly.
|
||||
|
||||
Blocks will be rejected if they are timestamped more than three hours in the
|
||||
future, but can be accepted again once enough time has passed.
|
||||
|
||||
Block ID
|
||||
--------
|
||||
|
||||
The ID of a block is derived using:
|
||||
Hash(Parent Block ID + 64 bit Nonce + Block Merkle Root)
|
||||
|
||||
The block Merkle root is obtained by creating a Merkle tree whose leaves are
|
||||
the hash of the timestamp, the hashes of the miner outputs (one leaf per miner
|
||||
output), and the hashes of the transactions (one leaf per transaction).
|
||||
|
||||
Block Target
|
||||
------------
|
||||
|
||||
For a block to be valid, the id of the block must be below a certain target.
|
||||
The target is adjusted once every 500 blocks, and it is adjusted by looking at
|
||||
the timestamps of the previous 1000 blocks. The expected amount of time passed
|
||||
between the most recent block and the 1000th previous block is 10e3 minutes. If
|
||||
more time has passed, the target is lowered. If less time has passed, the
|
||||
target is increased. Each adjustment can adjust the target by up to 2.5x.
|
||||
|
||||
The target is changed in proportion to the difference in time (If the time was
|
||||
half of what was expected, the new target is 1/2 the old target). There is a
|
||||
clamp on the adjustment. In one block, the target cannot adjust upwards by more
|
||||
more than 1001/1000, and cannot adjust downwards by more than 999/1000.
|
||||
|
||||
The new target is calculated using (expected time passed in seconds) / (actual
|
||||
time passed in seconds) * (current target). The division and multiplication
|
||||
should be done using infinite precision, and the result should be truncated.
|
||||
|
||||
If there are not 1000 blocks, the genesis timestamp is used for comparison.
|
||||
The expected time is (10 minutes * block height).
|
||||
|
||||
Block Subsidy
|
||||
-------------
|
||||
|
||||
The coinbase for a block is (300,000 - height) * 10^24, with a minimum of
|
||||
30,000 \* 10^24. Any miner fees get added to the coinbase to create the block
|
||||
subsidy. The block subsidy is then given to multiple outputs, called the miner
|
||||
payouts. The total value of the miner payouts must equal the block subsidy.
|
||||
|
||||
The ids of the outputs created by the miner payouts is determined by taking the
|
||||
block id and concatenating the index of the payout that the output corresponds
|
||||
to.
|
||||
|
||||
The outputs created by the block subsidy cannot be spent for 50 blocks, and are
|
||||
not considered a part of the consensus set until 50 blocks have transpired.
|
||||
This limitation is in place because a simple blockchain reorganization is
|
||||
enough to invalidate the output; double spend attacks and false spend attacks
|
||||
are much easier to execute.
|
||||
|
||||
Transactions
|
||||
------------
|
||||
|
||||
A Transaction is composed of the following:
|
||||
|
||||
- Siacoin Inputs
|
||||
- Siacoin Outputs
|
||||
- File Contracts
|
||||
- File Contract Revisions
|
||||
- Storage Proofs
|
||||
- Siafund Inputs
|
||||
- Siafund Outputs
|
||||
- Miner Fees
|
||||
- Arbitrary Data
|
||||
- Transaction Signatures
|
||||
|
||||
The sum of all the siacoin inputs must equal the sum of all the miner fees,
|
||||
siacoin outputs, and file contract payouts. There can be no leftovers. The sum
|
||||
of all siafund inputs must equal the sum of all siafund outputs.
|
||||
|
||||
Several objects have unlock hashes. An unlock hash is the Merkle root of the
|
||||
'unlock conditions' object. The unlock conditions contain a timelock, a number
|
||||
of required signatures, and a set of public keys that can be used during
|
||||
signing.
|
||||
|
||||
The Merkle root of the unlock condition objects is formed by taking the Merkle
|
||||
root of a tree whose leaves are the timelock, the public keys (one leaf per
|
||||
key), and the number of signatures. This ordering is chosen specifically
|
||||
because the timelock and the number of signatures are low entropy. By using
|
||||
random data as the first and last public key, you can make it safe to reveal
|
||||
any of the public keys without revealing the low entropy items.
|
||||
|
||||
The unlock conditions cannot be satisfied until enough signatures have
|
||||
provided, and until the height of the blockchain is at least equal to the value
|
||||
of the timelock.
|
||||
|
||||
The unlock conditions contains a set of public keys which can each be used only
|
||||
once when providing signatures. The same public key can be listed twice, which
|
||||
means that it can be used twice. The number of required signatures indicates
|
||||
how many public keys must be used to validate the input. If required signatures
|
||||
is '0', the input is effectively 'anyone can spend'. If the required signature
|
||||
count is greater than the number of public keys, the input is unspendable.
|
||||
There must be exactly enough signatures. For example, if there are 3 public
|
||||
keys and only two required signatures, then only two signatures can be included
|
||||
into the transaction.
|
||||
|
||||
Siacoin Inputs
|
||||
--------------
|
||||
|
||||
Each input spends an output. The output being spent must exist in the consensus
|
||||
set. The 'value' field of the output indicates how many siacoins must be used
|
||||
in the outputs of the transaction. Valid outputs are miner fees, siacoin
|
||||
outputs, and contract payouts.
|
||||
|
||||
Siacoin Outputs
|
||||
---------------
|
||||
|
||||
Siacoin outputs contain a value and an unlock hash (also called a coin
|
||||
address). The unlock hash is the Merkle root of the spend conditions that must
|
||||
be met to spend the output.
|
||||
|
||||
File Contracts
|
||||
--------------
|
||||
|
||||
A file contract is an agreement by some party to prove they have a file at a
|
||||
given point in time. The contract contains the Merkle root of the data being
|
||||
stored, and the size in bytes of the data being stored.
|
||||
|
||||
The Merkle root is formed by breaking the file into 64 byte segments and
|
||||
hashing each segment to form the leaves of the Merkle tree. The final segment
|
||||
is not padded out.
|
||||
|
||||
The storage proof must be submitted between the 'WindowStart' and 'WindowEnd'
|
||||
fields of the contract. There is a 'Payout', which indicates how many siacoins
|
||||
are given out when the storage proof is provided. 3.9% of this payout (rounded
|
||||
down to the nearest 10,000) is put aside for the owners of siafunds. If the
|
||||
storage proof is provided and is valid, the remaining payout is put in an
|
||||
output spendable by the 'valid proof spend hash', and if a valid storage proof
|
||||
is not provided to the blockchain by 'end', the remaining payout is put in an
|
||||
output spendable by the 'missed proof spend hash'.
|
||||
|
||||
All contracts must have a non-zero payout, 'start' must be before 'end', and
|
||||
'start' must be greater than the current height of the blockchain. A storage
|
||||
proof is acceptable if it is submitted in the block of height 'end'.
|
||||
|
||||
File contracts are created with a 'Revision Hash', which is the Merkle root of
|
||||
an unlock conditions object. A 'file contract revision' can be submitted which
|
||||
fulfills the unlock conditions object, resulting in the file contract being
|
||||
replaced by a new file contract, as specified in the revision.
|
||||
|
||||
File Contract Revisions
|
||||
-----------------------
|
||||
|
||||
A file contract revision modifies a contract. File contracts have a revision
|
||||
number, and any revision submitted to the blockchain must have a higher
|
||||
revision number in order to be valid. Any field can be changed except for the
|
||||
payout - siacoins cannot be added to or removed from the file contract during a
|
||||
revision, though the destination upon a successful or unsuccessful storage
|
||||
proof can be changed.
|
||||
|
||||
The greatest application for file contract revisions is file-diff channels - a
|
||||
file contract can be edited many times off-blockchain as a user uploads new or
|
||||
different content to the host. This improves the overall scalability of Sia.
|
||||
|
||||
Storage Proofs
|
||||
--------------
|
||||
|
||||
A storage proof transaction is any transaction containing a storage proof.
|
||||
Storage proof transactions are not allowed to have siacoin or siafund outputs,
|
||||
and are not allowed to have file contracts.
|
||||
|
||||
When creating a storage proof, you only prove that you have a single 64 byte
|
||||
segment of the file. The piece that you must prove you have is chosen
|
||||
randomly using the contract id and the id of the 'trigger block'. The
|
||||
trigger block is the block at height 'Start' - 1, where 'Start' is the value
|
||||
'Start' in the contract that the storage proof is fulfilling.
|
||||
|
||||
The file is composed of 64 byte segments whose hashes compose the leaves of a
|
||||
Merkle tree. When proving you have the file, you must prove you have one of the
|
||||
leaves. To determine which leaf, take the hash of the contract id concatenated
|
||||
to the trigger block id, then take the numerical value of the result modulus
|
||||
the number of segments:
|
||||
|
||||
Hash(file contract id + trigger block id) % num segments
|
||||
|
||||
The proof is formed by providing the 64 byte segment, and then the missing
|
||||
hashes required to fill out the remaining tree. The total size of the proof
|
||||
will be 64 bytes + 32 bytes * log(num segments), and can be verified by anybody
|
||||
who knows the root hash and the file size.
|
||||
|
||||
Storage proof transactions are not allowed to have siacoin outputs, siafund
|
||||
outputs, or contracts. All outputs created by the storage proofs cannot be
|
||||
spent for 50 blocks.
|
||||
|
||||
These limits are in place because a simple blockchain reorganization can change
|
||||
the trigger block, which will invalidate the storage proof and therefore the
|
||||
entire transaction. This makes double spend attacks and false spend attacks
|
||||
significantly easier to execute.
|
||||
|
||||
Siafund Inputs
|
||||
--------------
|
||||
|
||||
A siafund input works similar to a siacoin input. It contains the id of a
|
||||
siafund output being spent, and the unlock conditions required to spend the
|
||||
output.
|
||||
|
||||
A special output is created when a siafund output is used as input. All of the
|
||||
siacoins that have accrued in the siafund since its last spend are sent to the
|
||||
'claim spend hash' found in the siafund output, which is a normal siacoin
|
||||
address. The value of the siacoin output is determined by taking the size of
|
||||
the siacoin pool when the output was created and comparing it to the current
|
||||
size of the siacoin pool. The equation is:
|
||||
|
||||
((Current Pool Size - Previous Pool Size) / 10,000) * siafund quantity
|
||||
|
||||
Like the miner outputs and the storage proof outputs, the siafund output cannot
|
||||
be spent for 50 blocks because the value of the output can change if the
|
||||
blockchain reorganizes. Reorganizations will not however cause the transaction
|
||||
to be invalidated, so the ban on contracts and outputs does not need to be in
|
||||
place.
|
||||
|
||||
Siafund Outputs
|
||||
---------------
|
||||
|
||||
Like siacoin outputs, siafund outputs contain a value and an unlock hash. The
|
||||
value indicates the number of siafunds that are put into the output, and the
|
||||
unlock hash is the Merkle root of the unlock conditions object which allows the
|
||||
output to be spent.
|
||||
|
||||
Siafund outputs also contain a claim unlock hash field, which indicates the
|
||||
unlock hash of the siacoin output that is created when the siafund output is
|
||||
spent. The value of the output that gets created will depend on the growth of
|
||||
the siacoin pool between the creation and the spending of the output. This
|
||||
growth is measured by storing a 'claim start', which indicates the size of the
|
||||
siafund pool at the moment the siafund output was created.
|
||||
|
||||
Miner Fees
|
||||
----------
|
||||
|
||||
A miner fee is a volume of siacoins that get added to the block subsidy.
|
||||
|
||||
Arbitrary Data
|
||||
--------------
|
||||
|
||||
Arbitrary data is a set of data that is ignored by consensus. In the future, it
|
||||
may be used for soft forks, paired with 'anyone can spend' transactions. In the
|
||||
meantime, it is an easy way for third party applications to make use of the
|
||||
siacoin blockchain.
|
||||
|
||||
Transaction Signatures
|
||||
----------------------
|
||||
|
||||
Each signature points to a single public key index in a single unlock
|
||||
conditions object. No two signatures can point to the same public key index for
|
||||
the same set of unlock conditions.
|
||||
|
||||
Each signature also contains a timelock, and is not valid until the blockchain
|
||||
has reached a height equal to the timelock height.
|
||||
|
||||
Signatures also have a 'covered fields' object, which indicates which parts of
|
||||
the transaction get included in the signature. There is a 'whole transaction'
|
||||
flag, which indicates that every part of the transaction except for the
|
||||
signatures gets included, which eliminates any malleability outside of the
|
||||
signatures. The signatures can also be individually included, to enforce that
|
||||
your signature is only valid if certain other signatures are present.
|
||||
|
||||
If the 'whole transaction' is not set, all fields need to be added manually,
|
||||
and additional parties can add new fields, meaning the transaction will be
|
||||
malleable. This does however allow other parties to add additional inputs,
|
||||
fees, etc. after you have signed the transaction without invalidating your
|
||||
signature. If the whole transaction flag is set, all other elements in the
|
||||
covered fields object must be empty except for the signatures field.
|
||||
|
||||
The covered fields object contains a slice of indexes for each element of the
|
||||
transaction (siacoin inputs, miner fees, etc.). The slice must be sorted, and
|
||||
there can be no repeated elements.
|
||||
|
||||
Entirely nonmalleable transactions can be achieved by setting the 'whole
|
||||
transaction' flag and then providing the last signature, including every other
|
||||
signature in your signature. Because no frivolous signatures are allowed, the
|
||||
transaction cannot be changed without your signature being invalidated.
|
239
3rd_party/Sia-v1.1.1-windows-amd64/doc/Developers.md
vendored
Normal file
239
3rd_party/Sia-v1.1.1-windows-amd64/doc/Developers.md
vendored
Normal file
@@ -0,0 +1,239 @@
|
||||
Developer Environment
|
||||
=====================
|
||||
|
||||
Sia is written in Go. To build and test Sia, you are going to need a working go
|
||||
environment, including having both $GOROOT/bin and $GOPATH/bin in your $PATH.
|
||||
For most Linux distributions, Go will be in the package manager, though it may
|
||||
be an old version that is incompatible with Sia. Once you have a working Go
|
||||
environment, you are set to build the project. If you plan on cross compiling
|
||||
Sia, you may need to install Go from source. You can find information on that
|
||||
[here](http://golang.org/doc/install/source).
|
||||
|
||||
Sia has has a development build, an automated testing build, and a release
|
||||
build. The release build is the only one that can synchronize to the full
|
||||
network. To get the release build, it is usually sufficient to run `go get -u
|
||||
github.com/NebulousLabs/Sia/...`. This will download Sia and its dependencies
|
||||
and install binaries in $GOPATH/bin.
|
||||
|
||||
After downloading, you can find the Sia source code in
|
||||
$GOPATH/src/github.com/NebulousLabs/Sia. To build the release binary, run
|
||||
`make release-std` from this directory. To build the release binary with a
|
||||
(slow) race detector and an array of debugging asserts, run `make release`. To
|
||||
build the developer binary (which has a different genesis block, faster block
|
||||
times, and a few other tweaks), just run `make`.
|
||||
|
||||
If you intend to contribute to Sia, you should start by forking the project on
|
||||
GitHub, and then adding your fork as a "remote" in the Sia git repository via
|
||||
`git remote add [fork name] [fork url]`. Now you can develop by pulling changes
|
||||
from `origin`, pushing your modifications to `[fork name]`, and then making a
|
||||
pull request on GitHub.
|
||||
|
||||
If you see an error like the one below, it means that you either forgot to run
|
||||
`make dependencies`, or you cloned the project into a path that the go tool
|
||||
does not recognize (usually the wrong path, or symbolic links were somehow
|
||||
involved).
|
||||
|
||||
```
|
||||
consensus/fork.go:4:2: cannot find package "github.com/NebulousLabs/Sia/crypto" in any of:
|
||||
/usr/lib/go/src/github.com/NebulousLabs/Sia/crypto (from $GOROOT)
|
||||
/home/user/gopath/src/github.com/NebulousLabs/Sia/crypto (from $GOPATH)
|
||||
```
|
||||
|
||||
Developer Conventions
|
||||
=====================
|
||||
|
||||
This file is meant to help a developer navigate the codebase and develop clean,
|
||||
maintainable code. Knowing all of these conventions will also make it easier to
|
||||
read and code review the Sia project.
|
||||
|
||||
The primary purpose of the conventions within Sia is to keep the codebase
|
||||
simple. Simpler constructions means easier code reviews, greater accessibility
|
||||
to newcomers, and less potential for mistakes. It is also to keep things
|
||||
uniform, much in the spirit of 'go fmt'. When everything looks the same,
|
||||
everyone has an easier time reading and reviewing code they did not write
|
||||
themselves.
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
All structs, functions, and interfaces must have a docstring.
|
||||
|
||||
Anytime that something is left unfinished, place a comment containing the
|
||||
string 'TODO:'. This sends a clear message to other developers, and creates a
|
||||
greppable way to find unfinished parts of the codebase. 'TODO' statements are
|
||||
currently discouraged. As the codebase matures, 'TODO' statements will become
|
||||
increasingly frowned upon. 'TODO' statements should not document feature
|
||||
requests, but instead document incompleteness where the incompleteness causes
|
||||
disruption to user experience or causes a security vulnerability.
|
||||
|
||||
Documentation should give a sense of what each function does, but should also
|
||||
give a sense of the overall architecture of the code. Where useful, examples
|
||||
should be provided, and common pitfalls should be explained. Anything that
|
||||
breaks other conventions in any way needs to have a comment, even if it is
|
||||
obvious why the convention had to be broken.
|
||||
|
||||
The goal of the codebase is to be accessible to newbies. Anything more advanced
|
||||
than what you would expect to remember from an 'Intro to Data Structures' class
|
||||
should have an explanation about what the concept it is and why it was picked
|
||||
over other potential choices.
|
||||
|
||||
Code that exists purely to be compatible with previous versions of the
|
||||
software should be tagged with a 'COMPATvX.X.X' comment. Examples below.
|
||||
|
||||
```go
|
||||
// Find and sort the outputs.
|
||||
outputs := getOutputs()
|
||||
// TODO: actually sort the outputs.
|
||||
```
|
||||
|
||||
```go
|
||||
// Disallow unknown agents.
|
||||
//
|
||||
// COMPATv0.4.0: allow a blank agent to preserve compatibility with
|
||||
// 'siac' v0.4.0, which did not set an agent.
|
||||
if agent != "SiaAgent" && agent != "" {
|
||||
return errors.New("unrecognized agent!")
|
||||
}
|
||||
```
|
||||
|
||||
Naming
|
||||
------
|
||||
|
||||
Names are used to give readers and reviewers a sense of what is happening in
|
||||
the code. When naming variables, you should assume that the person reading your
|
||||
code is unfamiliar with the codebase. Short names (like 'cs' instead of
|
||||
'consensusSet') should only be used when the context is immediately obvious.
|
||||
For example 'cs := new(ConsensusSet)' is immediately obvious context for 'cs',
|
||||
and so 'cs' is appropriate for the rest of the function.
|
||||
|
||||
Data structures should never have shortened names. 'FileContract.mr' is
|
||||
confusing to anyone who has not used the data structure extensively. The code
|
||||
should be accessible to people who are unfamiliar with the codebase. One
|
||||
exception is for the variable called 'mu', which is short for 'mutex'. This
|
||||
exception is made because 'mu' appears in many data structures.
|
||||
|
||||
When calling functions with obscure parameters, named variables should be used
|
||||
to indicate what the parameters do. For example, 'm := NewMiner(1)' is
|
||||
confusing. Instead, use 'threads := 1; m := NewMiner(threads)'. The name gives
|
||||
readers a sense of what the parameter within 'NewMiner' does even when they are
|
||||
not familiar with the 'NewMiner' function. Where possible, functions with
|
||||
obscure, untyped inputs should be avoided.
|
||||
|
||||
The most important thing to remember when choosing names is to cater to people
|
||||
who are unfamiliar with the code. A reader should never have to ask 'What is
|
||||
`cs`?' on their first pass through the code, even though to experienced
|
||||
developers it is obvious that `cs` refers to a consensus.ConsensusSet.
|
||||
|
||||
Control Flow
|
||||
------------
|
||||
|
||||
Where possible, control structures should be minimized or avoided. This
|
||||
includes avoiding nested if statements, and avoiding else statements where
|
||||
possible. Sometimes, complex control structures are necessary, but where
|
||||
possible use alternative code patterns and insert functions to break things up.
|
||||
|
||||
Example:
|
||||
|
||||
```go
|
||||
// Do not do this:
|
||||
if err != nil {
|
||||
return
|
||||
} else {
|
||||
forkBlockchain(node)
|
||||
}
|
||||
|
||||
// Instead to this:
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
forkBlockchain(node)
|
||||
```
|
||||
|
||||
Mutexes
|
||||
-------
|
||||
|
||||
All exported functions from a package and/or object need to be thread safe.
|
||||
Usually, this means that the first lines of the function contain a `Lock();
|
||||
defer Unlock()`. Simple locking schemes should be preferred over performant
|
||||
locking schemes. As will everything else, anything unusual or convention
|
||||
breaking should have a comment.
|
||||
|
||||
Non-exported functions should not do any locking, unless they have a special
|
||||
prefix to the name (explained below). The responsibility for thread-safety
|
||||
comes from the exported functions which call the non-exported functions.
|
||||
Maintaining this convention minimizes developer overhead when working with
|
||||
complex objects.
|
||||
|
||||
Functions prefixed 'threaded' (example 'threadedMine') are meant to be called
|
||||
in their own goroutine (`go threadedMine()`) and will manage their own
|
||||
thread-safety.
|
||||
|
||||
Error Handling
|
||||
--------------
|
||||
|
||||
All errors need to be checked as soon as they are received, even if they are
|
||||
known to not cause problems. The statement that checks the error needs to be
|
||||
`if err != nil`, and if there is a good reason to use an alternative statement
|
||||
(such as `err == nil`), it must be documented. The body of the if statement
|
||||
should be at most 4 lines, but usually only one. Anything requiring more lines
|
||||
needs to be its own function.
|
||||
|
||||
Example:
|
||||
|
||||
```go
|
||||
block, err := s.AcceptBlock()
|
||||
if err != nil {
|
||||
handleAcceptBlockErr(block, err)
|
||||
return
|
||||
}
|
||||
```
|
||||
|
||||
Sanity Checks
|
||||
-------------
|
||||
|
||||
Some functions make assumptions. For example, the 'addTransaction' function
|
||||
assumes that the transaction being added is not in conflict with any other
|
||||
transactions. Where possible, these explicit assumptions should be validated.
|
||||
|
||||
Example:
|
||||
|
||||
```go
|
||||
if build.DEBUG {
|
||||
_, exists := tp.usedOutputs[input.OutputID]
|
||||
if exists {
|
||||
panic("incorrect use of addTransaction")
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In the example, a panic is called for incorrect use of the function, but only
|
||||
in debug mode. This failure will be invisible in production code, but the code
|
||||
will have higher performance because the code should never fail anyway.
|
||||
|
||||
If the code is continually checking items that should be universally true,
|
||||
mistakes are easier to catch during testing, and side effects are less likely
|
||||
to go unnoticed.
|
||||
|
||||
Sanity checks and panics are purely to check for developer mistakes. A user
|
||||
should not be able to trigger a panic, and no set of network communications or
|
||||
real-world conditions should be able to trigger a panic.
|
||||
|
||||
Testing
|
||||
-------
|
||||
|
||||
The test suite code should be the same quality as the rest of the codebase.
|
||||
When writing new code in a pull request, the pull request should include test
|
||||
coverage for the code.
|
||||
|
||||
Most modules have a tester object, which can be created by calling
|
||||
`createXXXTester`. Module testers typically have a consensus set, a miner, a
|
||||
wallet, and a few other relevant modules that can be used to build
|
||||
transactions, mine blocks, etc.
|
||||
|
||||
In general, testing that uses exclusively exported functions to achieve full
|
||||
coverage is preferred. These types of tests seem to find more bugs and trigger
|
||||
more asserts.
|
||||
|
||||
Any testing provided by a third party which is both maintainable and reasonably
|
||||
quick will be accepted. There is little downside to more testing, even when the
|
||||
testing is largely redundant.
|
74
3rd_party/Sia-v1.1.1-windows-amd64/doc/Encoding.md
vendored
Normal file
74
3rd_party/Sia-v1.1.1-windows-amd64/doc/Encoding.md
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
Encoding
|
||||
========
|
||||
|
||||
The encoding package converts arbitrary objects into byte slices, and vice
|
||||
versa. Objects are encoded as binary data, without type information. The
|
||||
decoder will attempt to decode its input bytes into whatever type it is
|
||||
passed. For example:
|
||||
|
||||
```go
|
||||
Marshal(int64(3)) == []byte{3, 0, 0, 0, 0, 0, 0, 0}
|
||||
|
||||
var x int64
|
||||
Unmarshal([]byte{3, 0, 0, 0, 0, 0, 0, 0}, &x)
|
||||
// x == 3
|
||||
```
|
||||
|
||||
Note that this leads to some ambiguity. Since an `int64` and a `uint64` are
|
||||
both 8 bytes long, it is possible to encode an `int64` and successfully decode
|
||||
it as a `uint64`. As a result, it is imperative that *the decoder knows
|
||||
exactly what it is decoding*. Developers must rely on context to determine
|
||||
what type to decode into.
|
||||
|
||||
The specific rules for encoding Go's builtin types are as follows:
|
||||
|
||||
Integers are little-endian, and are always encoded as 8 bytes, i.e. their
|
||||
`int64` or `uint64` equivalent.
|
||||
|
||||
Booleans are encoded as one byte, either zero (false) or one (true). No other
|
||||
values may be used.
|
||||
|
||||
Nil pointers are equivalent to "false," i.e. a single zero byte. Valid
|
||||
pointers are represented by a "true" byte (0x01) followed by the encoding of
|
||||
the dereferenced value.
|
||||
|
||||
Variable-length types, such as strings and slices, are represented by an
|
||||
8-byte unsigned length prefix followed by the encoded value. Strings are
|
||||
encoded as their literal UTF-8 bytes. Slices are encoded as the concatenation
|
||||
of their encoded elements. For example:
|
||||
|
||||
```go
|
||||
// slice len: 1 string len: 3 string data
|
||||
Marshal([]string{"foo"}) == []byte{1,0,0,0,0,0,0,0, 3,0,0,0,0,0,0,0, 'f','o','o'}
|
||||
```
|
||||
|
||||
Maps are not supported; attempting to encode a map will cause `Marshal` to
|
||||
panic. This is because their elements are not ordered in a consistent way, and
|
||||
it is imperative that this encoding scheme be deterministic. To encode a map,
|
||||
either convert it to a slice of structs, or define a `MarshalSia` method (see
|
||||
below).
|
||||
|
||||
Arrays and structs are simply the concatenation of their encoded elements.
|
||||
Byte slices are not subject to the 8-byte integer rule; they are encoded as
|
||||
their literal representation, one byte per byte.
|
||||
|
||||
All struct fields must be exported. (For some types this is a bit awkward, so
|
||||
this rule is subject to change.) The ordering of struct fields is determined
|
||||
by their type definition. For example:
|
||||
|
||||
```go
|
||||
type foo struct {
|
||||
S string
|
||||
I int
|
||||
}
|
||||
|
||||
Marshal(foo{"bar", 3}) == append(Marshal("bar"), Marshal(3)...)
|
||||
```
|
||||
|
||||
Finally, if a type implements the SiaMarshaler interface, its MarshalSia
|
||||
method will be used to encode the type. Similarly, if a type implements the
|
||||
SiaUnmarshal interface, its UnmarshalSia method will be used to decode the
|
||||
type. Note that unless a type implements both interfaces, it must conform to
|
||||
the spec above. Otherwise, it may encode and decode itself however desired.
|
||||
This may be an attractive option where speed is critical, since it allows for
|
||||
more compact representations, and bypasses the use of reflection.
|
289
3rd_party/Sia-v1.1.1-windows-amd64/doc/File Contract Negotiation.md
vendored
Normal file
289
3rd_party/Sia-v1.1.1-windows-amd64/doc/File Contract Negotiation.md
vendored
Normal file
@@ -0,0 +1,289 @@
|
||||
File Contract Negotiation
|
||||
=========================
|
||||
|
||||
Securing data on Sia requires creating and revising file contracts in an
|
||||
untrusted environment. Managing data on Sia happens through several protocols:
|
||||
|
||||
+ Settings Request - the host sends the renter its settings.
|
||||
|
||||
+ Revision Request - the renter will send the host a file contract id, and the
|
||||
host will send the most recent file contract revision that it knows of for
|
||||
that file contract, with the signatures. A challenge and response is also
|
||||
performed to verify that the renter is able to create the signatures to
|
||||
modify the file contract revision.
|
||||
|
||||
+ File Contract Creation - no data is uploaded during the initial creation of a
|
||||
file contract, but funds are allocated so that the file contract can be
|
||||
iteratively revised in the future.
|
||||
|
||||
+ File Contract Revision - an existing file contract is revised so that data
|
||||
can be added to an arbitrary place, or removed from an arbitrary place.
|
||||
|
||||
+ File Contract Renewal - an existing file contract is renewed, meaning that a
|
||||
new file contract with a different id is created, but that has the same data.
|
||||
New funds are added to this file contract, and it can now be modified
|
||||
separately from the previous contract.
|
||||
|
||||
+ Data Request - data is requested from the host by hash.
|
||||
|
||||
+ (planned for later) Storage Proof Request - the renter requests that the host
|
||||
perform an out-of-band storage proof.
|
||||
|
||||
+ (planned for later) Metadata Request - the renter requests some metadata
|
||||
about the file contract from the host, namely the list of hashes that compose
|
||||
the file. This list of hashes is provided along with a cryptographic proof
|
||||
that the hashes are valid. The proof is only needed if only a subset of
|
||||
hashes are being sent.
|
||||
|
||||
A frequently seen construction is 'acceptance'. The renter or host may have the
|
||||
opportunity to accept or reject a communication, which takes the form of a
|
||||
string. The acceptance string is always the same, and any string that is not
|
||||
the acceptance string is a rejection. The rejection string can include reasons
|
||||
why the rejection occurred, but most not exceed 255 bytes. After a rejection,
|
||||
the connection is always closed.
|
||||
|
||||
The protocols described below are numbered. The number indicates when the
|
||||
communicator is switching. Each pair of numbers is a full round trip of
|
||||
communications.
|
||||
|
||||
All communications attempt to support slow connections and Tor connections. Any
|
||||
connection with a throughput below 100kbps may struggle to perform the uploads
|
||||
and downloads, and any connection with a rountrip latency greater than 2
|
||||
minutes may struggle to complete the protocols.
|
||||
|
||||
Settings Request
|
||||
----------------
|
||||
|
||||
The host signs the settings request to prove that the connection has opened to
|
||||
the right party. Hosts announce on the blockchain and perform burn, therefore
|
||||
identity is important.
|
||||
|
||||
1. The renter makes an RPC to the host, opening a connection. The connection
|
||||
deadline should be at least 120 seconds.
|
||||
|
||||
2. The host sends the renter the most recent copy of its external settings,
|
||||
signed by the host public key. The connection is then closed.
|
||||
|
||||
Revision Request
|
||||
----------------
|
||||
|
||||
The renter requests a recent revision from the host. Often, this request
|
||||
precedes modifications. A file contract can only be open for revision with one
|
||||
party at a time. To prevent DoS attacks, the party must authenticate here by
|
||||
performing a challenge-response protocol during the revision request. Putting
|
||||
this challenge-response requirement in the revision-request can help improve
|
||||
privacy, though the host is under no cryptographic or incentive-based
|
||||
obligation to preserve the privacy of the revision.
|
||||
|
||||
1. The renter makes an RPC to the host, opening a connection. The connection
|
||||
deadline should be at least 120 seconds. The renter sends the file contract
|
||||
id for the revision being requested.
|
||||
|
||||
2. The host writes 32 bytes of random data that the renter must sign for the
|
||||
renter key in the corresponding file contract.
|
||||
|
||||
3. The renter returns the signed challenge.
|
||||
|
||||
4. The host verifies the signature from the renter and then sends the renter
|
||||
the most recent file contract revision, along with the transaction
|
||||
signatures from both the renter and the host. The connection is then closed.
|
||||
|
||||
File Contract Creation
|
||||
----------------------
|
||||
|
||||
A few decisions were made regarding the file contract protocol. The first is
|
||||
that the renter should not sign the file contract until the host has formally
|
||||
accepted the file contract. The second is that the host should be the last one
|
||||
to sign the file contract, as the renter is the party with the strong
|
||||
reputation system.
|
||||
|
||||
Instead of sending a whole transaction each time, the transaction is sent
|
||||
piecemeal, and only the new parts at each step are sent to the other party.
|
||||
This minimizes the surface area of data for a malicious party to manipulate,
|
||||
which means less verification code, which means less chances of having a bug in
|
||||
the verification code.
|
||||
|
||||
The renter pays for the siafund fee on the host's collateral and contract fee.
|
||||
If a renter opens a file contract and then never uses it, the host does not
|
||||
lose money. This does put the renter at risk, as they may open up a file
|
||||
contract and then watch the host leave, but the renter is spreading the risk
|
||||
over communications with many hosts, and has a reputation system that will help
|
||||
ensure that the renter is only dealing with upstanding hosts.
|
||||
|
||||
1. The renter makes an RPC to the host, opening a connection. The connection
|
||||
deadline should be at least 360 seconds.
|
||||
|
||||
2. The host sends the renter the most recent copy of its settings, signed. If
|
||||
the host is not accepting new file contracts, the connection is closed.
|
||||
|
||||
3. The renter sends a notice of acceptance or rejection. If the renter accepts,
|
||||
the renter then sends a funded file contract transaction without a
|
||||
signature, followed by the public key that will be used to create the
|
||||
renter's portion of the UnlockConditions for the file contract.
|
||||
|
||||
4. The host sends an acceptance or rejection of the file contract. If the host
|
||||
accepts, the host will add collateral to the file contract, and will send
|
||||
the renter the inputs + outputs for the collateral, followed by any new
|
||||
parent transactions. The length of any of these may be zero.
|
||||
|
||||
5. The renter indicates acceptance or rejection of the file contract. If the
|
||||
renter accepts, the renter will sign the file contract and send the
|
||||
transaction signatures to the host. The renter will also send a signature
|
||||
for a no-op file contract revision that follows the file contract.
|
||||
|
||||
6. The host may only reject the file contract in the event that the renter has
|
||||
sent invalid signatures, so the acceptance step is skipped. The host signs
|
||||
the file contract and sends the transaction signatures to the renter, and
|
||||
the host creates and sends a signature for the no-op revision that follows
|
||||
the file contract. The connection is closed.
|
||||
|
||||
File Contract Revision
|
||||
----------------------
|
||||
|
||||
1. The renter makes an RPC to the host, opening a connection. The minimum
|
||||
deadline for the connection is 600 seconds. The renter then sends a file
|
||||
contract ID, indicating the file contract that is getting revised during the
|
||||
RPC.
|
||||
|
||||
2. The host will respond with a 32 byte challenge - a random 32 bytes that the
|
||||
renter will need to sign.
|
||||
|
||||
3. The renter will sign the challenge with the renter key that protects the
|
||||
file contract. This is to prove that the renter has access to the file
|
||||
contract.
|
||||
|
||||
4. The host will verify the challenge signature, then send an acceptance or
|
||||
rejection. If accetped, the host will send the most recent file contract
|
||||
revision for the file contract along with the transaction signagtures that
|
||||
validate the revision. The host will lock the file contract, meaning no
|
||||
other changes can be made to the revision file contract until this
|
||||
connection has closed.
|
||||
|
||||
A loop begins. The host sends the most recent revision of the host settings
|
||||
to the renter, signed. The settings are sent after each iteration of the
|
||||
loop to enable high resolution dynamic pricing for the host, especially for
|
||||
bandwidth.
|
||||
|
||||
6. The renter may reject or accept the settings + revision. A specific
|
||||
rejection message will gracefully terminate the loop here. The renter will
|
||||
send an unsigned file contract revision followed by a batch of modification
|
||||
actions which the revision pays for. Batching allows the renter to send a
|
||||
lot of data in a single, one-way connection, improving throughput. The
|
||||
renter will send a number indicating how many modifications will be made in
|
||||
a batch, and then sends each modification in order.
|
||||
|
||||
A single modification can either be an insert, a modify, or a delete. An
|
||||
insert is an index, indicating the index where the data is going to be
|
||||
inserted. '0' indicates that the data is inserted at the very beginning, '1'
|
||||
indicates that the data will be inserted between the first and second
|
||||
existing sectors, etc. The index is followed by the 4MB of data. A modify is
|
||||
an index indicating which sector is being modified, followed by an offset
|
||||
indicating which data within the sector is being modified. Finally, some
|
||||
data is provided indicating what the data in the sector should be replaced
|
||||
with starting from that offset. The offset + len of the data should not
|
||||
exceed the sector size of 4MB. A delete is an index indicating the index of
|
||||
the sector that is being deleted. Each operation within a batch is atomic,
|
||||
meaning if you are inserting 3 sectors at the front of the file contract,
|
||||
the indexes of each should be '0', '1', '2'.
|
||||
|
||||
7. The host indicates either acceptance or rejection of the new revision.
|
||||
|
||||
8. The renter signs the revision and sends the signature to the host.
|
||||
|
||||
9. The host signs the revision and sends the signature to the renter. Both
|
||||
parties submit the new revision to the transaction pool. The connection
|
||||
deadline is reset to 600 seconds (unless the maximum deadline has been
|
||||
reached), and the loop restarts.
|
||||
|
||||
File Contract Renewal
|
||||
---------------------
|
||||
|
||||
1. The renter makes an RPC to the host, opening a connection. The minimum
|
||||
deadline for the connection is 600 seconds. The renter then sends a file
|
||||
contract ID, indicating the file contract that is getting revised during the
|
||||
RPC.
|
||||
|
||||
2. The host will respond with a 32 byte challenge - a random 32 bytes that the
|
||||
renter will need to sign.
|
||||
|
||||
3. The renter will sign the challenge with the renter key that protects the
|
||||
file contract. This is to prove that the renter has access to the file
|
||||
contract.
|
||||
|
||||
4. The host will verify the challenge signature, then send an acceptance or
|
||||
rejection. If accetped, the host will send the most recent file contract
|
||||
revision for the file contract along with the transaction signagtures that
|
||||
validate the revision. The host will lock the file contract, meaning no
|
||||
other changes can be made to the revision file contract until this
|
||||
connection has closed. The host sends the most recent revision of the host
|
||||
settings to the renter, signed. If the host is not accepting new file
|
||||
contracts, the connection is closed.
|
||||
|
||||
5. The renter either accepts or rejects the settings. If accepted, the renter
|
||||
sends a funded, unsigned file contract to the host, containing the same
|
||||
Merkle root as the previous file contract, and also containing a renewed
|
||||
payout with conditional payments to the host to cover the host storing the
|
||||
data for the extended duration.
|
||||
|
||||
6. The host will accept or reject the renewed file contract. If accepted, the
|
||||
host will add collateral (and miner fees if desired) and send the inputs +
|
||||
outputs for the collateral, along with any new parent transactions. The
|
||||
length of any of these may be zero.
|
||||
|
||||
7. The renter will accept or reject the host's additions. If accepting, the
|
||||
renter will send signatures for the transaction to the host. The renter will
|
||||
also send a signature for a no-op file contract revision that follows the
|
||||
file contract.
|
||||
|
||||
8. The host may only reject the file contract in the event that the renter has
|
||||
sent invalid signatures, so the acceptance step is skipped. The host signs
|
||||
the file contract and sends the transaction signatures to the renter, and
|
||||
the host creates and sends a signature for the no-op revision that follows
|
||||
the file contract. The connection is closed.
|
||||
|
||||
Data Request
|
||||
------------
|
||||
|
||||
1. The renter makes an RPC to the host, opening a connection. The connection
|
||||
deadline is at least 600 seconds. The renter will send a file contract id
|
||||
corresponding to the file contract that will be used to pay for the
|
||||
download.
|
||||
|
||||
2. The host will respond with a 32 byte challenge - a random 32 bytes that the
|
||||
renter will need to sign.
|
||||
|
||||
3. The renter will sign the challenge with the public key that protects the
|
||||
file contract being used to pay for the download. This proves that the
|
||||
renter has access to the payment.
|
||||
|
||||
4. The host will verify the challenge signature, and then send an acceptance or
|
||||
rejection. If accepted, the host will send the most recent file contract
|
||||
revision followed by the signautres that validate the revision. The host
|
||||
will lock the file contract, preventing other connections from making
|
||||
changes to the underlying storage obligation.
|
||||
|
||||
A loop begins. The host sends the most recent external settings to the
|
||||
renter, signed. The settings are sent each iteration to provide high
|
||||
resolution dynamic bandwidth pricing.
|
||||
|
||||
5. The host will send the renter the most recent file contract revision, along
|
||||
with the signatures that validate the revision.
|
||||
|
||||
A loop begins, which will allow the renter to download multiple batches of
|
||||
data from the same connection. The host will send the host settings, and the
|
||||
most recent file contract revision transaction. If there is no revision yet,
|
||||
the host will send a blank transaction. The host is expected to always have
|
||||
the most recent revision (the host signs last), the renter may not have the
|
||||
most recent revision.
|
||||
|
||||
6. The renter will accept or reject the host's settings. If accepting, the
|
||||
renter will send a file contract revision, unsigned, to pay for the download
|
||||
request. The renter will then send the download request itself.
|
||||
|
||||
7. The host will either accept or reject the revision.
|
||||
|
||||
8. The renter will send a signature for the file contract revision.
|
||||
|
||||
9. The host sends a signature for the file contract revision, followed by the
|
||||
data that was requested by the download request. The loop starts over, and
|
||||
the connection deadline is reset to a minimum of 600 seconds.
|
250
3rd_party/Sia-v1.1.1-windows-amd64/doc/Guide to Contributing to Sia.md
vendored
Normal file
250
3rd_party/Sia-v1.1.1-windows-amd64/doc/Guide to Contributing to Sia.md
vendored
Normal file
@@ -0,0 +1,250 @@
|
||||
# Contributing to Sia
|
||||
|
||||
#### Table of Contents
|
||||
* [Get started with Go](#go)
|
||||
* [Install Go](#install-go)
|
||||
* [Learn Go]("learn-go")
|
||||
* [Build Sia](#build-sia)
|
||||
* [Contribute to the codebase](#contribute)
|
||||
* [Set up git](#setup-git)
|
||||
* [Fork the Sia repository](#fork)
|
||||
* [Write some code](#write)
|
||||
* [Submit your code for review](#pull)
|
||||
* [More git resources](#git-resources)
|
||||
* [Where to start](#where-to-start)
|
||||
* [Contact us](#contact)
|
||||
|
||||
<a name="go"/>
|
||||
## Get started with Go
|
||||
|
||||
<a name="install-go"/>
|
||||
### Install Go
|
||||
To install Go on your computer, follow the
|
||||
[official installation guide][install-go].
|
||||
|
||||
You should install the latest [official Go binary][binary] for your system (if
|
||||
not available, [install from source][source]). If you plan to cross compile
|
||||
Sia, see [Cross Compilation with Go 1.5][cross] by Dave Cheney.
|
||||
|
||||
Now make a workspace directory in which you will store source code and
|
||||
dependencies. You can choose any filepath except where you installed Go (don't
|
||||
choose `/usr/local`).
|
||||
|
||||
```bash
|
||||
# make a working directory called golang in your home directory
|
||||
$ mkdir $HOME/golang
|
||||
# store base path in an environmental variable
|
||||
$ echo 'export GOPATH=$HOME/golang' >> $HOME/.profile
|
||||
# add bin subdirectory to PATH environmental variable
|
||||
$ echo 'export PATH=$PATH:$GOPATH/bin' >> $HOME/.profile
|
||||
```
|
||||
|
||||
<a name="learn-go"/>
|
||||
### Learn Go
|
||||
* To get familiar with the language, start with the official [Tour of Go][tour].
|
||||
* Move onto [How to Write Go Code][how] to learn how to organize Go packages
|
||||
and use the go tool.
|
||||
* Finish with the [Effective Go][effective] guide.
|
||||
|
||||
<a name="build-sia"/>
|
||||
## Build Sia
|
||||
To build Sia on your machine, enter the following on the command line:
|
||||
|
||||
```bash
|
||||
# Download Sia and its dependencies
|
||||
# Binaries will be installed in $GOPATH/bin
|
||||
$ go get -u github.com/NebulousLabs/Sia/...
|
||||
|
||||
# Switch to directory containing Sia source code
|
||||
$ cd $GOPATH/src/github.com/NebulousLabs/Sia
|
||||
|
||||
# You have three Sia builds to choose from.
|
||||
# To build the standard release binary:
|
||||
$ make release-std
|
||||
# Or to build the release binary with race detection and an array debugging
|
||||
# asserts:
|
||||
$ make release
|
||||
# Or to build the developer binary (with a different genesis block, faster
|
||||
# block times, and other changes):
|
||||
$ make
|
||||
```
|
||||
|
||||
<a name="contribute"/>
|
||||
## Contribute to the codebase
|
||||
<a name="setup-git"/>
|
||||
### Set up git
|
||||
Install git on your machine according to [these instructions][install-git] in
|
||||
the Pro Git book.
|
||||
|
||||
You will first need to set up global settings using the command line.
|
||||
```bash
|
||||
$ git config --global user.name "Your Name"
|
||||
$ git config --global user.email you@somedomain.com
|
||||
|
||||
# Tell git to remember your login information for a certain amount of time.
|
||||
# Default time is 15 minutes:
|
||||
$ git config --global credential.helper cache
|
||||
# Or you can choose a different amount of time:
|
||||
$ git config --global credential.helper "cache --timeout=[seconds]"
|
||||
|
||||
```
|
||||
<a name="fork"/>
|
||||
### Fork the Sia repository
|
||||
While logged into your Github account, navigate to the [Sia repository][sia]
|
||||
and click the 'Fork' button in the upper righthand corner. Your account now
|
||||
has a 'forked' copy of the original repo at
|
||||
`https://github.com/<your GitHub username>/Sia`.
|
||||
|
||||
When you installed Sia using `go get`, the go tool put the Sia source code in
|
||||
$GOPATH/src/github.com/NebulousLabs/Sia. Change to that directory and set up
|
||||
your fork as a git [remote][remote]:
|
||||
|
||||
```bash
|
||||
$ cd $GOPATH/src/github.com/NebulousLabs/Sia
|
||||
# Add your fork as a remote. Name it whatever is convenient,
|
||||
# e.g your GitHub username
|
||||
$ git remote add <remote name> https://github.com/<username>/Sia.git
|
||||
```
|
||||
|
||||
<a name="write">
|
||||
### Write some code
|
||||
Right now your git local repository only has one branch (called 'master' by
|
||||
default). If you want to make changes, add a new branch and make your changes
|
||||
there. You should maintain master as an up-to-date copy of the NebulousLabs/Sia
|
||||
repository's master branch.
|
||||
|
||||
To create and checkout a new branch:
|
||||
```bash
|
||||
# If you're not already in the right directory:
|
||||
$ cd $GOPATH/src/NebulousLabs/Sia
|
||||
# Make sure you're on branch master
|
||||
$ git checkout master
|
||||
# Create and checkout a new branch
|
||||
$ git checkout -b <branch>
|
||||
```
|
||||
Now write some code while the new branch is checked out.
|
||||
|
||||
Only implement one logical change per branch. If you're working on several
|
||||
things at once, make multiple branches. To switch between branches you're
|
||||
working on, you have to stash the changes in the branch you're switching from
|
||||
by running `git stash`, which tucks away all changes since the last
|
||||
commit.
|
||||
|
||||
```bash
|
||||
# Stash changes to current branch.
|
||||
$ git stash
|
||||
# Checkout other branch.
|
||||
$ git checkout <branch>
|
||||
...
|
||||
# Make changes
|
||||
...
|
||||
# Return to first branch:
|
||||
$ git checkout <branch 1>
|
||||
# View a list of stashes and their corresponding hashes.
|
||||
$ git stash list
|
||||
# Reapply changes from the stash you want to recover and remove that stash from.
|
||||
# the list
|
||||
$ git stash pop <hash>
|
||||
```
|
||||
|
||||
To learn more about branching, see
|
||||
[Using the Fork-and-Branch Git Workflow][branch] and
|
||||
[Pro Git - Branches in a Nutshell][nutshell].
|
||||
For more on stashing, see [Pro Git - Stashing and Cleaning][stashing].
|
||||
|
||||
Be sure to follow the conventions detailed in
|
||||
[docs/Developers.md][developers.md]. We will reject pull requests that do not
|
||||
satisfy these best practices.
|
||||
|
||||
Once you've finished making changes, stage and commit your changes then update
|
||||
your fork on Github:
|
||||
|
||||
```bash
|
||||
# Make sure the code is up to date with the original repo:
|
||||
$ git checkout master
|
||||
$ git pull origin master
|
||||
# Checkout branch with changes.
|
||||
$ git checkout <branch>
|
||||
$ git rebase master
|
||||
# Before every pull request, you should run `make test-long`
|
||||
# to test your code and fix formatting and style problems.
|
||||
$ make test-long
|
||||
# If all goes well, proceed to staging your changed files:
|
||||
$ git add <changed files>
|
||||
# Use `git status` to see what files have been staged.
|
||||
$ git status
|
||||
# Commit your changes. If you just run `commit`, a text editor will pop up for
|
||||
# you to enter a description of your changes.
|
||||
$ git commit -m "Add new tests for CommitSync method"
|
||||
# Push the changes to your fork on GitHub, which you should have set up as a
|
||||
# remote already.
|
||||
$ git push <fork remote> <branch>
|
||||
```
|
||||
<a name="pull"/>
|
||||
### Submit your code for review
|
||||
Once you've tested your new code and pushed changes to your fork, navigate to
|
||||
your fork at `https://github.com/<username>/Sia` in your browser.
|
||||
Switch to the branch you've made changes on by selecting it from the list on
|
||||
the upper left. Then click 'New pull request' on the upper right.
|
||||
|
||||
Once you have made the pull request, we will review your code. We will reject
|
||||
code that is unsafe, difficult to read, or otherwise violates the conventions
|
||||
outlined in [docs/Developers.md][developers.md].
|
||||
|
||||
Here's a sample code review comment:
|
||||

|
||||
|
||||
If you want to tweak code for which you've already submitted a pull request,
|
||||
push the updated code to your fork with `git push -f <fork remote> <branch>` and
|
||||
summarize the changes you've made in a comment on the pull request page on
|
||||
GitHub.
|
||||
|
||||
Once we have accepted your changes and merged them into the original repo, you
|
||||
have some cleanup to do:
|
||||
|
||||
```bash
|
||||
# Update local master branch to reflect changes in origin (the original
|
||||
# repo).
|
||||
$ git pull origin master
|
||||
# Delete the branch you made the pull request from.
|
||||
$ git branch -d <branch>
|
||||
# Delete the remote branch on your fork.
|
||||
$ git push <fork remote> :<branch>
|
||||
# Update your fork.
|
||||
$ git push <fork remote> master
|
||||
```
|
||||
<a name="git-resources"/>
|
||||
### More Git resources
|
||||
* [How to into git (and Github)][luke] by Luke Champine
|
||||
* [Official resources for learning Git][git]
|
||||
|
||||
<a name="where-to-start"/>
|
||||
## Where to start
|
||||
If you'd like to contribute to Sia but don't have any specific ideas, writing
|
||||
tests is a good way to get your feet wet. See [doc/Running and Writing Tests for Sia.md](Running\ and\ Writing\ Tests\ for\ Sia.md) to get started.
|
||||
|
||||
<a name="contact"/>
|
||||
## Contact us
|
||||
Feel free to ask for help on the #dev channel on [Slack][slack].
|
||||
|
||||
[cross]: http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5
|
||||
[binary]: https://golang.org/dl/
|
||||
[source]: https://golang.org/doc/install/source
|
||||
[tour]: https://tour.golang.org/welcome/1
|
||||
[how]: https://golang.org/doc/code.html
|
||||
[luke]: https://gist.github.com/lukechampine/6418449
|
||||
[git]: https://git-scm.com/doc
|
||||
[cheney]: http://dave.cheney.net/2013/06/09/writing-table-driven-tests-in-go
|
||||
[install-go]: https://golang.org/doc/install
|
||||
[signup]: https://github.com/join?source=header-home
|
||||
[effective]: https://golang.org/doc/effective_go.html
|
||||
[sia]: https://github.com/NebulousLabs/Sia
|
||||
[branch]: http://blog.scottlowe.org/2015/01/27/using-fork-branch-git-workflow/
|
||||
[developers.md]: https://github.com/NebulousLabs/Sia/blob/master/doc/Developers.md
|
||||
[gofmt]: https://golang.org/cmd/gofmt/
|
||||
[nutshell]: https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell
|
||||
[slack]: http://slackin.siacoin.com
|
||||
[install-git]: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
|
||||
[test-doc]: https://github.com/NebulousLabs/Sia/blob/master/doc/Testing.md
|
||||
[stashing]: https://git-scm.com/book/en/v2/Git-Tools-Stashing-and-Cleaning
|
||||
[remote]: https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes
|
35
3rd_party/Sia-v1.1.1-windows-amd64/doc/Modules.md
vendored
Normal file
35
3rd_party/Sia-v1.1.1-windows-amd64/doc/Modules.md
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
Module Conventions
|
||||
==================
|
||||
|
||||
Each module has a file/directory where they store persistent data (if
|
||||
necessary). When module.New is called, the module is responsible for creating
|
||||
and populating that directory. The logic for saving and loading data belongs in
|
||||
persist.go.
|
||||
|
||||
Modules that depend on external information (such as the state of consensus)
|
||||
have an update.go to manage fetching and integrating the external information.
|
||||
If that information is coming from another module, a subscription should be
|
||||
used. Module subscription uses a ModuleSubscriber interface (which the
|
||||
subscriber must satisfy) and a ModuleSubscribe method (implemented by the
|
||||
parent module). As the parent module gets updates, it will call
|
||||
ReceiveModuleUpdate (the only method of the ModuleSubscriber interface) on all
|
||||
subscribers, taking care that each subscriber always receives the updates in
|
||||
the correct order. This method of subscription is chosen to keep information
|
||||
flow simple and synchronized - a child module should never have information
|
||||
that the parent module does not (it just causes problems).
|
||||
|
||||
For testing, it is often important to know that an update has propagated to all
|
||||
modules. Any module that subscribes to another must also implement a
|
||||
ModuleNotify function in subscriptions.go. ModuleNotify returns a channel down
|
||||
which a struct{} will be sent every time that module receives an update from a
|
||||
parent module. To keep things simple, a module should not subscribe to the
|
||||
parent of another module that it is subscribed to. For example, the transaction
|
||||
pool is subscribed to the consensus set. Therefore, no module should subscribe
|
||||
to both the transaction pool and the consensus set. All consensus set updates
|
||||
should be received through the transaction pool. This helps with
|
||||
synchronization and ensures that no child module ever has information that the
|
||||
parent module has not yet received (desynchronization).
|
||||
|
||||
#### Module Update Flow
|
||||
|
||||
consensus -> (host, hostdb, renter, (transaction pool -> miner, wallet))
|
256
3rd_party/Sia-v1.1.1-windows-amd64/doc/Running and Writing Tests for Sia.md
vendored
Normal file
256
3rd_party/Sia-v1.1.1-windows-amd64/doc/Running and Writing Tests for Sia.md
vendored
Normal file
@@ -0,0 +1,256 @@
|
||||
# Running and Writing Tests for Sia
|
||||
Improving test coverage is a great way to start contributing to Sia.
|
||||
|
||||
This guide focuses on how to write tests. To learn about making pull requests
|
||||
to submit the code you've written, see
|
||||
[doc/Guide to Contributing to Sia.md][guide]. You should also read
|
||||
[doc/Developers.md][developers] to learn about Sia code conventions and quality
|
||||
standards.
|
||||
|
||||
|
||||
#### Table of Contents
|
||||
* [Running tests for Sia](#existing)
|
||||
* [Updating code before testing](#update)
|
||||
* [Testing the entire build](#entire)
|
||||
* [Testing a particular package](#particular)
|
||||
* [Writing new tests for Sia](#write)
|
||||
* [A few guidelines](#naming)
|
||||
* [Basic test format](#basic)
|
||||
* [Table-driven tests](#table)
|
||||
* [Questions?](#questions)
|
||||
|
||||
<a name="existing"/>
|
||||
## Running tests for Sia
|
||||
Go's comprehensive [test package][pkg/testing] makes testing straightforward,
|
||||
particularly when you use the bundled tools included in the
|
||||
[Sia makefile][makefile], including `make test`, `make cover`, `make bench`,
|
||||
and their variants.
|
||||
|
||||
<a name="update"/>
|
||||
### Updating code before testing
|
||||
If you just want to run existing tests on the codebase as is, you just need to
|
||||
pull the latest version of the original repo to your master branch. (If that
|
||||
sentence didn't make sense, go read
|
||||
[doc/Guide to Contributing to Sia.md][guide].)
|
||||
|
||||
```bash
|
||||
# Make sure you are in the right directory.
|
||||
$ cd $GOPATH/src/github.com/<your Github username>/Sia
|
||||
# Also make sure you're working with the right branch.
|
||||
$ git checkout master
|
||||
# Pull latest changes from origin, the original Sia repo.
|
||||
$ git pull origin master
|
||||
# Update your fork of the repo, which should be set up as a remote.
|
||||
$ git push <remote> master
|
||||
```
|
||||
|
||||
If you want to run tests on the new code you've added, first make sure the rest
|
||||
of the code is up to date. New code should be on its own branch (again, see
|
||||
[doc/Guide to Contributing to Sia.md][guide]).
|
||||
|
||||
```bash
|
||||
# Make sure you are in the right directory.
|
||||
$ cd $GOPATH/src/github.com/<your Github username>/Sia
|
||||
# Checkout the branch you made the changes on.
|
||||
$ git checkout <branch name>
|
||||
# Stash any tracked but uncommitted changes.
|
||||
$ git stash
|
||||
# Then switch back to `master` and update it to match the original repo.
|
||||
$ git checkout master
|
||||
$ git pull origin master
|
||||
# Update your fork of the repo, which you should have set up as a remote.
|
||||
$ git push <remote> master
|
||||
# Make the updated `master` the new base of the branch you made the changes on,
|
||||
# which involves reapplying all the commits made to that branch. Without the
|
||||
# `--ignore-date` flag, git rebase changes the date on all the commits to the
|
||||
# current date.
|
||||
$ git checkout <branch name>
|
||||
$ git rebase master --ignore-date
|
||||
# Restore the changes you stashed earlier.
|
||||
$ git stash pop
|
||||
```
|
||||
When you call `rebase`, you may run into some merge conflicts. Luke Champine's
|
||||
['How to into git and GitHub'][luke] has more details (and many useful tricks).
|
||||
|
||||
Once the branch you want to test is up to date, you're ready to run some tests.
|
||||
|
||||
<a name="entire"/>
|
||||
### Testing the entire build
|
||||
The `make test` command runs all tests (functions starting with `Test` in
|
||||
`_test.go` files) for each package, setting off a panic for any test that runs
|
||||
longer than 5s. For verbose output, run `make test-v` (which panics after 15s
|
||||
instead of 5s). Finally, `make test-long` has verbose output, only panics when
|
||||
a test takes 5 minutes, and also cleans up your code using `gofmt` and `golint`.
|
||||
**You should run** `make test-long` **before each pull request.**
|
||||
|
||||
Run `make cover` to run all tests for each package and generate color-coded
|
||||
.html visualizations of test coverage by function for each source file. Open
|
||||
`cover/<module>.html` in a browser to inspect a module's test coverage. For
|
||||
example, here's part of the html file generated for the persist package:
|
||||
|
||||

|
||||
|
||||
Meanwhile, `make bench` will call `gofmt` on all packages, then run all
|
||||
benchmarks (functions starting with `Benchmark` in `_test.go` files).
|
||||
|
||||
<a name="particular"/>
|
||||
### Testing a particular package or function
|
||||
To run tests for just a certain package, run `make test pkgs=./<package>`. To run
|
||||
a certain test function, run `make test pkgs=./<package> run=<function>`. The same
|
||||
goes for `make test-long`, `make cover` and `make bench`.
|
||||
|
||||
For example, running `test-long` on the package persist produces this output:
|
||||
|
||||
```bash
|
||||
$ make test-long pkgs=./persist
|
||||
rm -rf release doc/whitepaper.aux doc/whitepaper.log doc/whitepaper.pdf
|
||||
gofmt -s -l -w ./persist
|
||||
go install ./persist
|
||||
go vet ./persist
|
||||
go test -v -race -tags='testing debug' -timeout=300s ./persist -run=Test
|
||||
=== RUN TestOpenDatabase
|
||||
--- PASS: TestOpenDatabase (0.42s)
|
||||
=== RUN TestSaveLoad
|
||||
--- PASS: TestSaveLoad (0.00s)
|
||||
=== RUN TestSaveLoadFile
|
||||
--- PASS: TestSaveLoadFile (0.01s)
|
||||
=== RUN TestSaveLoadFileSync
|
||||
--- PASS: TestSaveLoadFileSync (0.00s)
|
||||
=== RUN TestLogger
|
||||
--- PASS: TestLogger (0.00s)
|
||||
=== RUN TestLoggerCritical
|
||||
--- PASS: TestLoggerCritical (0.00s)
|
||||
=== RUN TestIntegrationRandomSuffix
|
||||
--- PASS: TestIntegrationRandomSuffix (0.01s)
|
||||
=== RUN TestAbsolutePathSafeFile
|
||||
--- PASS: TestAbsolutePathSafeFile (0.00s)
|
||||
=== RUN TestRelativePathSafeFile
|
||||
--- PASS: TestRelativePathSafeFile (0.00s)
|
||||
PASS
|
||||
ok github.com/NebulousLabs/Sia/persist 1.485s
|
||||
$
|
||||
```
|
||||
|
||||
<a name="write"/>
|
||||
## Writing new tests for Sia
|
||||
When you run `make cover`, you'll notice that many files have pretty low
|
||||
coverage. We're working on fixing that, but we could use your help.
|
||||
|
||||
<a name="naming"/>
|
||||
### A few guidelines
|
||||
* The test functions for `filename.go` should go in `filename_test.go` in the
|
||||
same directory and package.
|
||||
* A test function name should start with `Test` and clearly convey what is
|
||||
being tested.
|
||||
* You should declare function-specific variables and constants locally (inside
|
||||
the test function) instead of globally (outside the test function). [That
|
||||
holds in general][global], not just for tests.
|
||||
* As always, code should adhere to the standards and conventions laid out in
|
||||
[doc/Developers.md][developers].
|
||||
|
||||
<a name="basic"/>
|
||||
### Basic test format
|
||||
Suppose we'd like to test the Bar method belonging to type Foo.
|
||||
|
||||
```go
|
||||
// TestFoo checks that the Bar method on type Foo responds correctly to a normal
|
||||
// input and returns the expected error when given a bad input.
|
||||
func TestFoo(t *testing.T) {
|
||||
foo, err := NewFoo()
|
||||
if err != nil {
|
||||
// If NewFoo failed, we can't continue testing.
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Try a normal input; should succeed.
|
||||
err := foo.Bar(3)
|
||||
if err != nil {
|
||||
// Report the error, but don't abort the test.
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// Try a bad input; should return an error.
|
||||
// NOTE: Always prefer to compare to a specific error, rather than
|
||||
// err == nil
|
||||
err = Foo.Bar(0)
|
||||
if err != errDivideByZero {
|
||||
t.Errorf("expected errDivideByZero, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
<a name="table"/>
|
||||
### Table-driven tests in Go
|
||||
If you're looking to test a bunch of inputs, write a [table-driven test][table]
|
||||
with a slice of anonymous structs. For example, see `TestParseFileSize` in
|
||||
[siac/parse_test.go][parse_test]:
|
||||
|
||||
```go
|
||||
func TestParseFilesize(t *testing.T) {
|
||||
// Define a table of test cases in the form of a slice of anonymous structs.
|
||||
tests := []struct {
|
||||
in, out string
|
||||
err error
|
||||
}{
|
||||
{"1b", "1", nil},
|
||||
{"1KB", "1000", nil},
|
||||
{"1MB", "1000000", nil},
|
||||
{"1GB", "1000000000", nil},
|
||||
{"1TB", "1000000000000", nil},
|
||||
{"1KiB", "1024", nil},
|
||||
{"1MiB", "1048576", nil},
|
||||
{"1GiB", "1073741824", nil},
|
||||
{"1TiB", "1099511627776", nil},
|
||||
{"", "", errUnableToParseSize},
|
||||
{"123", "123", nil},
|
||||
{"123TB", "123000000000000", nil},
|
||||
{"123GiB", "132070244352", nil},
|
||||
{"123BiB", "", errUnableToParseSize},
|
||||
{"GB", "", errUnableToParseSize},
|
||||
{"123G", "", errUnableToParseSize},
|
||||
{"123B99", "", errUnableToParseSize},
|
||||
{"12A3456", "", errUnableToParseSize},
|
||||
{"1.23KB", "1230", nil},
|
||||
{"1.234KB", "1234", nil},
|
||||
{"1.2345KB", "1234", nil},
|
||||
}
|
||||
// Loop through the table of test cases to make sure ParseFileSize returns
|
||||
// the expected output and error for each.
|
||||
for _, test := range tests {
|
||||
res, err := parseFilesize(test.in)
|
||||
if res != test.out || err != test.err {
|
||||
t.Errorf("parseFilesize(%v): expected %v %v, got %v %v", test.in, test.out, test.err, res, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
<a name="questions"/>
|
||||
## Questions?
|
||||
Read these if you haven't already:
|
||||
* [doc/Guide to Contributing to Sia.md][guide]: getting started with Go, Sia,
|
||||
and git
|
||||
* [doc/Developers.md][developers]: conventions and quality standards for Sia
|
||||
code
|
||||
|
||||
Some other useful resources, some of which have been linked to already:
|
||||
* [Golang.org page on the go testing package][pkg/testing]
|
||||
* [Writing Table-Driven Tests in Go][table]
|
||||
* [How to Write Benchmarks in Go][cheney-benchmarks]
|
||||
* [How to into git and GitHub][luke]: an essential introduction to git
|
||||
|
||||
And feel free to ask questions on the [#dev channel][slack] on the Sia Slack.
|
||||
Odds are, someone else is wondering the same thing.
|
||||
|
||||
[pkg/testing]: https://golang.org/pkg/testing/
|
||||
[makefile]: https://github.com/NebulousLabs/Sia/blob/master/Makefile
|
||||
[luke]: https://gist.github.com/lukechampine/6418449
|
||||
[guide]: https://github.com/NebulousLabs/Sia/blob/master/doc/Guide%20to%20Contributing%20to%20Sia.md
|
||||
[developers]: https://github.com/NebulousLabs/Sia/blob/master/doc/Developers.md
|
||||
[table]: http://dave.cheney.net/2013/06/09/writing-table-driven-tests-in-go
|
||||
[boltdb_test.go]: https://github.com/NebulousLabs/Sia/blob/master/persist/boltdb_test.go
|
||||
[cheney-benchmarks]: http://dave.cheney.net/2013/06/30/how-to-write-benchmarks-in-go
|
||||
[pkg/testing]: https://golang.org/pkg/testing/
|
||||
[slack]: https://siatalk.slack.com/messages/dev/
|
||||
[parse_test]: https://github.com/NebulousLabs/Sia/blob/master/siac/parse_test.go
|
||||
[global]: http://c2.com/cgi/wiki?GlobalVariablesAreBad
|
61
3rd_party/Sia-v1.1.1-windows-amd64/doc/Standard.md
vendored
Normal file
61
3rd_party/Sia-v1.1.1-windows-amd64/doc/Standard.md
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
Standard Transaction Rules
|
||||
==========================
|
||||
|
||||
Some transactions will not be accepted by miners unless they appear in a block.
|
||||
This is equivalent to the 'IsStandard' function in Bitcoin. This file dictates
|
||||
the rules for standard Sia transactions.
|
||||
|
||||
Transaction Size
|
||||
----------------
|
||||
|
||||
Consensus rules limit the size of a block, but not the size of a transaction.
|
||||
Standard rules however limit the size of a single transaction to 16kb.
|
||||
|
||||
A chain of dependent transactions cannot exceed 500kb.
|
||||
|
||||
Double Spend Rules
|
||||
------------------
|
||||
|
||||
When two conflicting transactions are seen, the first transaction is the only
|
||||
one that is kept. If the blockchain reorganizes, the transaction that is kept
|
||||
is the transaction that was most recently in the blockchain. This is to
|
||||
discourage double spending, and enforce that the first transaction seen is the
|
||||
one that should be kept by the network. Other conflicts are thrown out.
|
||||
|
||||
Transactions are currently included into blocks using a first-come first-serve
|
||||
algorithm. Eventually, transactions will be rejected if the fee does not meet a
|
||||
certain minimum. For the near future, there are no plans to prioritize
|
||||
transactions with substantially higher fees. Other mining software may take
|
||||
alternative approaches.
|
||||
|
||||
File Contract Rules
|
||||
-------------------
|
||||
|
||||
File Contracts that start in less than 10 blocks time are not accepted into the
|
||||
transaction pool. This is because a file contract becomes invalid if it is not
|
||||
accepted into the blockchain by the start block, and this might result in a
|
||||
cascade of invalidated unconfirmed transactions, which may make it easier to
|
||||
launch double spend attacks on zero confirmation outputs. 10 blocks is plenty
|
||||
of time on the other hand for a file contract to make it into the blockchain.
|
||||
|
||||
Signature Algorithms
|
||||
--------------------
|
||||
|
||||
Miners will reject transactions that have public keys using algorithms that the
|
||||
miner does not understand.
|
||||
|
||||
Arbitrary Data Usage
|
||||
--------------------
|
||||
|
||||
Arbitrary data can be used to make verifiable announcements, or to have other
|
||||
protocols sit on top of Sia. The arbitrary data can also be used for soft
|
||||
forks, and for protocol relevant information. Any arbitrary data is allowed by
|
||||
consensus, but only certain arbitrary data is considered standard.
|
||||
|
||||
Arbitrary data that is prefixed by the string 'NonSia' is always allowed. This
|
||||
indicates that the remaining data has no relevance to Sia protocol rules, and
|
||||
never will.
|
||||
|
||||
Arbitrary data that is prefixed by the string 'HostAnnouncement' is allowed,
|
||||
but only if the data within accurately decodes to the HostAnnouncement struct
|
||||
found in modules/hostdb.go, and contains no extra information.
|
61
3rd_party/Sia-v1.1.1-windows-amd64/doc/api/Consensus.md
vendored
Normal file
61
3rd_party/Sia-v1.1.1-windows-amd64/doc/api/Consensus.md
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
Consensus API
|
||||
=============
|
||||
|
||||
This document contains detailed descriptions of the consensus's API routes. For
|
||||
an overview of the consensus' API routes, see
|
||||
[API.md#consensus](/doc/API.md#consensus). For an overview of all API routes,
|
||||
see [API.md](/doc/API.md)
|
||||
|
||||
There may be functional API calls which are not documented. These are not
|
||||
guaranteed to be supported beyond the current release, and should not be used
|
||||
in production.
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
The consensus set manages everything related to consensus and keeps the
|
||||
blockchain in sync with the rest of the network. The consensus set's API
|
||||
endpoint returns information about the state of the blockchain.
|
||||
|
||||
Index
|
||||
-----
|
||||
|
||||
| Route | HTTP verb |
|
||||
| --------------------------------------------------------------------------- | --------- |
|
||||
| [/consensus](#consensus-get) | GET |
|
||||
| [/consensus/validate/transactionset](#consensusvalidatetransactionset-post) | POST |
|
||||
|
||||
#### /consensus [GET]
|
||||
|
||||
returns information about the consensus set, such as the current block height.
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
// True if the consensus set is synced with the network, i.e. it has downloaded the entire blockchain.
|
||||
"synced": true,
|
||||
|
||||
// Number of blocks preceding the current block.
|
||||
"height": 62248,
|
||||
|
||||
// Hash of the current block.
|
||||
"currentblock": "00000000000008a84884ba827bdc868a17ba9c14011de33ff763bd95779a9cf1",
|
||||
|
||||
// An immediate child block of this block must have a hash less than this
|
||||
// target for it to be valid.
|
||||
"target": [0,0,0,0,0,0,11,48,125,79,116,89,136,74,42,27,5,14,10,31,23,53,226,238,202,219,5,204,38,32,59,165]
|
||||
}
|
||||
```
|
||||
|
||||
#### /consensus/validate/transactionset [POST]
|
||||
|
||||
validates a set of transactions using the current utxo set.
|
||||
|
||||
###### Request Body Bytes
|
||||
|
||||
Since transactions may be large, the transaction set is supplied in the POST
|
||||
body, encoded in JSON format.
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[#standard-responses](#standard-responses).
|
100
3rd_party/Sia-v1.1.1-windows-amd64/doc/api/Daemon.md
vendored
Normal file
100
3rd_party/Sia-v1.1.1-windows-amd64/doc/api/Daemon.md
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
Daemon API
|
||||
===========
|
||||
|
||||
This document contains detailed descriptions of the daemon's API routes. For an
|
||||
overview of the daemon's API routes, see [API.md#daemon](/doc/API.md#daemon).
|
||||
For an overview of all API routes, see [API.md](/doc/API.md)
|
||||
|
||||
There may be functional API calls which are not documented. These are not
|
||||
guaranteed to be supported beyond the current release, and should not be used
|
||||
in production.
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
The daemon is responsible for starting and stopping the modules which make up
|
||||
the rest of Sia. It also provides endpoints for viewing build constants.
|
||||
|
||||
Index
|
||||
-----
|
||||
|
||||
| Route | HTTP verb |
|
||||
| ----------------------------------------- | --------- |
|
||||
| [/daemon/constants](#daemonconstants-get) | GET |
|
||||
| [/daemon/stop](#daemonstop-get) | GET |
|
||||
| [/daemon/version](#daemonversion-get) | GET |
|
||||
|
||||
#### /daemon/constants [GET]
|
||||
|
||||
returns the set of constants in use.
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
// Timestamp of the genesis block.
|
||||
"genesistimestamp": 1433600000, // Unix time
|
||||
// Maximum size, in bytes, of a block. Blocks larger than this will be
|
||||
// rejected by peers.
|
||||
"blocksizelimit": 2000000, // bytes
|
||||
// Target for how frequently new blocks should be mined.
|
||||
"blockfrequency": 600, // seconds per block
|
||||
// Height of the window used to adjust the difficulty.
|
||||
"targetwindow": 1000, // blocks
|
||||
// Duration of the window used to adjust the difficulty.
|
||||
"mediantimestampwindow": 11, // blocks
|
||||
// How far in the future a block can be without being rejected. A block
|
||||
// further into the future will not be accepted immediately, but the daemon
|
||||
// will attempt to accept the block as soon as it is valid.
|
||||
"futurethreshold": 10800, // seconds
|
||||
// Total number of siafunds.
|
||||
"siafundcount": "10000",
|
||||
// Fraction of each file contract payout given to siafund holders.
|
||||
"siafundportion": "39/1000",
|
||||
// Number of children a block must have before it is considered "mature."
|
||||
"maturitydelay": 144, // blocks
|
||||
|
||||
// Number of coins given to the miner of the first block. Note that elsewhere
|
||||
// in the API currency is typically returned in hastings and as a bignum.
|
||||
// This is not the case here.
|
||||
"initialcoinbase": 300000, // Siacoins.
|
||||
// Minimum number of coins paid out to the miner of a block (the coinbase
|
||||
// decreases with each block). Note that elsewhere in the API currency is
|
||||
// typically returned in hastings and as a bignum. This is not the case
|
||||
// here.
|
||||
"minimumcoinbase": 30000, // Siacoins
|
||||
|
||||
// Initial target.
|
||||
"roottarget": [0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
|
||||
// Initial depth.
|
||||
"rootdepth": [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255],
|
||||
|
||||
// Largest allowed ratio between the old difficulty and the new difficulty.
|
||||
"maxadjustmentup": "5/2",
|
||||
// Smallest allowed ratio between the old difficulty and the new difficulty.
|
||||
"maxadjustmentdown": "2/5",
|
||||
|
||||
// Number of Hastings in one siacoin.
|
||||
"siacoinprecision": "1000000000000000000000000" // hastings per siacoin
|
||||
}
|
||||
```
|
||||
|
||||
#### /daemon/stop [GET]
|
||||
|
||||
cleanly shuts down the daemon. May take a few seconds.
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[#standard-responses](#standard-responses).
|
||||
|
||||
#### /daemon/version [GET]
|
||||
|
||||
returns the version of the Sia daemon currently running.
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
// Version number of the running Sia Daemon. This number is visible to its
|
||||
// peers on the network.
|
||||
"version": "1.0.0"
|
||||
}
|
||||
```
|
159
3rd_party/Sia-v1.1.1-windows-amd64/doc/api/Gateway.md
vendored
Normal file
159
3rd_party/Sia-v1.1.1-windows-amd64/doc/api/Gateway.md
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
Gateway API
|
||||
===========
|
||||
|
||||
This document contains detailed descriptions of the gateway's API routes. For
|
||||
an overview of the gateway's API routes, see
|
||||
[API.md#gateway](/doc/API.md#gateway). For an overview of all API routes, see
|
||||
[API.md](/doc/API.md)
|
||||
|
||||
There may be functional API calls which are not documented. These are not
|
||||
guaranteed to be supported beyond the current release, and should not be used
|
||||
in production.
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
The gateway maintains a peer to peer connection to the network and provides a
|
||||
method for calling RPCs on connected peers. The gateway's API endpoints expose
|
||||
methods for viewing the connected peers, manually connecting to peers, and
|
||||
manually disconnecting from peers. The gateway may connect or disconnect from
|
||||
peers on its own.
|
||||
|
||||
Index
|
||||
-----
|
||||
|
||||
| Route | HTTP verb | Examples |
|
||||
| ---------------------------------------------------------------------------------- | --------- | ------------------------------------------------------- |
|
||||
| [/gateway](#gateway-get-example) | GET | [Gateway info](#gateway-info) |
|
||||
| [/gateway/connect/___:netaddress___](#gatewayconnectnetaddress-post-example) | POST | [Connecting to a peer](#connecting-to-a-peer) |
|
||||
| [/gateway/disconnect/___:netaddress___](#gatewaydisconnectnetaddress-post-example) | POST | [Disconnecting from a peer](#disconnecting-from-a-peer) |
|
||||
|
||||
#### /gateway [GET] [(example)](#gateway-info)
|
||||
|
||||
returns information about the gateway, including the list of connected peers.
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
// netaddress is the network address of the gateway as seen by the rest of
|
||||
// the network. The address consists of the external IP address and the
|
||||
// port Sia is listening on. It represents a `modules.NetAddress`.
|
||||
"netaddress": String,
|
||||
|
||||
// peers is an array of peers the gateway is connected to. It represents
|
||||
// an array of `modules.Peer`s.
|
||||
"peers": []{
|
||||
// netaddress is the address of the peer. It represents a
|
||||
// `modules.NetAddress`.
|
||||
"netaddress": String,
|
||||
|
||||
// version is the version number of the peer.
|
||||
"version": String,
|
||||
|
||||
// inbound is true when the peer initiated the connection. This field
|
||||
// is exposed as outbound peers are generally trusted more than inbound
|
||||
// peers, as inbound peers are easily manipulated by an adversary.
|
||||
"inbound": Boolean
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### /gateway/connect/{netaddress} [POST] [(example)](#connecting-to-a-peer)
|
||||
|
||||
connects the gateway to a peer. The peer is added to the node list if it is not
|
||||
already present. The node list is the list of all nodes the gateway knows
|
||||
about, but is not necessarily connected to.
|
||||
|
||||
###### Path Parameters
|
||||
```
|
||||
// netaddress is the address of the peer to connect to. It should be a
|
||||
// reachable ip address and port number, of the form 'IP:port'. IPV6 addresses
|
||||
// must be enclosed in square brackets.
|
||||
//
|
||||
// Example IPV4 address: 123.456.789.0:123
|
||||
// Example IPV6 address: [123::456]:789
|
||||
:netaddress
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[API.md#standard-responses](/doc/API.md#standard-responses).
|
||||
|
||||
#### /gateway/disconnect/{netaddress} [POST] [(example)](#disconnecting-from-a-peer)
|
||||
|
||||
disconnects the gateway from a peer. The peer remains in the node list.
|
||||
Disconnecting from a peer does not prevent the gateway from automatically
|
||||
connecting to the peer in the future.
|
||||
|
||||
###### Path Parameters
|
||||
```
|
||||
// netaddress is the address of the peer to connect to. It should be a
|
||||
// reachable ip address and port number, of the form 'IP:port'. IPV6 addresses
|
||||
// must be enclosed in square brackets.
|
||||
//
|
||||
// Example IPV4 address: 123.456.789.0:123
|
||||
// Example IPV6 address: [123::456]:789
|
||||
:netaddress
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[API.md#standard-responses](/doc/API.md#standard-responses).
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
#### Gateway info
|
||||
|
||||
###### Request
|
||||
```
|
||||
/gateway
|
||||
```
|
||||
|
||||
###### Expected Response Code
|
||||
```
|
||||
200 OK
|
||||
```
|
||||
|
||||
###### Example JSON Response
|
||||
```json
|
||||
{
|
||||
"netaddress":"333.333.333.333:9981",
|
||||
"peers":[
|
||||
{
|
||||
"netaddress":"222.222.222.222:9981",
|
||||
"version":"1.0.0",
|
||||
"inbound":false
|
||||
},
|
||||
{
|
||||
"netaddress":"111.111.111.111:9981",
|
||||
"version":"0.6.0",
|
||||
"inbound":true
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### Connecting to a peer
|
||||
|
||||
###### Request
|
||||
```
|
||||
/gateway/connect/123.456.789.0:123
|
||||
```
|
||||
|
||||
###### Expected Response Code
|
||||
```
|
||||
204 No Content
|
||||
```
|
||||
|
||||
#### Disconnecting from a peer
|
||||
|
||||
###### Request
|
||||
```
|
||||
/gateway/disconnect/123.456.789.0:123
|
||||
```
|
||||
|
||||
###### Expected Response Code
|
||||
```
|
||||
204 No Content
|
||||
```
|
536
3rd_party/Sia-v1.1.1-windows-amd64/doc/api/Host.md
vendored
Normal file
536
3rd_party/Sia-v1.1.1-windows-amd64/doc/api/Host.md
vendored
Normal file
@@ -0,0 +1,536 @@
|
||||
Host API
|
||||
--------
|
||||
|
||||
This document contains detailed descriptions of the host's API routes. For an
|
||||
overview of the host's API routes, see [API.md#host](/doc/API.md#host). For an
|
||||
overview of all API routes, see [API.md](/doc/API.md)
|
||||
|
||||
There may be functional API calls which are not documented. These are not
|
||||
guaranteed to be supported beyond the current release, and should not be used
|
||||
in production.
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
The host provides storage from local disks to the network. The host negotiates
|
||||
file contracts with remote renters to earn money for storing other users'
|
||||
files. The host's endpoints expose methods for viewing and modifying host
|
||||
settings, announcing to the network, and managing how files are stored on disk.
|
||||
|
||||
Index
|
||||
-----
|
||||
|
||||
| Route | HTTP verb |
|
||||
| ------------------------------------------------------------------------------------- | --------- |
|
||||
| [/host](#host-get) | GET |
|
||||
| [/host](#host-post) | POST |
|
||||
| [/host/announce](#hostannounce-post) | POST |
|
||||
| [/host/storage](#hoststorage-get) | GET |
|
||||
| [/host/storage/folders/add](#hoststoragefoldersadd-post) | POST |
|
||||
| [/host/storage/folders/remove](#hoststoragefoldersremove-post) | POST |
|
||||
| [/host/storage/folders/resize](#hoststoragefoldersresize-post) | POST |
|
||||
| [/host/storage/sectors/delete/___:merkleroot___](#hoststoragesectorsdeletemerkleroot) | POST |
|
||||
|
||||
#### /host [GET]
|
||||
|
||||
fetches status information about the host.
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
// The settings that get displayed to untrusted nodes querying the host's
|
||||
// status.
|
||||
"externalsettings": {
|
||||
// Whether or not the host is accepting new contracts.
|
||||
"acceptingcontracts": true,
|
||||
|
||||
// The maximum size of a single download request from a renter. Each
|
||||
// download request has multiple round trips of communication that
|
||||
// exchange money. Larger batch sizes mean fewer round trips, but more
|
||||
// financial risk for the host - the renter can get a free batch when
|
||||
// downloading by refusing to provide a signature.
|
||||
"maxdownloadbatchsize": 17825792, // bytes
|
||||
|
||||
// The maximum duration that a host will allow for a file contract. The
|
||||
// host commits to keeping files for the full duration under the threat
|
||||
// of facing a large penalty for losing or dropping data before the
|
||||
// duration is complete. The storage proof window of an incoming file
|
||||
// contract must end before the current height + maxduration.
|
||||
"maxduration": 25920, // blocks
|
||||
|
||||
// The maximum size of a single batch of file contract revisions. The
|
||||
// renter can perform DoS attacks on the host by uploading a batch of
|
||||
// data then refusing to provide a signature to pay for the data. The
|
||||
// host can reduce this exposure by limiting the batch size. Larger
|
||||
// batch sizes allow for higher throughput as there is significant
|
||||
// communication overhead associated with performing a batch upload.
|
||||
"maxrevisebatchsize": 17825792, // bytes
|
||||
|
||||
// The IP address or hostname (including port) that the host should be
|
||||
// contacted at.
|
||||
"netaddress": "123.456.789.0:9982",
|
||||
|
||||
// The amount of unused storage capacity on the host in bytes. It
|
||||
// should be noted that the host can lie.
|
||||
"remainingstorage": 35000000000, // bytes
|
||||
|
||||
// The smallest amount of data in bytes that can be uploaded or
|
||||
// downloaded when performing calls to the host.
|
||||
"sectorsize": 4194304, // bytes
|
||||
|
||||
// The total amount of storage capacity on the host. It should be noted
|
||||
// that the host can lie.
|
||||
"totalstorage": 35000000000, // bytes
|
||||
|
||||
// The unlock hash is the address at which the host can be paid when
|
||||
// forming file contracts.
|
||||
"unlockhash": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789ab",
|
||||
|
||||
// The storage proof window is the number of blocks that the host has
|
||||
// to get a storage proof onto the blockchain. The window size is the
|
||||
// minimum size of window that the host will accept in a file contract.
|
||||
"windowsize": 144, // blocks
|
||||
|
||||
// The maximum amount of money that the host will put up as collateral
|
||||
// for storage that is contracted by the renter.
|
||||
"collateral": "57870370370", // hastings / byte / block
|
||||
|
||||
// The maximum amount of collateral that the host will put into a
|
||||
// single file contract.
|
||||
"maxcollateral": "100000000000000000000000000000", // hastings
|
||||
|
||||
// The price that a renter has to pay to create a contract with the
|
||||
// host. The payment is intended to cover transaction fees
|
||||
// for the file contract revision and the storage proof that the host
|
||||
// will be submitting to the blockchain.
|
||||
"contractprice": "30000000000000000000000000", // hastings
|
||||
|
||||
// The price that a renter has to pay when downloading data from the
|
||||
// host.
|
||||
"downloadbandwidthprice": "250000000000000", // hastings / byte
|
||||
|
||||
// The price that a renter has to pay to store files with the host.
|
||||
"storageprice": "231481481481", // hastings / byte / block
|
||||
|
||||
// The price that a renter has to pay when uploading data to the host.
|
||||
"uploadbandwidthprice": "100000000000000", // hastings / byte
|
||||
|
||||
// The revision number indicates to the renter what iteration of
|
||||
// settings the host is currently at. Settings are generally signed.
|
||||
// If the renter has multiple conflicting copies of settings from the
|
||||
// host, the renter can expect the one with the higher revision number
|
||||
// to be more recent.
|
||||
"revisionnumber": 0,
|
||||
|
||||
// The version of external settings being used. This field helps
|
||||
// coordinate updates while preserving compatibility with older nodes.
|
||||
"version": "1.0.0"
|
||||
},
|
||||
|
||||
// The financial status of the host.
|
||||
"financialmetrics": {
|
||||
// Number of open file contracts.
|
||||
"contractcount": 2,
|
||||
|
||||
// The amount of money that renters have given to the host to pay for
|
||||
// file contracts. The host is required to submit a file contract
|
||||
// revision and a storage proof for every file contract that gets created,
|
||||
// and the renter pays for the miner fees on these objects.
|
||||
"contractcompensation": "123", // hastings
|
||||
|
||||
// The amount of money that renters have given to the host to pay for
|
||||
// file contracts which have not been confirmed yet. The potential
|
||||
// compensation becomes compensation after the storage proof is
|
||||
// submitted.
|
||||
"potentialcontractcompensation": "123", // hastings
|
||||
|
||||
// The amount of storage collateral which the host has tied up in file
|
||||
// contracts. The host has to commit collateral to a file contract even
|
||||
// if there is no storage, but the locked collateral will be returned
|
||||
// even if the host does not submit a storage proof - the collateral is
|
||||
// not at risk, it is merely set aside so that it can be put at risk
|
||||
// later.
|
||||
"lockedstoragecollateral": "123", // hastings
|
||||
|
||||
// The amount of revenue, including storage revenue and bandwidth
|
||||
// revenue, that has been lost due to failed file contracts and
|
||||
// failed storage proofs.
|
||||
"lostrevenue": "123", // hastings
|
||||
|
||||
// The amount of collateral that was put up to protect data which has
|
||||
// been lost due to failed file contracts and missed storage proofs.
|
||||
"loststoragecollateral": "123", // hastings
|
||||
|
||||
// The amount of revenue that the host stands to earn if all storage
|
||||
// proofs are submitted corectly and in time.
|
||||
"potentialstoragerevenue": "123", // hastings
|
||||
|
||||
// The amount of money that the host has risked on file contracts. If
|
||||
// the host starts missing storage proofs, the host can forfeit up to
|
||||
// this many coins. In the event of a missed storage proof, locked
|
||||
// storage collateral gets returned, but risked storage collateral
|
||||
// does not get returned.
|
||||
"riskedstoragecollateral": "123", // hastings
|
||||
|
||||
// The amount of money that the host has earned from storing data. This
|
||||
// money has been locked down by successful storage proofs.
|
||||
"storagerevenue": "123", // hastings
|
||||
|
||||
// The amount of money that the host has spent on transaction fees when
|
||||
// submitting host announcements, file contract revisions, and storage
|
||||
// proofs.
|
||||
"transactionfeeexpenses": "123", // hastings
|
||||
|
||||
// The amount of money that the host has made from renters downloading
|
||||
// their files. This money has been locked in by successsful storage
|
||||
// proofs.
|
||||
"downloadbandwidthrevenue": "123", // hastings
|
||||
|
||||
// The amount of money that the host stands to make from renters that
|
||||
// downloaded their files. The host will only realize this revenue if
|
||||
// the host successfully submits storage proofs for the related file
|
||||
// contracts.
|
||||
"potentialdownloadbandwidthrevenue": "123", // hastings
|
||||
|
||||
// The amount of money that the host stands to make from renters that
|
||||
// uploaded files. The host will only realize this revenue if the host
|
||||
// successfully submits storage proofs for the related file contracts.
|
||||
"potentialuploadbandwidthrevenue": "123", // hastings
|
||||
|
||||
// The amount of money that the host has made from renters uploading
|
||||
// their files. This money has been locked in by successful storage
|
||||
// proofs.
|
||||
"uploadbandwidthrevenue": "123" // hastings
|
||||
},
|
||||
|
||||
// The settings of the host. Most interactions between the user and the
|
||||
// host occur by changing the internal settings.
|
||||
"internalsettings": {
|
||||
// When set to true, the host will accept new file contracts if the
|
||||
// terms are reasonable. When set to false, the host will not accept new
|
||||
// file contracts at all.
|
||||
"acceptingcontracts": true,
|
||||
|
||||
// The maximum size of a single download request from a renter. Each
|
||||
// download request has multiple round trips of communication that
|
||||
// exchange money. Larger batch sizes mean fewer round trips, but more
|
||||
// financial risk for the host - the renter can get a free batch when
|
||||
// downloading by refusing to provide a signature.
|
||||
"maxdownloadbatchsize": 17825792, // bytes
|
||||
|
||||
// The maximum duration of a file contract that the host will accept.
|
||||
// The storage proof window must end before the current height +
|
||||
// maxduration.
|
||||
"maxduration": 25920, // blocks
|
||||
|
||||
// The maximum size of a single batch of file contract revisions. The
|
||||
// renter can perform DoS attacks on the host by uploading a batch of
|
||||
// data then refusing to provide a signature to pay for the data. The
|
||||
// host can reduce this exposure by limiting the batch size. Larger
|
||||
// batch sizes allow for higher throughput as there is significant
|
||||
// communication overhead associated with performing a batch upload.
|
||||
"maxrevisebatchsize": 17825792, // bytes
|
||||
|
||||
// The IP address or hostname (including port) that the host should be
|
||||
// contacted at. If left blank, the host will automatically figure out
|
||||
// its ip address and use that. If given, the host will use the address
|
||||
// given.
|
||||
"netaddress": "123.456.789.0:9982",
|
||||
|
||||
// The storage proof window is the number of blocks that the host has
|
||||
// to get a storage proof onto the blockchain. The window size is the
|
||||
// minimum size of window that the host will accept in a file contract.
|
||||
"windowsize": 144, // blocks
|
||||
|
||||
// The maximum amount of money that the host will put up as collateral
|
||||
// per byte per block of storage that is contracted by the renter.
|
||||
"collateral": "57870370370", // hastings / byte / block
|
||||
|
||||
// The total amount of money that the host will allocate to collateral
|
||||
// across all file contracts.
|
||||
"collateralbudget": "2000000000000000000000000000000", // hastings
|
||||
|
||||
// The maximum amount of collateral that the host will put into a
|
||||
// single file contract.
|
||||
"maxcollateral": "100000000000000000000000000000", // hastings
|
||||
|
||||
// The minimum price that the host will demand from a renter when
|
||||
// forming a contract. Typically this price is to cover transaction
|
||||
// fees on the file contract revision and storage proof, but can also
|
||||
// be used if the host has a low amount of collateral. The price is a
|
||||
// minimum because the host may automatically adjust the price upwards
|
||||
// in times of high demand.
|
||||
"mincontractprice": "30000000000000000000000000", // hastings
|
||||
|
||||
// The minimum price that the host will demand from a renter when the
|
||||
// renter is downloading data. If the host is saturated, the host may
|
||||
// increase the price from the minimum.
|
||||
"mindownloadbandwidthprice": "250000000000000", // hastings / byte
|
||||
|
||||
// The minimum price that the host will demand when storing data for
|
||||
// extended periods of time. If the host is low on space, the price of
|
||||
// storage may be set higher than the minimum.
|
||||
"minstorageprice": "231481481481", // hastings / byte / block
|
||||
|
||||
// The minimum price that the host will demand from a renter when the
|
||||
// renter is uploading data. If the host is saturated, the host may
|
||||
// increase the price from the minimum.
|
||||
"minuploadbandwidthprice": "100000000000000" // hastings / byte
|
||||
},
|
||||
|
||||
// Information about the network, specifically various ways in which
|
||||
// renters have contacted the host.
|
||||
"networkmetrics": {
|
||||
// The number of times that a renter has attempted to download
|
||||
// something from the host.
|
||||
"downloadcalls": 0,
|
||||
|
||||
// The number of calls that have resulted in errors. A small number of
|
||||
// errors are expected, but a large number of errors indicate either
|
||||
// buggy software or malicious network activity. Usually buggy
|
||||
// software.
|
||||
"errorcalls": 1,
|
||||
|
||||
// The number of times that a renter has tried to form a contract with
|
||||
// the host.
|
||||
"formcontractcalls": 2,
|
||||
|
||||
// The number of times that a renter has tried to renew a contract with
|
||||
// the host.
|
||||
"renewcalls": 3,
|
||||
|
||||
// The number of times that the renter has tried to revise a contract
|
||||
// with the host.
|
||||
"revisecalls": 4,
|
||||
|
||||
// The number of times that a renter has queried the host for the
|
||||
// host's settings. The settings include the price of bandwidth, which
|
||||
// is a price that can adjust every few minutes. This value is usually
|
||||
// very high compared to the others.
|
||||
"settingscalls": 5,
|
||||
|
||||
// The number of times that a renter has attempted to use an
|
||||
// unrecognized call. Larger numbers typically indicate buggy software.
|
||||
"unrecognizedcalls": 6
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### /host [POST]
|
||||
|
||||
configures hosting parameters. All parameters are optional; unspecified
|
||||
parameters will be left unchanged.
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// When set to true, the host will accept new file contracts if the
|
||||
// terms are reasonable. When set to false, the host will not accept new
|
||||
// file contracts at all.
|
||||
acceptingcontracts // Optional, true / false
|
||||
|
||||
// The maximum size of a single download request from a renter. Each
|
||||
// download request has multiple round trips of communication that
|
||||
// exchange money. Larger batch sizes mean fewer round trips, but more
|
||||
// financial risk for the host - the renter can get a free batch when
|
||||
// downloading by refusing to provide a signature.
|
||||
maxdownloadbatchsize // Optional, bytes
|
||||
|
||||
// The maximum duration of a file contract that the host will accept.
|
||||
// The storage proof window must end before the current height +
|
||||
// maxduration.
|
||||
maxduration // Optional, blocks
|
||||
|
||||
// The maximum size of a single batch of file contract revisions. The
|
||||
// renter can perform DoS attacks on the host by uploading a batch of
|
||||
// data then refusing to provide a signature to pay for the data. The
|
||||
// host can reduce this exposure by limiting the batch size. Larger
|
||||
// batch sizes allow for higher throughput as there is significant
|
||||
// communication overhead associated with performing a batch upload.
|
||||
maxrevisebatchsize // Optional, bytes
|
||||
|
||||
// The IP address or hostname (including port) that the host should be
|
||||
// contacted at. If left blank, the host will automatically figure out
|
||||
// its ip address and use that. If given, the host will use the address
|
||||
// given.
|
||||
netaddress // Optional
|
||||
|
||||
// The storage proof window is the number of blocks that the host has
|
||||
// to get a storage proof onto the blockchain. The window size is the
|
||||
// minimum size of window that the host will accept in a file contract.
|
||||
windowsize // Optional, blocks
|
||||
|
||||
// The maximum amount of money that the host will put up as collateral
|
||||
// per byte per block of storage that is contracted by the renter.
|
||||
collateral // Optional, hastings / byte / block
|
||||
|
||||
// The total amount of money that the host will allocate to collateral
|
||||
// across all file contracts.
|
||||
collateralbudget // Optional, hastings
|
||||
|
||||
// The maximum amount of collateral that the host will put into a
|
||||
// single file contract.
|
||||
maxcollateral // Optional, hastings
|
||||
|
||||
// The minimum price that the host will demand from a renter when
|
||||
// forming a contract. Typically this price is to cover transaction
|
||||
// fees on the file contract revision and storage proof, but can also
|
||||
// be used if the host has a low amount of collateral. The price is a
|
||||
// minimum because the host may automatically adjust the price upwards
|
||||
// in times of high demand.
|
||||
mincontractprice // Optional, hastings
|
||||
|
||||
// The minimum price that the host will demand from a renter when the
|
||||
// renter is downloading data. If the host is saturated, the host may
|
||||
// increase the price from the minimum.
|
||||
mindownloadbandwidthprice // Optional, hastings / byte
|
||||
|
||||
// The minimum price that the host will demand when storing data for
|
||||
// extended periods of time. If the host is low on space, the price of
|
||||
// storage may be set higher than the minimum.
|
||||
minstorageprice // Optional, hastings / byte / block
|
||||
|
||||
// The minimum price that the host will demand from a renter when the
|
||||
// renter is uploading data. If the host is saturated, the host may
|
||||
// increase the price from the minimum.
|
||||
minuploadbandwidthprice // Optional, hastings / byte
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[#standard-responses](#standard-responses).
|
||||
|
||||
#### /host/announce [POST]
|
||||
|
||||
Announce the host to the network as a source of storage. Generally only needs
|
||||
to be called once.
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// The address to be announced. If no address is provided, the automatically
|
||||
// discovered address will be used instead.
|
||||
netaddress string // Optional
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[#standard-responses](#standard-responses).
|
||||
|
||||
#### /host/storage [GET]
|
||||
|
||||
gets a list of folders tracked by the host's storage manager.
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
// Absolute path to the storage folder on the local filesystem.
|
||||
"path": "/home/foo/bar",
|
||||
|
||||
// Maximum capacity of the storage folder. The host will not store more
|
||||
// than this many bytes in the folder. This capacity is not checked
|
||||
// against the drive's remaining capacity. Therefore, you must manually
|
||||
// ensure the disk has sufficient capacity for the folder at all times.
|
||||
// Otherwise you risk losing renter's data and failing storage proofs.
|
||||
"capacity": 50000000000, // bytes
|
||||
|
||||
// Unused capacity of the storage folder.
|
||||
"capacityremaining": 100000, // bytes
|
||||
|
||||
// Number of failed disk read & write operations. A large number of
|
||||
// failed reads or writes indicates a problem with the filesystem or
|
||||
// drive's hardware.
|
||||
"failedreads": 0,
|
||||
"failedwrites": 1,
|
||||
|
||||
// Number of successful read & write operations.
|
||||
"successfulreads": 2,
|
||||
"successfulwrites": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### /host/storage/folders/add [POST]
|
||||
|
||||
adds a storage folder to the manager. The manager may not check that there is
|
||||
enough space available on-disk to support as much storage as requested
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// Local path on disk to the storage folder to add.
|
||||
path // Required
|
||||
|
||||
// Initial capacity of the storage folder. This value isn't validated so it is
|
||||
// possible to set the capacity of the storage folder greater than the capacity
|
||||
// of the disk. Do not do this.
|
||||
size // bytes, Required
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[#standard-responses](#standard-responses).
|
||||
|
||||
#### /host/storage/folders/remove [POST]
|
||||
|
||||
remove a storage folder from the manager. All storage on the folder will be
|
||||
moved to other storage folders, meaning that no data will be lost. If the
|
||||
manager is unable to save data, an error will be returned and the operation
|
||||
will be stopped.
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// Local path on disk to the storage folder to remove.
|
||||
path // Required
|
||||
|
||||
// If `force` is true, the storage folder will be removed even if the data in
|
||||
// the storage folder cannot be moved to other storage folders, typically
|
||||
// because they don't have sufficient capacity. If `force` is true and the data
|
||||
// cannot be moved, data will be lost.
|
||||
force // bool, Optional, default is false
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[#standard-responses](#standard-responses).
|
||||
|
||||
#### /host/storage/folders/resize [POST]
|
||||
|
||||
grows or shrink a storage folder in the manager. The manager may not check that
|
||||
there is enough space on-disk to support growing the storage folder, but should
|
||||
gracefully handle running out of space unexpectedly. When shrinking a storage
|
||||
folder, any data in the folder that needs to be moved will be placed into other
|
||||
storage folders, meaning that no data will be lost. If the manager is unable to
|
||||
migrate the data, an error will be returned and the operation will be stopped.
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// Local path on disk to the storage folder to resize.
|
||||
path // Required
|
||||
|
||||
// Desired new size of the storage folder. This will be the new capacity of the
|
||||
// storage folder.
|
||||
newsize // bytes, Required
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[#standard-responses](#standard-responses).
|
||||
|
||||
#### /host/storage/sectors/delete/___*merkleroot___ [POST]
|
||||
|
||||
deletes a sector, meaning that the manager will be unable to upload that sector
|
||||
and be unable to provide a storage proof on that sector. This endpoint is for
|
||||
removing the data entirely, and will remove instances of the sector appearing
|
||||
at all heights. The primary purpose is to comply with legal requests to remove
|
||||
data.
|
||||
|
||||
###### Path Parameters
|
||||
```
|
||||
// Merkleroot of the sector to delete.
|
||||
:merkleroot
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[#standard-responses](#standard-responses).
|
464
3rd_party/Sia-v1.1.1-windows-amd64/doc/api/HostDB.md
vendored
Normal file
464
3rd_party/Sia-v1.1.1-windows-amd64/doc/api/HostDB.md
vendored
Normal file
@@ -0,0 +1,464 @@
|
||||
Host DB API
|
||||
===========
|
||||
|
||||
This document contains detailed descriptions of the hostdb's API routes. For an
|
||||
overview of the hostdb's API routes, see [API.md#host-db](/doc/API.md#host-db).
|
||||
For an overview of all API routes, see [API.md](/doc/API.md)
|
||||
|
||||
There may be functional API calls which are not documented. These are not
|
||||
guaranteed to be supported beyond the current release, and should not be used
|
||||
in production.
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
The hostdb maintains a database of all hosts known to the network. The database
|
||||
identifies hosts by their public key and keeps track of metrics such as price.
|
||||
|
||||
Index
|
||||
-----
|
||||
|
||||
| Request | HTTP Verb | Examples |
|
||||
| ------------------------------------------------------- | --------- | ----------------------------- |
|
||||
| [/hostdb/active](#hostdbactive-get-example) | GET | [Active hosts](#active-hosts) |
|
||||
| [/hostdb/all](#hostdball-get-example) | GET | [All hosts](#all-hosts) |
|
||||
| [/hostdb/hosts/___:pubkey___](#hostdbhosts-get-example) | GET | [Hosts](#hosts) |
|
||||
|
||||
#### /hostdb/active [GET] [(example)](#active-hosts)
|
||||
|
||||
lists all of the active hosts known to the renter, sorted by preference.
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// Number of hosts to return. The actual number of hosts returned may be less
|
||||
// if there are insufficient active hosts. Optional, the default is all active
|
||||
// hosts.
|
||||
numhosts
|
||||
```
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
"hosts": [
|
||||
{
|
||||
// true if the host is accepting new contracts.
|
||||
"acceptingcontracts": true,
|
||||
|
||||
// Maximum number of bytes that the host will allow to be requested by a
|
||||
// single download request.
|
||||
"maxdownloadbatchsize": 17825792,
|
||||
|
||||
// Maximum duration in blocks that a host will allow for a file contract.
|
||||
// The host commits to keeping files for the full duration under the
|
||||
// threat of facing a large penalty for losing or dropping data before
|
||||
// the duration is complete. The storage proof window of an incoming file
|
||||
// contract must end before the current height + maxduration.
|
||||
//
|
||||
// There is a block approximately every 10 minutes.
|
||||
// e.g. 1 day = 144 blocks
|
||||
"maxduration": 25920,
|
||||
|
||||
// Maximum size in bytes of a single batch of file contract
|
||||
// revisions. Larger batch sizes allow for higher throughput as there is
|
||||
// significant communication overhead associated with performing a batch
|
||||
// upload.
|
||||
"maxrevisebatchsize": 17825792,
|
||||
|
||||
// Remote address of the host. It can be an IPv4, IPv6, or hostname,
|
||||
// along with the port. IPv6 addresses are enclosed in square brackets.
|
||||
"netaddress": "123.456.789.0:9982",
|
||||
|
||||
// Unused storage capacity the host claims it has, in bytes.
|
||||
"remainingstorage": 35000000000,
|
||||
|
||||
// Smallest amount of data in bytes that can be uploaded or downloaded to
|
||||
// or from the host.
|
||||
"sectorsize": 4194304,
|
||||
|
||||
// Total amount of storage capacity the host claims it has, in bytes.
|
||||
"totalstorage": 35000000000,
|
||||
|
||||
// Address at which the host can be paid when forming file contracts.
|
||||
"unlockhash": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789ab",
|
||||
|
||||
// A storage proof window is the number of blocks that the host has to
|
||||
// get a storage proof onto the blockchain. The window size is the
|
||||
// minimum size of window that the host will accept in a file contract.
|
||||
"windowsize": 144,
|
||||
|
||||
// Public key used to identify and verify hosts.
|
||||
"publickey": {
|
||||
// Algorithm used for signing and verification. Typically "ed25519".
|
||||
"algorithm": "ed25519",
|
||||
|
||||
// Key used to verify signed host messages.
|
||||
"key": "RW50cm9weSBpc24ndCB3aGF0IGl0IHVzZWQgdG8gYmU="
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### /hostdb/all [GET] [(example)](#all-hosts)
|
||||
|
||||
lists all of the hosts known to the renter. Hosts are not guaranteed to be in
|
||||
any particular order, and the order may change in subsequent calls.
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
"hosts": [
|
||||
{
|
||||
// true if the host is accepting new contracts.
|
||||
"acceptingcontracts": true,
|
||||
|
||||
// Maximum number of bytes that the host will allow to be requested by a
|
||||
// single download request.
|
||||
"maxdownloadbatchsize": 17825792,
|
||||
|
||||
// Maximum duration in blocks that a host will allow for a file contract.
|
||||
// The host commits to keeping files for the full duration under the
|
||||
// threat of facing a large penalty for losing or dropping data before
|
||||
// the duration is complete. The storage proof window of an incoming file
|
||||
// contract must end before the current height + maxduration.
|
||||
//
|
||||
// There is a block approximately every 10 minutes.
|
||||
// e.g. 1 day = 144 blocks
|
||||
"maxduration": 25920,
|
||||
|
||||
// Maximum size in bytes of a single batch of file contract
|
||||
// revisions. Larger batch sizes allow for higher throughput as there is
|
||||
// significant communication overhead associated with performing a batch
|
||||
// upload.
|
||||
"maxrevisebatchsize": 17825792,
|
||||
|
||||
// Remote address of the host. It can be an IPv4, IPv6, or hostname,
|
||||
// along with the port. IPv6 addresses are enclosed in square brackets.
|
||||
"netaddress": "123.456.789.0:9982",
|
||||
|
||||
// Unused storage capacity the host claims it has, in bytes.
|
||||
"remainingstorage": 35000000000,
|
||||
|
||||
// Smallest amount of data in bytes that can be uploaded or downloaded to
|
||||
// or from the host.
|
||||
"sectorsize": 4194304,
|
||||
|
||||
// Total amount of storage capacity the host claims it has, in bytes.
|
||||
"totalstorage": 35000000000,
|
||||
|
||||
// Address at which the host can be paid when forming file contracts.
|
||||
"unlockhash": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789ab",
|
||||
|
||||
// A storage proof window is the number of blocks that the host has to
|
||||
// get a storage proof onto the blockchain. The window size is the
|
||||
// minimum size of window that the host will accept in a file contract.
|
||||
"windowsize": 144,
|
||||
|
||||
// Public key used to identify and verify hosts.
|
||||
"publickey": {
|
||||
// Algorithm used for signing and verification. Typically "ed25519".
|
||||
"algorithm": "ed25519",
|
||||
|
||||
// Key used to verify signed host messages.
|
||||
"key": "RW50cm9weSBpc24ndCB3aGF0IGl0IHVzZWQgdG8gYmU="
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### /hostdb/hosts/___:pubkey___ [GET] [(example)](#hosts)
|
||||
|
||||
fetches detailed information about a particular host, including metrics
|
||||
regarding the score of the host within the database. It should be noted that
|
||||
each renter uses different metrics for selecting hosts, and that a good score on
|
||||
in one hostdb does not mean that the host will be successful on the network
|
||||
overall.
|
||||
|
||||
###### Path Parameters
|
||||
```
|
||||
// The public key of the host. Each public key identifies a single host.
|
||||
//
|
||||
// Example Pubkey: ed25519:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
|
||||
|
||||
:pubkey
|
||||
```
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
"entry": {
|
||||
// true if the host is accepting new contracts.
|
||||
"acceptingcontracts": true,
|
||||
|
||||
// Maximum number of bytes that the host will allow to be requested by a
|
||||
// single download request.
|
||||
"maxdownloadbatchsize": 17825792,
|
||||
|
||||
// Maximum duration in blocks that a host will allow for a file contract.
|
||||
// The host commits to keeping files for the full duration under the
|
||||
// threat of facing a large penalty for losing or dropping data before
|
||||
// the duration is complete. The storage proof window of an incoming file
|
||||
// contract must end before the current height + maxduration.
|
||||
//
|
||||
// There is a block approximately every 10 minutes.
|
||||
// e.g. 1 day = 144 blocks
|
||||
"maxduration": 25920,
|
||||
|
||||
// Maximum size in bytes of a single batch of file contract
|
||||
// revisions. Larger batch sizes allow for higher throughput as there is
|
||||
// significant communication overhead associated with performing a batch
|
||||
// upload.
|
||||
"maxrevisebatchsize": 17825792,
|
||||
|
||||
// Remote address of the host. It can be an IPv4, IPv6, or hostname,
|
||||
// along with the port. IPv6 addresses are enclosed in square brackets.
|
||||
"netaddress": "123.456.789.0:9982",
|
||||
|
||||
// Unused storage capacity the host claims it has, in bytes.
|
||||
"remainingstorage": 35000000000,
|
||||
|
||||
// Smallest amount of data in bytes that can be uploaded or downloaded to
|
||||
// or from the host.
|
||||
"sectorsize": 4194304,
|
||||
|
||||
// Total amount of storage capacity the host claims it has, in bytes.
|
||||
"totalstorage": 35000000000,
|
||||
|
||||
// Address at which the host can be paid when forming file contracts.
|
||||
"unlockhash": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789ab",
|
||||
|
||||
// A storage proof window is the number of blocks that the host has to
|
||||
// get a storage proof onto the blockchain. The window size is the
|
||||
// minimum size of window that the host will accept in a file contract.
|
||||
"windowsize": 144,
|
||||
|
||||
// Public key used to identify and verify hosts.
|
||||
"publickey": {
|
||||
// Algorithm used for signing and verification. Typically "ed25519".
|
||||
"algorithm": "ed25519",
|
||||
|
||||
// Key used to verify signed host messages.
|
||||
"key": "RW50cm9weSBpc24ndCB3aGF0IGl0IHVzZWQgdG8gYmU="
|
||||
},
|
||||
|
||||
// The string representation of the full public key, used when calling
|
||||
// /hostdb/hosts.
|
||||
"publickeystring": "ed25519:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
|
||||
},
|
||||
|
||||
// A set of scores as determined by the renter. Generally, the host's final
|
||||
// final score is all of the values multiplied together. Modified renters may
|
||||
// have additional criteria that they use to judge a host, or may ignore
|
||||
// certin criteia. In general, these fields should only be used as a loose
|
||||
// guide for the score of a host, as every renter sees the world differently
|
||||
// and uses different metrics to evaluate hosts.
|
||||
"scorebreakdown": {
|
||||
// The multiplier that gets applied to the host based on how long it has
|
||||
// been a host. Older hosts typically have a lower penalty.
|
||||
"ageadjustment": 0.1234,
|
||||
|
||||
// The multiplier that gets applied to the host based on how much
|
||||
// proof-of-burn the host has performed. More burn causes a linear increase
|
||||
// in score.
|
||||
"burnadjustment": 23.456,
|
||||
|
||||
// The multiplier that gets applied to a host based on how much collateral
|
||||
// the host is offering. More collateral is typically better, though above
|
||||
// a point it can be detrimental.
|
||||
"collateraladjustment": 23.456,
|
||||
|
||||
// The multiplier that gets applied to a host based on the host's price.
|
||||
// Lower prices are almost always better. Below a certain, very low price,
|
||||
// there is no advantage.
|
||||
"priceadjustment": 0.1234,
|
||||
|
||||
// The multiplier that gets applied to a host based on how much storage is
|
||||
// remaining for the host. More storage remaining is better, to a point.
|
||||
"storageremainingadjustment": 0.1234,
|
||||
|
||||
// The multiplier that gets applied to a host based on the uptime percentage
|
||||
// of the host. The penalty increases extremely quickly as uptime drops
|
||||
// below 90%.
|
||||
"uptimeadjustment": 0.1234,
|
||||
|
||||
// The multiplier that gets applied to a host based on the version of Sia
|
||||
// that they are running. Versions get penalties if there are known bugs,
|
||||
// scaling limitations, performance limitations, etc. Generally, the most
|
||||
// recent version is always the one with the highest score.
|
||||
"versionadjustment": 0.1234
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
#### Active hosts
|
||||
|
||||
###### Request
|
||||
```
|
||||
/hostdb/active?numhosts=2
|
||||
```
|
||||
|
||||
###### Expected Response Code
|
||||
```
|
||||
200 OK
|
||||
```
|
||||
|
||||
###### Example JSON Response
|
||||
```javascript
|
||||
{
|
||||
"hosts": [
|
||||
{
|
||||
"acceptingcontracts": true,
|
||||
"maxdownloadbatchsize": 17825792,
|
||||
"maxduration": 25920,
|
||||
"maxrevisebatchsize": 17825792,
|
||||
"netaddress": "123.456.789.0:9982",
|
||||
"remainingstorage": 35000000000,
|
||||
"sectorsize": 4194304,
|
||||
"totalstorage": 35000000000,
|
||||
"unlockhash": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789ab",
|
||||
"windowsize": 144,
|
||||
"publickey": {
|
||||
"algorithm": "ed25519",
|
||||
"key": "RW50cm9weSBpc24ndCB3aGF0IGl0IHVzZWQgdG8gYmU="
|
||||
}
|
||||
"publickeystring": "ed25519:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
|
||||
},
|
||||
{
|
||||
"acceptingcontracts": true,
|
||||
"maxdownloadbatchsize": 17825792,
|
||||
"maxduration": 25920,
|
||||
"maxrevisebatchsize": 17825792,
|
||||
"netaddress": "123.456.789.1:9982",
|
||||
"remainingstorage": 314,
|
||||
"sectorsize": 4194304,
|
||||
"totalstorage": 314159265359,
|
||||
"unlockhash": "ba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210",
|
||||
"windowsize": 144,
|
||||
"publickey": {
|
||||
"algorithm": "ed25519",
|
||||
"key": "WWVzIEJydWNlIFNjaG5laWVyIGNhbiByZWFkIHRoaXM="
|
||||
}
|
||||
"publickeystring": "ed25519:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### All hosts
|
||||
|
||||
###### Request
|
||||
```
|
||||
/hostdb/all
|
||||
```
|
||||
|
||||
###### Expected Response Code
|
||||
```
|
||||
200 OK
|
||||
```
|
||||
|
||||
###### Example JSON Response
|
||||
```javascript
|
||||
{
|
||||
"hosts": [
|
||||
{
|
||||
"acceptingcontracts": false,
|
||||
"maxdownloadbatchsize": 17825792,
|
||||
"maxduration": 25920,
|
||||
"maxrevisebatchsize": 17825792,
|
||||
"netaddress": "123.456.789.2:9982",
|
||||
"remainingstorage": 314,
|
||||
"sectorsize": 4194304,
|
||||
"totalstorage": 314159265359,
|
||||
"unlockhash": "abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789",
|
||||
"windowsize": 144,
|
||||
"publickey": {
|
||||
"algorithm": "ed25519",
|
||||
"key": "SSByYW4gb3V0IG9mIDMyIGNoYXIgbG9uZyBqb2tlcy4="
|
||||
}
|
||||
"publickeystring": "ed25519:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
|
||||
},
|
||||
{
|
||||
"acceptingcontracts": true,
|
||||
"maxdownloadbatchsize": 17825792,
|
||||
"maxduration": 25920,
|
||||
"maxrevisebatchsize": 17825792,
|
||||
"netaddress": "123.456.789.0:9982",
|
||||
"remainingstorage": 35000000000,
|
||||
"sectorsize": 4194304,
|
||||
"totalstorage": 35000000000,
|
||||
"unlockhash": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789ab",
|
||||
"windowsize": 144,
|
||||
"publickey": {
|
||||
"algorithm": "ed25519",
|
||||
"key": "RW50cm9weSBpc24ndCB3aGF0IGl0IHVzZWQgdG8gYmU="
|
||||
}
|
||||
"publickeystring": "ed25519:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
|
||||
},
|
||||
{
|
||||
"acceptingcontracts": true,
|
||||
"maxdownloadbatchsize": 17825792,
|
||||
"maxduration": 25920,
|
||||
"maxrevisebatchsize": 17825792,
|
||||
"netaddress": "123.456.789.1:9982",
|
||||
"remainingstorage": 314,
|
||||
"sectorsize": 4194304,
|
||||
"totalstorage": 314159265359,
|
||||
"unlockhash": "ba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210",
|
||||
"windowsize": 144,
|
||||
"publickey": {
|
||||
"algorithm": "ed25519",
|
||||
"key": "WWVzIEJydWNlIFNjaG5laWVyIGNhbiByZWFkIHRoaXM="
|
||||
}
|
||||
"publickeystring": "ed25519:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### Hosts
|
||||
|
||||
###### Request
|
||||
```
|
||||
/hostdb/hosts/ed25519:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
|
||||
```
|
||||
|
||||
###### Expected Response Code
|
||||
```
|
||||
200 OK
|
||||
```
|
||||
|
||||
###### Example JSON Response
|
||||
```javascript
|
||||
{
|
||||
"entry": {
|
||||
"acceptingcontracts": false,
|
||||
"maxdownloadbatchsize": 17825792,
|
||||
"maxduration": 25920,
|
||||
"maxrevisebatchsize": 17825792,
|
||||
"netaddress": "123.456.789.2:9982",
|
||||
"remainingstorage": 314,
|
||||
"sectorsize": 4194304,
|
||||
"totalstorage": 314159265359,
|
||||
"unlockhash": "abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789",
|
||||
"windowsize": 144,
|
||||
"publickey": {
|
||||
"algorithm": "ed25519",
|
||||
"key": "SSByYW4gb3V0IG9mIDMyIGNoYXIgbG9uZyBqb2tlcy4="
|
||||
}
|
||||
"publickeystring": "ed25519:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
|
||||
},
|
||||
"scorebreakdown": {
|
||||
"ageadjustment": 0.1234,
|
||||
"burnadjustment": 0.1234,
|
||||
"collateraladjustment": 23.456,
|
||||
"priceadjustment": 0.1234,
|
||||
"storageremainingadjustment": 0.1234,
|
||||
"uptimeadjustment": 0.1234,
|
||||
"versionadjustment": 0.1234,
|
||||
}
|
||||
}
|
||||
```
|
124
3rd_party/Sia-v1.1.1-windows-amd64/doc/api/Miner.md
vendored
Normal file
124
3rd_party/Sia-v1.1.1-windows-amd64/doc/api/Miner.md
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
Miner API
|
||||
=========
|
||||
|
||||
This document contains detailed descriptions of the miner's API routes. For an
|
||||
overview of the miner's API routes, see [API.md#miner](/doc/API.md#miner). For
|
||||
an overview of all API routes, see [API.md](/doc/API.md)
|
||||
|
||||
There may be functional API calls which are not documented. These are not
|
||||
guaranteed to be supported beyond the current release, and should not be used
|
||||
in production.
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
The miner provides endpoints for getting headers for work and submitting solved
|
||||
headers to the network. The miner also provides endpoints for controlling a
|
||||
basic CPU mining implementation.
|
||||
|
||||
Index
|
||||
-----
|
||||
|
||||
| Route | HTTP verb |
|
||||
| ---------------------------------- | --------- |
|
||||
| [/miner](#miner-get) | GET |
|
||||
| [/miner/start](#minerstart-get) | GET |
|
||||
| [/miner/stop](#minerstop-get) | GET |
|
||||
| [/miner/header](#minerheader-get) | GET |
|
||||
| [/miner/header](#minerheader-post) | POST |
|
||||
|
||||
#### /miner [GET]
|
||||
|
||||
returns the status of the miner.
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
// Number of mined blocks. This value is remembered after restarting.
|
||||
"blocksmined": 9001,
|
||||
|
||||
// How fast the cpu is hashing, in hashes per second.
|
||||
"cpuhashrate": 1337,
|
||||
|
||||
// true if the cpu miner is active.
|
||||
"cpumining": false,
|
||||
|
||||
// Number of mined blocks that are stale, indicating that they are not
|
||||
// included in the current longest chain, likely because some other block at
|
||||
// the same height had its chain extended first.
|
||||
"staleblocksmined": 0,
|
||||
}
|
||||
```
|
||||
|
||||
#### /miner/start [GET]
|
||||
|
||||
starts a single threaded cpu miner. Does nothing if the cpu miner is already
|
||||
running.
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[API.md#standard-responses](/doc/API.md#standard-responses).
|
||||
|
||||
#### /miner/stop [GET]
|
||||
|
||||
stops the cpu miner. Does nothing if the cpu miner is not running.
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[API.md#standard-responses](/doc/API.md#standard-responses).
|
||||
|
||||
#### /miner/header [GET]
|
||||
|
||||
provides a block header that is ready to be grinded on for work.
|
||||
|
||||
###### Byte Response
|
||||
|
||||
For efficiency the header for work is returned as a raw byte encoding of the
|
||||
header, rather than encoded to JSON.
|
||||
|
||||
Blocks are mined by repeatedly changing the nonce of the header, hashing the
|
||||
header's bytes, and comparing the resulting hash to the target. The block with
|
||||
that nonce is valid if the hash is less than the target. If none of the 2^64
|
||||
possible nonces result in a header with a hash less than the target, call
|
||||
`/miner/header [GET]` again to get a new block header with a different merkle
|
||||
root. The above process can then be repeated for the new block header.
|
||||
|
||||
The other fields can generally be ignored. The parent block ID field is the
|
||||
hash of the parent block's header. Modifying this field will result in an
|
||||
orphan block. The timestamp is the time at which the block was mined and is set
|
||||
by the Sia Daemon. Modifying this field can result in invalid block. The merkle
|
||||
root is the merkle root of a merkle tree consisting of the timestamp, the miner
|
||||
outputs (one leaf per payout), and the transactions (one leaf per transaction).
|
||||
Modifying this field will result in an invalid block.
|
||||
|
||||
| Field | Byte range within response | Byte range within header |
|
||||
| --------------- | -------------------------- | ------------------------ |
|
||||
| target | [0-32) | |
|
||||
| header | [32-112) | |
|
||||
| parent block ID | [32-64) | [0-32) |
|
||||
| nonce | [64-72) | [32-40) |
|
||||
| timestamp | [72-80) | [40-48) |
|
||||
| merkle root | [80-112) | [48-80) |
|
||||
|
||||
```
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (returned bytes)
|
||||
tttttttttttttttttttttttttttttttt (target)
|
||||
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh (header)
|
||||
pppppppppppppppppppppppppppppppp (parent block ID)
|
||||
nnnnnnnn (nonce)
|
||||
ssssssss (timestamp)
|
||||
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm (merkle root)
|
||||
```
|
||||
|
||||
#### /miner/header [POST]
|
||||
|
||||
submits a header that has passed the POW.
|
||||
|
||||
###### Request Body Bytes
|
||||
|
||||
For efficiency headers are submitted as raw byte encodings of the header in the
|
||||
body of the request, rather than as a query string parameter or path parameter.
|
||||
The request body should contain only the 80 bytes of the encoded header. The
|
||||
encoding is the same encoding used in `/miner/header [GET]` endpoint. Refer to
|
||||
[#byte-response](#byte-response) for a detailed description of the byte
|
||||
encoding.
|
327
3rd_party/Sia-v1.1.1-windows-amd64/doc/api/Renter.md
vendored
Normal file
327
3rd_party/Sia-v1.1.1-windows-amd64/doc/api/Renter.md
vendored
Normal file
@@ -0,0 +1,327 @@
|
||||
Renter API
|
||||
==========
|
||||
|
||||
This document contains detailed descriptions of the renter's API routes. For an
|
||||
overview of the renter's API routes, see [API.md#renter](/doc/API.md#renter). For
|
||||
an overview of all API routes, see [API.md](/doc/API.md)
|
||||
|
||||
There may be functional API calls which are not documented. These are not
|
||||
guaranteed to be supported beyond the current release, and should not be used
|
||||
in production.
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
The renter manages the user's files on the network. The renter's API endpoints
|
||||
expose methods for managing files on the network and managing the renter's
|
||||
allocated funds.
|
||||
|
||||
Index
|
||||
-----
|
||||
|
||||
| Route | HTTP verb |
|
||||
| ------------------------------------------------------------- | --------- |
|
||||
| [/renter](#renter-get) | GET |
|
||||
| [/renter](#renter-post) | POST |
|
||||
| [/renter/contracts](#rentercontracts-get) | GET |
|
||||
| [/renter/downloads](#renterdownloads-get) | GET |
|
||||
| [/renter/files](#renterfiles-get) | GET |
|
||||
| [/renter/prices](#renter-prices-get) | GET |
|
||||
| [/renter/delete/___*siapath___](#renterdeletesiapath-post) | POST |
|
||||
| [/renter/download/___*siapath___](#renterdownloadsiapath-get) | GET |
|
||||
| [/renter/rename/___*siapath___](#renterrenamesiapath-post) | POST |
|
||||
| [/renter/upload/___*siapath___](#renteruploadsiapath-post) | POST |
|
||||
|
||||
#### /renter [GET]
|
||||
|
||||
returns the current settings along with metrics on the renter's spending.
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
// Settings that control the behavior of the renter.
|
||||
"settings": {
|
||||
// Allowance dictates how much the renter is allowed to spend in a given
|
||||
// period. Note that funds are spent on both storage and bandwidth.
|
||||
"allowance": {
|
||||
// Amount of money allocated for contracts. Funds are spent on both
|
||||
// storage and bandwidth.
|
||||
"funds": "1234", // hastings
|
||||
|
||||
// Number of hosts that contracts will be formed with.
|
||||
"hosts":24,
|
||||
|
||||
// Duration of contracts formed, in number of blocks.
|
||||
"period": 6048, // blocks
|
||||
|
||||
// If the current blockheight + the renew window >= the height the
|
||||
// contract is scheduled to end, the contract is renewed automatically.
|
||||
// Is always nonzero.
|
||||
"renewwindow": 3024 // blocks
|
||||
}
|
||||
},
|
||||
|
||||
// Metrics about how much the Renter has spent on storage, uploads, and
|
||||
// downloads.
|
||||
"financialmetrics": {
|
||||
// How much money, in hastings, the Renter has spent on file contracts,
|
||||
// including fees.
|
||||
"contractspending": "1234", // hastings
|
||||
|
||||
// Amount of money spent on downloads.
|
||||
"downloadspending": "5678", // hastings
|
||||
|
||||
// Amount of money spend on storage.
|
||||
"storagespending": "1234", // hastings
|
||||
|
||||
// Amount of money spent on uploads.
|
||||
"uploadspending": "5678", // hastings
|
||||
|
||||
// Amount of money in the allowance that has not been spent.
|
||||
"unspent": "1234" // hastings
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### /renter [POST]
|
||||
|
||||
modify settings that control the renter's behavior.
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// Number of hastings allocated for file contracts in the given period.
|
||||
funds // hastings
|
||||
|
||||
// Number of hosts that contracts should be formed with. Files cannot be
|
||||
// uploaded to more hosts than you have contracts with, and it's generally good
|
||||
// to form a few more contracts than you need.
|
||||
hosts
|
||||
|
||||
// Duration of contracts formed. Must be nonzero.
|
||||
period // block height
|
||||
|
||||
// Renew window specifies how many blocks before the expriation of the current
|
||||
// contracts the renter will wait before renewing the contracts. A smaller
|
||||
// renew window means that Sia must be run more frequently, but also means
|
||||
// fewer total transaction fees. Storage spending is not affected by the renew
|
||||
// window size.
|
||||
renewwindow // block height
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[API.md#standard-responses](/doc/API.md#standard-responses).
|
||||
|
||||
#### /renter/contracts [GET]
|
||||
|
||||
returns active contracts. Expired contracts are not included.
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
"contracts": [
|
||||
{
|
||||
// Block height that the file contract ends on.
|
||||
"endheight": 50000, // block height
|
||||
|
||||
// ID of the file contract.
|
||||
"id": "1234567890abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||
|
||||
// Address of the host the file contract was formed with.
|
||||
"netaddress": "12.34.56.78:9",
|
||||
|
||||
// A signed transaction containing the most recent contract revision.
|
||||
"lasttransaction": {},
|
||||
|
||||
// Remaining funds left for the renter to spend on uploads & downloads.
|
||||
"renterfunds": "1234", // hastings
|
||||
|
||||
// Size of the file contract, which is typically equal to the number of
|
||||
// bytes that have been uploaded to the host.
|
||||
"size": 8192 // bytes
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### /renter/downloads [GET]
|
||||
|
||||
lists all files in the download queue.
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
"downloads": [
|
||||
{
|
||||
// Siapath given to the file when it was uploaded.
|
||||
"siapath": "foo/bar.txt",
|
||||
|
||||
// Local path that the file will be downloaded to.
|
||||
"destination": "/home/users/alice",
|
||||
|
||||
// Size, in bytes, of the file being downloaded.
|
||||
"filesize": 8192, // bytes
|
||||
|
||||
// Number of bytes downloaded thus far.
|
||||
"received": 4096, // bytes
|
||||
|
||||
// Time at which the download was initiated.
|
||||
"starttime": "2009-11-10T23:00:00Z" // RFC 3339 time
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### /renter/files [GET]
|
||||
|
||||
lists the status of all files.
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
"files": [
|
||||
{
|
||||
// Path to the file in the renter on the network.
|
||||
"siapath": "foo/bar.txt",
|
||||
|
||||
// Size of the file in bytes.
|
||||
"filesize": 8192, // bytes
|
||||
|
||||
// true if the file is available for download. Files may be available
|
||||
// before they are completely uploaded.
|
||||
"available": true,
|
||||
|
||||
// true if the file's contracts will be automatically renewed by the
|
||||
// renter.
|
||||
"renewing": true,
|
||||
|
||||
// Average redundancy of the file on the network. Redundancy is
|
||||
// calculated by dividing the amount of data uploaded in the file's open
|
||||
// contracts by the size of the file. Redundancy does not necessarily
|
||||
// correspond to availability. Specifically, a redundancy >= 1 does not
|
||||
// indicate the file is available as there could be a chunk of the file
|
||||
// with 0 redundancy.
|
||||
"redundancy": 5,
|
||||
|
||||
// Percentage of the file uploaded, including redundancy. Uploading has
|
||||
// completed when uploadprogress is 100. Files may be available for
|
||||
// download before upload progress is 100.
|
||||
"uploadprogress": 100, // percent
|
||||
|
||||
// Block height at which the file ceases availability.
|
||||
"expiration": 60000
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### /renter/prices [GET]
|
||||
|
||||
lists the estimated prices of performing various storage and data operations.
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
// The estimated cost of downloading one terabyte of data from the
|
||||
// network.
|
||||
"downloadterabyte": "1234", // hastings
|
||||
|
||||
// The estimated cost of forming a set of contracts on the network. This
|
||||
// cost also applies to the estimated cost of renewing the renter's set of
|
||||
// contracts.
|
||||
"formcontracts": "1234", // hastings
|
||||
|
||||
// The estimated cost of storing one terabyte of data on the network for
|
||||
// a month, including accounting for redundancy.
|
||||
"storageterabytemonth": "1234", // hastings
|
||||
|
||||
// The estimated cost of uploading one terabyte of data to the network,
|
||||
// including accounting for redundancy.
|
||||
"uploadterabyte": "1234", // hastings
|
||||
}
|
||||
```
|
||||
|
||||
#### /renter/delete/___*siapath___ [POST]
|
||||
|
||||
deletes a renter file entry. Does not delete any downloads or original files,
|
||||
only the entry in the renter.
|
||||
|
||||
###### Path Parameters
|
||||
```
|
||||
// Location of the file in the renter on the network.
|
||||
*siapath
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[API.md#standard-responses](/doc/API.md#standard-responses).
|
||||
|
||||
#### /renter/download/___*siapath___ [GET]
|
||||
|
||||
downloads a file to the local filesystem. The call will block until the file
|
||||
has been downloaded.
|
||||
|
||||
###### Path Parameters
|
||||
```
|
||||
// Location of the file in the renter on the network.
|
||||
*siapath
|
||||
```
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// Location on disk that the file will be downloaded to.
|
||||
destination
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[API.md#standard-responses](/doc/API.md#standard-responses).
|
||||
|
||||
#### /renter/rename/___*siapath___ [POST]
|
||||
|
||||
renames a file. Does not rename any downloads or source files, only renames the
|
||||
entry in the renter. An error is returned if `siapath` does not exist or
|
||||
`newsiapath` already exists.
|
||||
|
||||
###### Path Parameters
|
||||
```
|
||||
// Current location of the file in the renter on the network.
|
||||
*siapath
|
||||
```
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// New location of the file in the renter on the network.
|
||||
newsiapath
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[API.md#standard-responses](/doc/API.md#standard-responses).
|
||||
|
||||
#### /renter/upload/___*siapath___ [POST]
|
||||
|
||||
uploads a file to the network from the local filesystem.
|
||||
|
||||
###### Path Parameters
|
||||
```
|
||||
// Location where the file will reside in the renter on the network.
|
||||
*siapath
|
||||
```
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// The number of data pieces to use when erasure coding the file.
|
||||
datapieces // int
|
||||
|
||||
// The number of parity pieces to use when erasure coding the file. Total
|
||||
// redundancy of the file is (datapieces+paritypieces)/datapieces.
|
||||
paritypieces // int
|
||||
|
||||
// Location on disk of the file being uploaded.
|
||||
source // string - a filepath
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[API.md#standard-responses](/doc/API.md#standard-responses).
|
521
3rd_party/Sia-v1.1.1-windows-amd64/doc/api/Wallet.md
vendored
Normal file
521
3rd_party/Sia-v1.1.1-windows-amd64/doc/api/Wallet.md
vendored
Normal file
@@ -0,0 +1,521 @@
|
||||
Wallet
|
||||
======
|
||||
|
||||
This document contains detailed descriptions of the wallet's API routes. For an
|
||||
overview of the wallet's API routes, see [API.md#wallet](/doc/API.md#wallet).
|
||||
For an overview of all API routes, see [API.md](/doc/API.md)
|
||||
|
||||
There may be functional API calls which are not documented. These are not
|
||||
guaranteed to be supported beyond the current release, and should not be used
|
||||
in production.
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
The wallet stores and manages siacoins and siafunds. The wallet's API endpoints
|
||||
expose methods for creating and loading wallets, locking and unlocking, sending
|
||||
siacoins and siafunds, and getting the wallet's balance.
|
||||
|
||||
You must create a wallet before you can use the wallet's API endpoints. You can
|
||||
create a wallet with the `/wallet/init` endpoint. Wallets are always encrypted
|
||||
on disk. Calls to some wallet API endpoints will fail until the wallet is
|
||||
unlocked. The wallet can be unlocked with the `/wallet/unlock` endpoint. Once
|
||||
the wallet is unlocked calls to the API endpoints will succeed until the wallet
|
||||
is locked again with `/wallet/lock`, or Siad is restarted. The host and renter
|
||||
require the miner to be unlocked.
|
||||
|
||||
Index
|
||||
-----
|
||||
|
||||
| Route | HTTP verb |
|
||||
| --------------------------------------------------------------- | --------- |
|
||||
| [/wallet](#wallet-get) | GET |
|
||||
| [/wallet/033x](#wallet033x-post) | POST |
|
||||
| [/wallet/address](#walletaddress-get) | GET |
|
||||
| [/wallet/addresses](#walletaddresses-get) | GET |
|
||||
| [/wallet/backup](#walletbackup-get) | GET |
|
||||
| [/wallet/init](#walletinit-post) | POST |
|
||||
| [/wallet/lock](#walletlock-post) | POST |
|
||||
| [/wallet/seed](#walletseed-post) | POST |
|
||||
| [/wallet/seeds](#walletseeds-get) | GET |
|
||||
| [/wallet/siacoins](#walletsiacoins-post) | POST |
|
||||
| [/wallet/siafunds](#walletsiafunds-post) | POST |
|
||||
| [/wallet/siagkey](#walletsiagkey-post) | POST |
|
||||
| [/wallet/transaction/___:id___](#wallettransactionid-get) | GET |
|
||||
| [/wallet/transactions](#wallettransactions-get) | GET |
|
||||
| [/wallet/transactions/___:addr___](#wallettransactionsaddr-get) | GET |
|
||||
| [/wallet/unlock](#walletunlock-post) | POST |
|
||||
|
||||
#### /wallet [GET]
|
||||
|
||||
returns basic information about the wallet, such as whether the wallet is
|
||||
locked or unlocked.
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
// Indicates whether the wallet has been encrypted or not. If the wallet
|
||||
// has not been encrypted, then no data has been generated at all, and the
|
||||
// first time the wallet is unlocked, the password given will be used as
|
||||
// the password for encrypting all of the data. 'encrypted' will only be
|
||||
// set to false if the wallet has never been unlocked before (the unlocked
|
||||
// wallet is still encryped - but the encryption key is in memory).
|
||||
"encrypted": true,
|
||||
|
||||
// Indicates whether the wallet is currently locked or unlocked. Some calls
|
||||
// become unavailable when the wallet is locked.
|
||||
"unlocked": true,
|
||||
|
||||
// Number of siacoins, in hastings, available to the wallet as of the most
|
||||
// recent block in the blockchain.
|
||||
"confirmedsiacoinbalance": "123456", // hastings, big int
|
||||
|
||||
// Number of siacoins, in hastings, that are leaving the wallet according
|
||||
// to the set of unconfirmed transactions. Often this number appears
|
||||
// inflated, because outputs are frequently larger than the number of coins
|
||||
// being sent, and there is a refund. These coins are counted as outgoing,
|
||||
// and the refund is counted as incoming. The difference in balance can be
|
||||
// calculated using 'unconfirmedincomingsiacoins' - 'unconfirmedoutgoingsiacoins'
|
||||
"unconfirmedoutgoingsiacoins": "0", // hastings, big int
|
||||
|
||||
// Number of siacoins, in hastings, are entering the wallet according to
|
||||
// the set of unconfirmed transactions. This number is often inflated by
|
||||
// outgoing siacoins, because outputs are frequently larger than the amount
|
||||
// being sent. The refund will be included in the unconfirmed incoming
|
||||
// siacoins balance.
|
||||
"unconfirmedincomingsiacoins": "789", // hastings, big int
|
||||
|
||||
// Number of siafunds available to the wallet as of the most recent block
|
||||
// in the blockchain.
|
||||
"siafundbalance": "1", // big int
|
||||
|
||||
// Number of siacoins, in hastings, that can be claimed from the siafunds
|
||||
// as of the most recent block. Because the claim balance increases every
|
||||
// time a file contract is created, it is possible that the balance will
|
||||
// increase before any claim transaction is confirmed.
|
||||
"siacoinclaimbalance": "9001", // hastings, big int
|
||||
}
|
||||
```
|
||||
|
||||
#### /wallet/033x [POST]
|
||||
|
||||
loads a v0.3.3.x wallet into the current wallet, harvesting all of the secret
|
||||
keys. All spendable addresses in the loaded wallet will become spendable from
|
||||
the current wallet. An error will be returned if the given `encryptionpassword`
|
||||
is incorrect.
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// Path on disk to the v0.3.3.x wallet to be loaded.
|
||||
source
|
||||
|
||||
// Encryption key of the wallet.
|
||||
encryptionpassword
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[API.md#standard-responses](/doc/API.md#standard-responses).
|
||||
|
||||
#### /wallet/address [GET]
|
||||
|
||||
gets a new address from the wallet generated by the primary seed. An error will
|
||||
be returned if the wallet is locked.
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
// Wallet address that can receive siacoins or siafunds. Addresses are 76 character long hex strings.
|
||||
"address": "1234567890abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789ab"
|
||||
}
|
||||
```
|
||||
|
||||
#### /wallet/addresses [GET]
|
||||
|
||||
fetches the list of addresses from the wallet.
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
// Array of wallet addresses owned by the wallet.
|
||||
"addresses": [
|
||||
"1234567890abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789ab",
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### /wallet/backup [GET]
|
||||
|
||||
creates a backup of the wallet settings file. Though this can easily be done
|
||||
manually, the settings file is often in an unknown or difficult to find
|
||||
location. The /wallet/backup call can spare users the trouble of needing to
|
||||
find their wallet file. The destination file is overwritten if it already
|
||||
exists.
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// path to the location on disk where the backup file will be saved.
|
||||
destination
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[API.md#standard-responses](/doc/API.md#standard-responses).
|
||||
|
||||
#### /wallet/init [POST]
|
||||
|
||||
initializes the wallet. After the wallet has been initialized once, it does not
|
||||
need to be initialized again, and future calls to /wallet/init will return an
|
||||
error. The encryption password is provided by the api call. If the password is
|
||||
blank, then the password will be set to the same as the seed.
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// Password that will be used to encrypt the wallet. All subsequent calls
|
||||
// should use this password. If left blank, the seed that gets returned will
|
||||
// also be the encryption password.
|
||||
encryptionpassword
|
||||
|
||||
// Name of the dictionary that should be used when encoding the seed. 'english'
|
||||
// is the most common choice when picking a dictionary.
|
||||
dictionary // Optional, default is english.
|
||||
```
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
// Wallet seed used to generate addresses that the wallet is able to spend.
|
||||
"primaryseed": "hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello"
|
||||
}
|
||||
```
|
||||
|
||||
#### /wallet/seed [POST]
|
||||
|
||||
gives the wallet a seed to track when looking for incoming transactions. The
|
||||
wallet will be able to spend outputs related to addresses created by the seed.
|
||||
The seed is added as an auxiliary seed, and does not replace the primary seed.
|
||||
Only the primary seed will be used for generating new addresses.
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// Key used to encrypt the new seed when it is saved to disk.
|
||||
encryptionpassword
|
||||
|
||||
// Name of the dictionary that should be used when encoding the seed. 'english'
|
||||
// is the most common choice when picking a dictionary.
|
||||
dictionary
|
||||
|
||||
// Dictionary-encoded phrase that corresponds to the seed being added to the
|
||||
// wallet.
|
||||
seed
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[API.md#standard-responses](/doc/API.md#standard-responses).
|
||||
|
||||
#### /wallet/seeds [GET]
|
||||
|
||||
returns a list of seeds in use by the wallet. The primary seed is the only seed
|
||||
that gets used to generate new addresses. This call is unavailable when the
|
||||
wallet is locked.
|
||||
|
||||
A seed is an encoded version of a 128 bit random seed. The output is 15 words
|
||||
chosen from a small dictionary as indicated by the input. The most common
|
||||
choice for the dictionary is going to be 'english'. The underlying seed is the
|
||||
same no matter what dictionary is used for the encoding. The encoding also
|
||||
contains a small checksum of the seed, to help catch simple mistakes when
|
||||
copying. The library
|
||||
[entropy-mnemonics](https://github.com/NebulousLabs/entropy-mnemonics) is used
|
||||
when encoding.
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// Name of the dictionary that should be used when encoding the seed. 'english'
|
||||
// is the most common choice when picking a dictionary.
|
||||
dictionary
|
||||
```
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
// Seed that is actively being used to generate new addresses for the wallet.
|
||||
"primaryseed": "hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello",
|
||||
|
||||
// Number of addresses that remain in the primary seed until exhaustion has
|
||||
// been reached. Once exhaustion has been reached, new addresses will
|
||||
// continue to be generated but they will be more difficult to recover in the
|
||||
// event of a lost wallet file or encryption password.
|
||||
"addressesremaining": 2500,
|
||||
|
||||
// Array of all seeds that the wallet references when scanning the blockchain
|
||||
// for outputs. The wallet is able to spend any output generated by any of
|
||||
// the seeds, however only the primary seed is being used to generate new
|
||||
// addresses.
|
||||
"allseeds": [
|
||||
"hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello",
|
||||
"foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo",
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### /wallet/siacoins [POST]
|
||||
|
||||
Function: Send siacoins to an address. The outputs are arbitrarily selected
|
||||
from addresses in the wallet.
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// Number of hastings being sent. A hasting is the smallest unit in Sia. There
|
||||
// are 10^24 hastings in a siacoin.
|
||||
amount // hastings
|
||||
|
||||
// Address that is receiving the coins.
|
||||
destination // address
|
||||
```
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
// Array of IDs of the transactions that were created when sending the coins.
|
||||
// The last transaction contains the output headed to the 'destination'.
|
||||
// Transaction IDs are 64 character long hex strings.
|
||||
transactionids [
|
||||
"1234567890abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### /wallet/siafunds [POST]
|
||||
|
||||
sends siafunds to an address. The outputs are arbitrarily selected from
|
||||
addresses in the wallet. Any siacoins available in the siafunds being sent (as
|
||||
well as the siacoins available in any siafunds that end up in a refund address)
|
||||
will become available to the wallet as siacoins after 144 confirmations. To
|
||||
access all of the siacoins in the siacoin claim balance, send all of the
|
||||
siafunds to an address in your control (this will give you all the siacoins,
|
||||
while still letting you control the siafunds).
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// Number of siafunds being sent.
|
||||
amount // siafunds
|
||||
|
||||
// Address that is receiving the funds.
|
||||
destination // address
|
||||
```
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
// Array of IDs of the transactions that were created when sending the coins.
|
||||
// The last transaction contains the output headed to the 'destination'.
|
||||
// Transaction IDs are 64 character long hex strings.
|
||||
"transactionids": [
|
||||
"1234567890abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### /wallet/siagkey [POST]
|
||||
|
||||
Function: Load a key into the wallet that was generated by siag. Most siafunds
|
||||
are currently in addresses created by siag.
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// Key that is used to encrypt the siag key when it is imported to the wallet.
|
||||
encryptionpassword
|
||||
|
||||
// List of filepaths that point to the keyfiles that make up the siag key.
|
||||
// There should be at least one keyfile per required signature. The filenames
|
||||
// need to be commna separated (no spaces), which means filepaths that contain
|
||||
// a comma are not allowed.
|
||||
keyfiles
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[API.md#standard-responses](/doc/API.md#standard-responses).
|
||||
|
||||
#### /wallet/lock [POST]
|
||||
|
||||
locks the wallet, wiping all secret keys. After being locked, the keys are
|
||||
encrypted. Queries for the seed, to send siafunds, and related queries become
|
||||
unavailable. Queries concerning transaction history and balance are still
|
||||
available.
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[API.md#standard-responses](/doc/API.md#standard-responses).
|
||||
|
||||
#### /wallet/transaction/___:id___ [GET]
|
||||
|
||||
gets the transaction associated with a specific transaction id.
|
||||
|
||||
###### Path Parameters
|
||||
```
|
||||
// ID of the transaction being requested.
|
||||
:id
|
||||
```
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
"transaction": {
|
||||
// Raw transaction. The rest of the fields in the resposne are determined
|
||||
// from this raw transaction. It is left undocumented here as the processed
|
||||
// transaction (the rest of the fields in this object) are usually what is
|
||||
// desired.
|
||||
"transaction": {
|
||||
// See types.Transaction in https://github.com/NebulousLabs/Sia/blob/master/types/transactions.go
|
||||
},
|
||||
|
||||
// ID of the transaction from which the wallet transaction was derived.
|
||||
"transactionid": "1234567890abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||
|
||||
// Block height at which the transaction was confirmed. If the transaction
|
||||
// is unconfirmed the height will be the max value of an unsigned 64-bit
|
||||
// integer.
|
||||
"confirmationheight": 50000,
|
||||
|
||||
// Time, in unix time, at which a transaction was confirmed. If the
|
||||
// transaction is unconfirmed the timestamp will be the max value of an
|
||||
// unsigned 64-bit integer.
|
||||
"confirmationtimestamp": 1257894000,
|
||||
|
||||
// Array of processed inputs detailing the inputs to the transaction.
|
||||
"inputs": [
|
||||
{
|
||||
// Type of fund represented by the input. Possible values are
|
||||
// 'siacoin input' and 'siafund input'.
|
||||
"fundtype": "siacoin input",
|
||||
|
||||
// true if the address is owned by the wallet.
|
||||
"walletaddress": false,
|
||||
|
||||
// Address that is affected. For inputs (outgoing money), the related
|
||||
// address is usually not important because the wallet arbitrarily
|
||||
// selects which addresses will fund a transaction.
|
||||
"relatedaddress": "1234567890abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789ab",
|
||||
|
||||
// Amount of funds that have been moved in the input.
|
||||
"value": "1234", // hastings or siafunds, depending on fundtype, big int
|
||||
}
|
||||
],
|
||||
// Array of processed outputs detailing the outputs of the transaction.
|
||||
// Outputs related to file contracts are excluded.
|
||||
"outputs": [
|
||||
{
|
||||
// Type of fund is represented by the output. Possible values are
|
||||
// 'siacoin output', 'siafund output', 'claim output', and 'miner
|
||||
// payout'. Siacoin outputs and claim outputs both relate to siacoins.
|
||||
// Siafund outputs relate to siafunds. Miner payouts point to siacoins
|
||||
// that have been spent on a miner payout. Because the destination of
|
||||
// the miner payout is determined by the block and not the transaction,
|
||||
// the data 'maturityheight', 'walletaddress', and 'relatedaddress' are
|
||||
// left blank.
|
||||
"fundtype": "siacoin output",
|
||||
|
||||
// Block height the output becomes available to be spent. Siacoin
|
||||
// outputs and siafund outputs mature immediately - their maturity
|
||||
// height will always be the confirmation height of the transaction.
|
||||
// Claim outputs cannot be spent until they have had 144 confirmations,
|
||||
// thus the maturity height of a claim output will always be 144 larger
|
||||
// than the confirmation height of the transaction.
|
||||
"maturityheight": 50000,
|
||||
|
||||
// true if the address is owned by the wallet.
|
||||
"walletaddress": false,
|
||||
|
||||
// Address that is affected. For outputs (incoming money), the related
|
||||
// address field can be used to determine who has sent money to the
|
||||
// wallet.
|
||||
"relatedaddress": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
|
||||
// Amount of funds that have been moved in the output.
|
||||
"value": "1234", // hastings or siafunds, depending on fundtype, big int
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### /wallet/transactions [GET]
|
||||
|
||||
returns a list of transactions related to the wallet.
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// Height of the block where transaction history should begin.
|
||||
startheight // block height
|
||||
|
||||
// Height of of the block where the transaction history should end. If
|
||||
// 'endheight' is greater than the current height, all transactions up to and
|
||||
// including the most recent block will be provided.
|
||||
endheight // block height
|
||||
```
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
// All of the confirmed transactions appearing between height 'startheight'
|
||||
// and height 'endheight' (inclusive).
|
||||
"confirmedtransactions": [
|
||||
{
|
||||
// See the documentation for '/wallet/transaction/:id' for more information.
|
||||
}
|
||||
],
|
||||
|
||||
// All of the unconfirmed transactions.
|
||||
"unconfirmedtransactions": [
|
||||
{
|
||||
// See the documentation for '/wallet/transaction/:id' for more information.
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### /wallet/transactions/___:addr___ [GET]
|
||||
|
||||
returns all of the transactions related to a specific address.
|
||||
|
||||
###### Path Parameters
|
||||
```
|
||||
// Unlock hash (i.e. wallet address) whose transactions are being requested.
|
||||
:addr
|
||||
```
|
||||
|
||||
###### JSON Response
|
||||
```javascript
|
||||
{
|
||||
// Array of processed transactions that relate to the supplied address.
|
||||
"transactions": [
|
||||
{
|
||||
// See the documentation for '/wallet/transaction/:id' for more information.
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### /wallet/unlock [POST]
|
||||
|
||||
unlocks the wallet. The wallet is capable of knowing whether the correct
|
||||
password was provided.
|
||||
|
||||
###### Query String Parameters
|
||||
```
|
||||
// Password that gets used to decrypt the file. Most frequently, the encryption
|
||||
// password is the same as the primary wallet seed.
|
||||
encryptionpassword string
|
||||
```
|
||||
|
||||
###### Response
|
||||
standard success or error response. See
|
||||
[API.md#standard-responses](/doc/API.md#standard-responses).
|
BIN
3rd_party/Sia-v1.1.1-windows-amd64/doc/assets/codereview.png
vendored
Normal file
BIN
3rd_party/Sia-v1.1.1-windows-amd64/doc/assets/codereview.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
BIN
3rd_party/Sia-v1.1.1-windows-amd64/doc/assets/covertool.png
vendored
Normal file
BIN
3rd_party/Sia-v1.1.1-windows-amd64/doc/assets/covertool.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 86 KiB |
482
3rd_party/Sia-v1.1.1-windows-amd64/doc/whitepaper.tex
vendored
Normal file
482
3rd_party/Sia-v1.1.1-windows-amd64/doc/whitepaper.tex
vendored
Normal file
@@ -0,0 +1,482 @@
|
||||
\documentclass[twocolumn]{article}
|
||||
\usepackage{amsmath}
|
||||
|
||||
\begin{document}
|
||||
\frenchspacing
|
||||
|
||||
\title{Sia: Simple Decentralized Storage}
|
||||
|
||||
\author{
|
||||
{\rm David Vorick}\\
|
||||
Nebulous Inc.\\
|
||||
david@nebulouslabs.com
|
||||
\and
|
||||
{\rm Luke Champine}\\
|
||||
Nebulous Inc.\\
|
||||
luke@nebulouslabs.com
|
||||
}
|
||||
|
||||
\maketitle
|
||||
|
||||
\subsection*{Abstract}
|
||||
The authors introduce Sia, a platform for decentralized storage.
|
||||
Sia enables the formation of storage contracts between peers.
|
||||
Contracts are agreements between a storage provider and their client, defining what data will be stored and at what price.
|
||||
They require the storage provider to prove, at regular intervals, that they are still storing their client's data.
|
||||
|
||||
Contracts are stored in a blockchain, making them publicly auditable.
|
||||
In this respect, Sia can be viewed as a Bitcoin derivative that includes support for such contracts.
|
||||
Sia will initially be implemented as an altcoin, and later financially connected to Bitcoin via a two-way peg.
|
||||
|
||||
\section{Introduction}
|
||||
Sia is a decentralized cloud storage platform that intends to compete with existing storage solutions, at both the P2P and enterprise level.
|
||||
Instead of renting storage from a centralized provider, peers on Sia rent storage from each other.
|
||||
Sia itself stores only the storage contracts formed between parties, defining the terms of their arrangement.
|
||||
A blockchain, similar to Bitcoin \cite{btc, btcdg}, is used for this purpose.
|
||||
|
||||
By forming a contract, a storage provider (also known as a \textit{host}) agrees to store a client's data, and to periodically submit proof of their continued storage until the contract expires.
|
||||
The host is compensated for every proof they submit, and penalized for missing a proof.
|
||||
Since these proofs are publicly verifiable (and are publicly available in the blockchain), network consensus can be used to automatically enforce storage contracts.
|
||||
Importantly, this means that clients do not need to personally verify storage proofs; they can simply upload their file and let the network do the rest.
|
||||
|
||||
We acknowledge that storing data on a single untrusted host guarantees little in the way of availability, bandwidth, or general quality of service.
|
||||
Instead, we recommend storing data redundantly across multiple hosts.
|
||||
In particular, the use of erasure codes can enable high availability without excessive redundancy.
|
||||
|
||||
Sia will initially be implemented as a blockchain-based altcoin.
|
||||
Future support for a two-way peg with Bitcoin is planned, as discussed in ``Enabling Blockchain Innovations with Pegged Sidechains'' \cite{side}.
|
||||
The Sia protocol largely resembles Bitcoin except for the changes noted below.
|
||||
|
||||
\section{General Structure}
|
||||
Sia's primary departure from Bitcoin lies in its transactions.
|
||||
Bitcoin uses a scripting system to enable a range of transaction types, such as pay-to-public-key-hash and pay-to-script-hash.
|
||||
Sia opts instead to use an $M$--of--$N$ multi-signature scheme for all transactions, eschewing the scripting system entirely.
|
||||
This reduces complexity and attack surface.
|
||||
|
||||
Sia also extends transactions to enable the creation and enforcement of storage contracts.
|
||||
Three extensions are used to accomplish this: contracts, proofs, and contract updates.
|
||||
Contracts declare the intention of a host to store a file with a certain size and hash.
|
||||
They define the regularity with which a host must submit storage proofs.
|
||||
Once established, contracts can be modified later via contract updates.
|
||||
The specifics of these transaction types are defined in sections \ref{sec:contracts} and \ref{sec:storage}.
|
||||
|
||||
\section{Transactions}
|
||||
A transaction contains the following fields: \\
|
||||
|
||||
\noindent
|
||||
\begin{tabular}{ l | l }
|
||||
\textbf{Field} & \textbf{Description} \\ \hline
|
||||
Version & Protocol version number \\
|
||||
Arbitrary Data & Used for metadata or otherwise \\
|
||||
Miner Fee & Reward given to miner \\
|
||||
Inputs & Incoming funds \\
|
||||
Outputs & Outgoing funds (optional) \\
|
||||
File Contract & See: File Contracts (optional) \\
|
||||
Storage Proof & See: Proof of Storage (optional) \\
|
||||
Signatures & Signatures from each input \\
|
||||
\end{tabular}
|
||||
|
||||
\subsection{Inputs and Outputs}
|
||||
An output comprises a volume of coins.
|
||||
Each output has an associated identifier, which is derived from the transaction that the output appeared in.
|
||||
The ID of output $i$ in transaction $t$ is defined as:
|
||||
\[
|
||||
H(t || \text{``output''} || i)
|
||||
\]
|
||||
where $H$ is a cryptographic hashing function, and ``output'' is a string literal.
|
||||
The block reward and miner fees have special output IDs, given by:
|
||||
\[
|
||||
H(H(\text{Block Header}) || \text{``blockreward''})
|
||||
\]
|
||||
Every input must come from a prior output, so an input is simply an output ID.
|
||||
|
||||
Inputs and outputs are also paired with a set of \textit{spend conditions}.
|
||||
Inputs contain the spend conditions themselves, while outputs contain their Merkle root hash \cite{merkle}.
|
||||
|
||||
\subsection{Spend Conditions}
|
||||
Spend conditions are properties that must be met before coins are ``unlocked'' and can be spent.
|
||||
The spend conditions include a time lock and a set of public keys, and the number of signatures required.
|
||||
An output cannot be spent until the time lock has expired and enough of the specified keys have added their signature.
|
||||
|
||||
The spend conditions are hashed into a Merkle tree, using the time lock, the number of signatures required, and the public keys as leaves.
|
||||
The root hash of this tree is used as the address to which the coins are sent.
|
||||
In order to spend the coins, the spend conditions corresponding to the address hash must be provided.
|
||||
The use of a Merkle tree allows parties to selectively reveal information in the spend conditions.
|
||||
For example, the time lock can be revealed without revealing the number of public keys or the number of signatures required.
|
||||
|
||||
It should be noted that the time lock and number of signatures have low entropy, making their hashes vulnerable to brute-forcing.
|
||||
This could be resolved by adding a random nonce to these fields, increasing their entropy at the cost of space efficiency.
|
||||
|
||||
\subsection{Signatures}
|
||||
Each input in a transaction must be signed.
|
||||
The cryptographic signature itself is paired with an input ID, a time lock, and a set of flags indicating which parts of the transaction have been signed.
|
||||
The input ID indicates which input the signature is being applied to.
|
||||
The time lock specifies when the signature becomes valid.
|
||||
Any subset of fields in the transaction can be signed, with the exception of the signature itself (as this would be impossible).
|
||||
There is also a flag to indicate that the whole transaction should be signed, except for the signatures.
|
||||
This allows for more nuanced transaction schemes.
|
||||
|
||||
The actual data being signed, then, is a concatenation of the time lock, input ID, flags, and every flagged field.
|
||||
Every such signature in the transaction must be valid for the transaction to be accepted.
|
||||
|
||||
\section{File Contracts}
|
||||
\label{sec:contracts}
|
||||
A file contract is an agreement between a storage provider and their client.
|
||||
At the core of a file contract is the file's Merkle root hash.
|
||||
To construct this hash, the file is split into segments of constant size and hashed into a Merkle tree.
|
||||
The root hash, along with the total size of the file, can be used to verify storage proofs.
|
||||
|
||||
File contracts also specify a duration, challenge frequency, and payout parameters, including the reward for a valid proof, the reward for an invalid or missing proof, and the maximum number of proofs that can be missed.
|
||||
The challenge frequency specifies how often a storage proof must be submitted, and creates discrete \textit{challenge windows} during which a host must submit storage proofs (one proof per window).
|
||||
Submitting a valid proof during the challenge window triggers an automatic payment to the ``valid proof'' address (presumably the host).
|
||||
If, at the end of the challenge window, no valid proof has been submitted, coins are instead sent to the ``missed proof'' address
|
||||
(likely an unspendable address in order to disincentivize DoS attacks; see section \ref{subsec:host-protect}).
|
||||
Contracts define a maximum number of proofs that can be missed; if this number is exceeded, the contract becomes invalid.
|
||||
|
||||
If the contract is still valid at the end of the contract duration, it \textit{successfully terminates} and any remaining coins are sent to the valid proof address.
|
||||
Conversely, if the contract funds are exhausted before the duration elapses, or if the maximum number of missed proofs is exceeded, the contract \textit{unsuccessfully terminates} and any remaining coins are sent to the missed proof address.
|
||||
|
||||
Completing or missing a proof results in a new transaction output belonging to the recipient specified in the contract.
|
||||
The output ID of a proof depends on the contract ID, defined as:
|
||||
\[
|
||||
H(\text{transaction} || \text{``contract''} || i)
|
||||
\]
|
||||
where $i$ is the index of the contract within the transaction.
|
||||
The output ID of the proof can then be determined from:
|
||||
\[
|
||||
H(\text{contract ID} || \text{outcome} || W_i)
|
||||
\]
|
||||
Where $W_i$ is the window index, i.e. the number of windows that have elapsed since the contract was formed.
|
||||
The outcome is a string literal: either ``validproof'' and ``missedproof'', corresponding to the validity of the proof.
|
||||
|
||||
The output ID of a contract termination is defined as:
|
||||
\[
|
||||
H(\text{contract ID} || \text{outcome})
|
||||
\]
|
||||
Where outcome has the potential values ``successfultermination'' and ``unsucessfultermination'', corresponding to the termination status of the contract.
|
||||
|
||||
File contracts are also created with a list of ``edit conditions,'' analogous to the spend conditions of a transaction.
|
||||
If the edit conditions are fulfilled, the contract may be modified.
|
||||
Any of the values can be modified, including the contract funds, file hash, and output addresses.
|
||||
As these modifications can affect the validity of subsequent storage proofs, contract edits must specify a future challenge window at which they will become effective.
|
||||
|
||||
Theoretically, peers could create ``micro-edit channels'' to facilitate frequent edits; see discussion of \mbox{micropayment} channels, section \ref{sec:uptime}.
|
||||
|
||||
\section{Proof of Storage}
|
||||
\label{sec:storage}
|
||||
Storage proof transactions are periodically submitted in order to fulfill file contracts.
|
||||
Each storage proof targets a specific file contract.
|
||||
A storage proof does not need to have any inputs or outputs; only a contract ID and the proof data are required.
|
||||
|
||||
\subsection{Algorithm}
|
||||
Hosts prove their storage by providing a segment of the original file and a list of hashes from the file's Merkle tree.
|
||||
This information is sufficient to prove that the segment came from the original file.
|
||||
Because proofs are submitted to the blockchain, anyone can verify their validity or invalidity.
|
||||
Each storage proof uses a randomly selected segment.
|
||||
The random seed for challenge window $W_i$ is given by:
|
||||
\[
|
||||
H(\text{contract ID} || H(B_{i-1}))
|
||||
\]
|
||||
where $B_{i-1}$ is the block immediately prior to the beginning of $W_i$.
|
||||
|
||||
If the host is consistently able to demonstrate possession of a random segment, then they are very likely storing the whole file.
|
||||
A host storing only 50\% of the file will be unable to complete approximately 50\% of the proofs.
|
||||
|
||||
\subsection{Block Withholding Attacks}
|
||||
The random number generator is subject to manipulation via block withholding attacks, in which the attacker withholds blocks until they find one that will produce a favorable random number.
|
||||
However, the attacker has only one chance to manipulate the random number for a particular challenge.
|
||||
Furthermore, withholding a block to manipulate the random number will cost the attacker the block reward.
|
||||
|
||||
If an attacker is able to mine 50\% of the blocks, then 50\% of the challenges can be manipulated.
|
||||
Nevertheless, the remaining 50\% are still random, so the attacker will still fail some storage proofs.
|
||||
Specifically, they will fail half as many as they would without the withholding attack.
|
||||
|
||||
To protect against such attacks, clients can specify a high challenge frequency and large penalties for missing proofs.
|
||||
These precautions should be sufficient to deter any financially-motivated attacker that controls less than 50\% of the network's hashing power.
|
||||
Regardless, clients are advised to plan around potential Byzantine attacks, which may not be financially motivated.
|
||||
|
||||
\subsection{Closed Window Attacks}
|
||||
Hosts can only complete a storage proof if their proof transaction makes it into the blockchain.
|
||||
Miners could maliciously exclude storage proofs from blocks, depriving themselves of transaction fees but forcing a penalty on hosts.
|
||||
Alternatively, miners could extort hosts by requiring large fees to include storage proofs, knowing that they are more important than the average transaction.
|
||||
This is termed a \textit{closed window attack}, because the malicious miner has artificially ``closed the window.''
|
||||
|
||||
The defense for this is to use a large window size.
|
||||
Hosts can reasonably assume that some percentage of miners will include their proofs in return for a transaction fee.
|
||||
Because hosts consent to all file contracts, they are free to reject any contract that they feel leaves them vulnerable to closed window attacks.
|
||||
|
||||
\section{Arbitrary Transaction Data}
|
||||
Each transaction has an arbitrary data field which can be used for any type of information.
|
||||
Nodes will be required to store the arbitrary data if it is signed by any signature in the transaction.
|
||||
Nodes will initially accept up to 64 KB of arbitrary data per block.
|
||||
|
||||
This arbitrary data provides hosts and clients with a decentralized way to organize themselves.
|
||||
It can be used to advertise available space or files seeking a host, or to create a decentralized file tracker.
|
||||
|
||||
Arbitrary data could also be used to implement other types of soft forks.
|
||||
This would be done by creating an ``anyone-can-spend'' output but with restrictions specified in the arbitrary data.
|
||||
Miners that understand the restrictions can block any transaction that spends the output without satisfying the necessary stipulations.
|
||||
Naive nodes will stay synchronized without needing to be able to parse the arbitrary data.
|
||||
|
||||
\section{Storage Ecosystem}
|
||||
Sia relies on an ecosystem that facilitates decentralized storage.
|
||||
Storage providers can use the arbitrary data field to announce themselves to the network.
|
||||
This can be done using standardized template that clients will be able to read.
|
||||
Clients can use these announcements to create a database of potential hosts, and form contracts with only those they trust.
|
||||
|
||||
\subsection{Host Protections}
|
||||
\label{subsec:host-protect}
|
||||
A contract requires consent from both the storage provider and their client, allowing the provider to reject unfavorable terms or unwanted (e.g. illegal) files.
|
||||
The provider may also refuse to sign a contract until the entire file has been uploaded to them.
|
||||
|
||||
Contract terms give storage providers some flexibility.
|
||||
They can advertise themselves as minimally reliable, offering a low price and a agreeing to minimal penalties for losing files;
|
||||
or they can advertise themselves as highly reliable, offering a higher price and agreeing to harsher penalties for losing files.
|
||||
An efficient market will optimize storage strategies.
|
||||
|
||||
Hosts are vulnerable to denial of service attacks, which could prevent them from submitting storage proofs or transferring files.
|
||||
It is the responsibility of the host to protect themselves from such attacks.
|
||||
|
||||
\subsection{Client Protections}
|
||||
\label{subsec:client-protect}
|
||||
Clients can use erasure codes, such as regenerating codes \cite{reg}, to safeguard against hosts going offline.
|
||||
These codes typically operate by splitting a file into $n$ pieces, such that the file can be recovered from any subset of $m$ unique pieces.
|
||||
(The values of $n$ and $m$ vary based on the specific erasure code and redundancy factor.)
|
||||
Each piece is then encrypted and stored across many hosts.
|
||||
This allows a client to attain high file availability even if the average network reliability is low.
|
||||
As an extreme example, if only 10 out of 100 pieces are needed to recover the file, then the client is actually relying on the 10 most reliable hosts, rather than the average reliability.
|
||||
Availability can be further improved by rehosting file pieces whose hosts have gone offline.
|
||||
Other metrics benefit from this strategy as well; the client can reduce latency by downloading from the closest 10 hosts, or increase download speed by downloading from the 10 fastest hosts.
|
||||
These downloads can be run in parallel to maximize available bandwidth.
|
||||
|
||||
\subsection{Uptime Incentives}
|
||||
\label{sec:uptime}
|
||||
The storage proofs contain no mechanism to enforce constant uptime.
|
||||
There are also no provisions that require hosts to transfer files to clients upon request.
|
||||
One might expect, then, to see hosts holding their clients' files hostage and demanding exorbitant fees to download them.
|
||||
However, this attack is mitigated through the use of erasure codes, as described in section \ref{subsec:client-protect}.
|
||||
The strategy gives clients the freedom to ignore uncooperative hosts and work only with those that are cooperative.
|
||||
As a result, power shifts from the host to the client, and the ``download fee'' becomes an ``upload incentive.''
|
||||
|
||||
In this scenario, clients offer a reward for being sent a file, and hosts must compete to provide the best quality of service.
|
||||
Clients may request a file at any time, which incentivizes hosts to maximize uptime in order to collect as many rewards as possible.
|
||||
Clients can also incentivize greater throughput and lower latency via proportionally larger rewards.
|
||||
Clients could even perform random ``checkups'' that reward hosts simply for being online, even if they do not wish to download anything.
|
||||
However, we reiterate that uptime incentives are not part of the Sia protocol; they are entirely dependent on client behavior.
|
||||
|
||||
Payment for downloads is expected to be offered through preexisting micropayment channels \cite{mpc}.
|
||||
Micropayment channels allow clients to make many consecutive small payments with minimal latency and blockchain bloat.
|
||||
Hosts could transfer a small segment of the file and wait to receive a micropayment before proceeding.
|
||||
The use of many consecutive payments allows each party to minimize the risk of being cheated.
|
||||
Micropayments are small enough and fast enough that payments could be made every few seconds without having any major effect on throughput.
|
||||
|
||||
\subsection{Basic Reputation System}
|
||||
Clients need a reliable method for picking quality hosts.
|
||||
Analyzing their history is insufficient, because the history could be spoofed.
|
||||
A host could repeatedly form contracts with itself, agreeing to store large ``fake'' files, such as a file containing only zeros.
|
||||
It would be trivial to perform storage proofs on such data without actually storing anything.
|
||||
|
||||
To mitigate this Sybil attack, clients can require that hosts that announce themselves in the arbitrary data section also include a large volume of time locked coins.
|
||||
If 10 coins are time locked 14 days into the future, then the host can be said to have created a lock valued at 140 coin-days.
|
||||
By favoring hosts that have created high-value locks, clients can mitigate the risk of Sybil attacks, as valuable locks are not trivial to create.
|
||||
|
||||
Each client can choose their own equation for picking hosts, and can use a large number of factors, including price, lock value, volume of storage being offered, and the penalties hosts are willing to pay for losing files.
|
||||
More complex systems, such as those that use human review or other metrics, could be implemented out-of-band in a more centralized setting.
|
||||
|
||||
\section{Siafunds}
|
||||
Sia is a product of Nebulous Incorporated.
|
||||
Nebulous is a for-profit company, and Sia is intended to become a primary source of income for the company.
|
||||
Currency premining is not a stable source of income, as it requires creating a new currency and tethering the company's revenue to the currency's increasing value.
|
||||
When the company needs to spend money, it must trade away portions of its source of income.
|
||||
Additionally, premining means that one entity has control over a large volume of the currency, and therefore potentially large and disruptive control over the market.
|
||||
|
||||
Instead, Nebulous intends to generate revenue from Sia in a manner proportional to the value added by Sia, as determined by the value of the contracts set up between clients and hosts.
|
||||
This is accomplished by imposing a fee on all contracts.
|
||||
When a contract is created, 3.9\% of the contract fund is removed and distributed to the holders of \textit{siafunds}.
|
||||
Nebulous Inc. will initially hold approx. 88\% of the siafunds, and the early crowd-fund backers of Sia will hold the rest.
|
||||
|
||||
Siafunds can be sent to other addresses, in the same way that siacoins can be sent to other addresses.
|
||||
They cannot, however, be used to fund contracts or miner fees.
|
||||
When siafunds are transferred to a new address, an additional unspent output is created, containing all of the siacoins that have been earned by the siafunds since their previous transfer.
|
||||
These siacoins are sent to the same address as the siafunds.
|
||||
|
||||
\section{Economics of Sia}
|
||||
The primary currency of Sia is the siacoin.
|
||||
The supply of siacoins will increase permanently, and all fresh supply will be given to miners as a block subisdy.
|
||||
The first block will have 300,000 coins minted.
|
||||
This number will decrease by 1 coin per block, until a minimum of 30,000 coins per block is reached.
|
||||
Following a target of 10 minutes between blocks, the annual growth in supply is:\\
|
||||
|
||||
\tabcolsep=0.11cm \noindent
|
||||
\begin{tabular}{ l | *{7}{c} }
|
||||
Year & 1 & 2 & 3 & 4 & 5 & 8 & 20 \\ \hline
|
||||
Growth & 90\% & 39\% & 21\% & 11.5\% & 4.4\% & 3.2\% & 2.3\%
|
||||
\end{tabular} \\
|
||||
|
||||
There are inefficiencies within the Sia incentive scheme.
|
||||
The primary goal of Sia is to provide a blockchain that enforces storage contracts.
|
||||
The mining reward, however, is only indirectly linked to the total value of contracts being created.
|
||||
|
||||
The siacoin, especially initially, is likely to have high volatility.
|
||||
Hosts can be adversely affected if the value of the currency shifts mid-contract.
|
||||
As a result, we expect to see hosts increasing the price of long-term contracts as a hedge against volatility.
|
||||
Additionally, hosts can advertise their prices in a more stable currency (like USD) and convert to siacoin immediately before finalizing a contract.
|
||||
Eventually, the use of two-way pegs with other crypto-assets will give hosts additional means to insulate themselves from volatility.
|
||||
|
||||
% \section{Under Consideration}
|
||||
% The primary foundation of Sia has been established above.
|
||||
% Other considerations, such as mining algorithms, block time, etc., can be assumed to mirror those found in Bitcoin.
|
||||
|
||||
% Giving careful attention to ``A Treatise on Altcoins'' \cite{alts}, we are considering the following changes to Sia for the overall improvement of the cryptocurrency.
|
||||
% We caution that these propositions have not yet been rigorously examined from a security standpoint.
|
||||
|
||||
% \subsection{Flexible Contracts}
|
||||
% Contracts, in their present form, are fairly strict.
|
||||
% There is a set penalty for each missed storage proof, and a termination upon $n$ total missed storage proofs.
|
||||
% Increased flexibility in the penalty schedule may be desirable.
|
||||
|
||||
% Contracts are also permanent, creating what is essentially an uneditable file on the network.
|
||||
% There may be value in enabling clients and hosts to negotiate an updated file hash or other updated contract terms.
|
||||
% Updating the terms of the contract would require consent from all parties.
|
||||
|
||||
% \subsection{Proof of Existence Windows}
|
||||
% In an attempt to partially resolve the closed window attacks, we could use a proof of existence strategy.
|
||||
% A host can create a hash of the storage proof which they submit to the blockchain within the window.
|
||||
% The host then has a greatly extended window in which they can demonstrate that the proof of storage was created during the required window.
|
||||
|
||||
% This has two advantages.
|
||||
% First, an attacker cannot selectively exclude proof of existence hashes, because there's no way to figure out who owns each hash.
|
||||
% Either the attacker doesn't include any unknown proof of existence hashes, or the attacker risks including undesired proof of existence hashes.
|
||||
% Second, this allows hosts to submit small transactions to the network during peak hours and then the larger transactions when the traffic has died down.
|
||||
|
||||
% A further improvement would enable Merkle Tree proofs of existence.
|
||||
% This would enable a host to submit multiple proofs of storage in a single proof of existence hash.
|
||||
|
||||
% % delete/expand this section?
|
||||
% \subsection{Siafund the Miner fees}
|
||||
% Have some portion of siafunds contribute to the miner fees, which ensures that miners have compensation so long as Sia is being used for its core purpose - storage.
|
||||
|
||||
% \subsection{Miner Fee Adjustments}
|
||||
% If a block has miner fees which are significantly higher than the fees in the current block, there is incentive for miners to re-mine the previous block and change who gets the miner fees.
|
||||
% This can be mitigated by putting all of the fees into a pool which pays out 50\% every block, making re-mining unprofitable for any party with less than 50\% of the network hashing power.
|
||||
% Link to discussion threads of this potential change.
|
||||
|
||||
% Additionally, miners have incentives not to propagate high fee transactions, because this will prevent other miners from mining the transaction and collecting the fees.
|
||||
% It may be possible to construct a system using fee deterioration that means a miner has the highest expected total reward when the transaction is mined as soon as possible - regardless of who mines the transaction.
|
||||
% Link to discussion threads of this potential change.
|
||||
|
||||
% \subsection{More Frequent Target Adjustments}
|
||||
% % This section could use a few citations, but the discussion on this seems pretty well scattered. I could find things like the Kimoto Gravity Well, but other than alts.pdf I couldn't find any comments by respected individuals. I know that these discussions are out there, I've seen them before, just can't find them.
|
||||
% Bitcoin adjusts its block difficulty every 2016 blocks, with a target of 10 minutes per block.
|
||||
% This often means that the final blocks in a difficulty window are produced faster than 10 minutes (sometimes substantially) on account of rapid growth in available mining power.
|
||||
% To mitigate this effect, we are considering adjusting the difficulty after every block.
|
||||
|
||||
% % I don't understand this paragraph
|
||||
% The bi-weekly adjustments to the Bitcoin difficulty can also cause coordinated drops in mining power---all at once, miners lose a percentage of their dollars-per-energy efficiency.
|
||||
% Difficulty adjustments every block creates a much smoother function for when mining rigs are no longer profitable.
|
||||
|
||||
% The clamp on mining growth can also be increased.
|
||||
% The clamp serves to prevent an attacker from being easily manipulating the difficulty.
|
||||
% % 2,016,000 what?
|
||||
% In Bitcoin, raising the difficulty from 1000 to 4000 requires a minimum of 2,016,000 of work, and the difficulty can adjust by a maximum of 4x every week.
|
||||
% If the difficulty is being adjusted every block, however, and clamped at 1.001\% per block, an attacker will need 3,000,050 work to raise the difficulty from 1000 to 4000.
|
||||
% At this rate, the difficulty can shift by a maximum of 7.5x every week, which both increases the flexibility of the difficulty and makes difficulty raising attacks more difficult.
|
||||
|
||||
% Though the difficulty will be adjusted every block, it will still be adjusted according to the amount of time taken to produce the previous 2016 blocks, preventing randomly fast or slow blocks from having large impact on the network.
|
||||
|
||||
% \subsection{Committing to State}
|
||||
% One thing that could allow for substantially lighter weight clients is if the miners committed to the current state of the network, instead of just to the new transactions.
|
||||
% This would mean creating a structure for a database that represents the state of the network and hashing it.
|
||||
% We could follow suggestions similar to those presented in ``Ultimate blockchain compression'' \cite{ubc}.
|
||||
|
||||
% \subsection{Variance Enforced Merge Mining}
|
||||
% Bitcoin enforces a number of leading 0s on a winning block.
|
||||
% Sia could enforce something like a single leading 1, followed by a bunch of leading 0s.
|
||||
% This creates the property that no hash is ever valid for both Bitcoin and Sia.
|
||||
|
||||
% The value to this is that the number of payouts a miner gets from finding blocks goes up.
|
||||
% The total payout is still the same, but the number of payouts increases by the number of blocks that would have been valid for both.
|
||||
% A block that solves the coin with the highest difficulty will always be valid for both blockchains.
|
||||
% (I need to read more about merge mining before I publish this section)
|
||||
|
||||
\section{Conclusion}
|
||||
Sia is a variant on the Bitcoin protocol that enables decentralized file storage via cryptographic contracts.
|
||||
These contracts can be used to enforce storage agreements between clients and hosts.
|
||||
After agreeing to store a file, a host must regularly submit storage proofs to the network.
|
||||
The host will automatically be compensated for storing the file regardless of the behavior of the client.
|
||||
|
||||
Importantly, contracts do not require hosts to transfer files back to their client when requested.
|
||||
Instead, an out-of-band ecosystem must be created to reward hosts for uploading.
|
||||
Clients and hosts must also find a way to coordinate; one mechanism would be the arbitrary data field in the blockchain.
|
||||
Various precautions have been enumerated which mitigate Sybil attacks and the unreliability of hosts.
|
||||
|
||||
Siafunds are used as a mechanism of generating revenue for Nebulous Inc., the company responsible for the release and maintenance of Sia.
|
||||
By using Siafunds instead of premining, Nebulous more directly correlates revenue to actual use of the network, and is largely unaffected by market games that malicious entities may play with the network currency.
|
||||
Miners may also derive a part of their block subsidy from siafunds, with similar benefits.
|
||||
Long term, we hope to add support for two-way-pegs with various currencies, which would enable consumers to insulate themselves from the instability of a single currency.
|
||||
|
||||
We believe Sia will provide a fertile platform for decentralized cloud storage in trustless environments.
|
||||
|
||||
\onecolumn
|
||||
\begin{thebibliography}{9}
|
||||
|
||||
\bibitem{btc}
|
||||
Satoshi Nakamoto,
|
||||
\emph{Bitcoin: A Peer-to-Peer Electronic Cash System}.
|
||||
|
||||
\bibitem{merkle}
|
||||
R.C. Merkle,
|
||||
\emph{Protocols for public key cryptosystems},
|
||||
In Proc. 1980 Symposium on Security and Privacy,
|
||||
IEEE Computer Society, pages 122-133, April 1980.
|
||||
|
||||
\bibitem{cpr}
|
||||
Hovav Shacham, Brent Waters,
|
||||
\emph{Compact Proofs of Retrievability},
|
||||
Proc. of Asiacrypt 2008, vol. 5350, Dec 2008, pp. 90-107.
|
||||
|
||||
\bibitem{reg}
|
||||
K. V. Rashmi, Nihar B. Shah, and P. Vijay Kumar,
|
||||
\emph{Optimal Exact-Regenerating Codes for Distributed Storage at the MSR and MBR Points via a Product-Matrix Construction}.
|
||||
|
||||
\bibitem{side}
|
||||
Adam Back, Matt Corallo, Luke Dashjr, Mark Friedenbach, Gregory Maxwell, Andrew Miller, Andrew Peolstra, Jorge Timon, Pieter Wuille,
|
||||
\emph{Enabling Blockchain Innovations with Pegged Sidechains}.
|
||||
|
||||
\bibitem{alts}
|
||||
Andrew Poelstra,
|
||||
\emph{A Treatise on Altcoins}.
|
||||
|
||||
\bibitem{ibf}
|
||||
Gavin Andresen,
|
||||
\emph{O(1) Block Propagation},
|
||||
https://gist.github.com/gavinandresen/e20c3b5a1d4b97f79ac2
|
||||
|
||||
\bibitem{hdw}
|
||||
Gregory Maxwell,
|
||||
\emph{Deterministic Wallets},
|
||||
https://bitcointalk.org/index.php?topic=19137.0
|
||||
|
||||
\bibitem{ubc}
|
||||
etotheipi,
|
||||
Ultimate blockchain compression w/ trust-free lite nodes, \newline
|
||||
https://bitcointalk.org/index.php?topic=88208.0
|
||||
|
||||
\bibitem{poc}
|
||||
Gregory Maxwell,
|
||||
\emph{Proof of Storage to make distributed resource consumption costly.} \newline
|
||||
https://bitcointalk.org/index.php?topic=310323.0
|
||||
|
||||
\bibitem{mpc}
|
||||
Mike Hearn,
|
||||
\emph{Rapidly-adjusted (micro)payments to a pre-determined party},\newline
|
||||
https://en.bitcoin.it/wiki/Contracts\#Example\_7:\_Rapidly-adjusted\_.28micro.29payments\_to\_a\_pre-determined\_party
|
||||
|
||||
\bibitem{btcdg}
|
||||
Bitcoin Developer Guide,
|
||||
https://bitcoin.org/en/developer-guide
|
||||
|
||||
|
||||
\end{thebibliography}
|
||||
|
||||
\end{document}
|
BIN
3rd_party/Sia-v1.1.1-windows-amd64/siac.exe
vendored
Normal file
BIN
3rd_party/Sia-v1.1.1-windows-amd64/siac.exe
vendored
Normal file
Binary file not shown.
BIN
3rd_party/Sia-v1.1.1-windows-amd64/siac.exe.sig
vendored
Normal file
BIN
3rd_party/Sia-v1.1.1-windows-amd64/siac.exe.sig
vendored
Normal file
Binary file not shown.
BIN
3rd_party/Sia-v1.1.1-windows-amd64/siad.exe
vendored
Normal file
BIN
3rd_party/Sia-v1.1.1-windows-amd64/siad.exe
vendored
Normal file
Binary file not shown.
BIN
3rd_party/Sia-v1.1.1-windows-amd64/siad.exe.sig
vendored
Normal file
BIN
3rd_party/Sia-v1.1.1-windows-amd64/siad.exe.sig
vendored
Normal file
Binary file not shown.
601
3rd_party/ttmath-0.9.3/CHANGELOG
vendored
Normal file
601
3rd_party/ttmath-0.9.3/CHANGELOG
vendored
Normal file
@@ -0,0 +1,601 @@
|
||||
Version 0.9.3 (2012.11.28):
|
||||
* fixed: in Big::FromDouble(double value) (only 32 bit version)
|
||||
buffer overflow in referencing to UInt<2>
|
||||
this was used when 'value' was in so called "unnormalized" state
|
||||
(E=0 and F is nonzero)
|
||||
it produced incorrect mantissa (on about 8th decimal digit up)
|
||||
* added: Parser::InitCGamma()
|
||||
initializing coefficients used when calculating the gamma (or factorial) function
|
||||
this speed up the next calculations
|
||||
you don't have to call this method explicitly
|
||||
these coefficients will be calculated when needed
|
||||
* added: option 'group_digits' to Conv struct
|
||||
you can set how many digits should be grouped
|
||||
* changed: small optimizations in UInt::ToString() and Big::FromString()
|
||||
|
||||
|
||||
Version 0.9.2 (2010.09.23):
|
||||
* fixed: Big::Add() sometimes incorrectly rounded the last bit from its mantissa
|
||||
* fixed: Big::BigAnd() Big::BigOr() Big::BigXor() should have set NaN
|
||||
when the argument was negative (they only returned 2)
|
||||
* fixed: recurrence calling in Big::FromString(const std::string &, uint, const wchar_t **, bool *)
|
||||
it should have the signature: Big::FromString(const std::string &, uint, const char **, bool *)
|
||||
* fixed: Big::ToString method
|
||||
in some cases when in the output string the exponent should be equal zero
|
||||
the method changes the exponent to one so the last digit from the mantissa
|
||||
was lost
|
||||
* fixed: Big::ToDouble(double &) set always +INF (infinity)
|
||||
when the value was too large (even for negative values)
|
||||
(it should set -INF in such a case)
|
||||
* added: some missing operators
|
||||
UInt::operator~() /* bitwise neg */
|
||||
UInt::operator&() /* bitwise and */
|
||||
UInt::operator&=()
|
||||
UInt::operator|() /* bitwise or */
|
||||
UInt::operator|=()
|
||||
UInt::operator^() /* bitwise xor */
|
||||
UInt::operator^=()
|
||||
Big::operator&()
|
||||
Big::operator&=()
|
||||
Big::operator|()
|
||||
Big::operator|=()
|
||||
Big::operator^()
|
||||
Big::operator^=()
|
||||
for Big<> we do not define bitwise neg
|
||||
Big::operator++()
|
||||
Big::operator++(int)
|
||||
Big::operator--()
|
||||
Big::operator--(int)
|
||||
* added: macro TTMATH_DONT_USE_WCHAR
|
||||
if defined then the library does not use wide characters
|
||||
(wchar_t, std::wstring, ...) this is a workaround for some compilers
|
||||
* added: bool UInt::IsOnlyTheHighestBitSet()
|
||||
bool UInt::IsOnlyTheLowestBitSet()
|
||||
returning true if only the highest/lowest bit is set
|
||||
* added: uint Int::MulInt(sint ss2)
|
||||
* added: void UInt::Swap(UInt<value_size> & ss2)
|
||||
void Big::Swap(UInt<value_size> & ss2)
|
||||
method for swapping this for an argument
|
||||
* added: macro TTMATH_BIG_DEFAULT_CLEAR
|
||||
when defined the default constructor from Big<> clears its mantissa and exponent
|
||||
Big<1, 2> var;
|
||||
var.mantissa and var.exponent will be set to zero
|
||||
(but var has the NaN flag set too - it is not zero value, this is mainly for debug purposes)
|
||||
* added: only on 32bit platforms:
|
||||
uint UInt::FromUInt(uint64_t n)
|
||||
uint Int::FromInt(int64_t n)
|
||||
void Big::FromUInt(uint64_t n)
|
||||
void Big::FromInt(int64_t n)
|
||||
and appropriate constructors and operators
|
||||
* added: TTMATH_FORCEASM macro
|
||||
asm version of the library is available by default only for:
|
||||
x86 and amd64 platforms and for Microsoft Visual and GCC compilers,
|
||||
but you can force using asm version (the same asm as for Microsoft Visual)
|
||||
by defining TTMATH_FORCEASM macro
|
||||
you have to be sure that your compiler accept such an asm format
|
||||
* added: some missing methods for converting
|
||||
for UInt<>, Int<> and Big<> classes:
|
||||
uint ToUInt()
|
||||
sint ToInt()
|
||||
ToUInt(uint32_t &)
|
||||
ToInt(uint32_t &)
|
||||
ToInt(int32_t &)
|
||||
ToUInt(uint64_t &)
|
||||
ToInt(uint64_t &)
|
||||
ToInt(int64_t &)
|
||||
FromUInt(uint32_t &)
|
||||
FromInt(uint32_t &)
|
||||
FromInt(int32_t &)
|
||||
FromUInt(uint64_t &)
|
||||
FromInt(uint64_t &)
|
||||
FromInt(int64_t &)
|
||||
and appropriate constructors and operators
|
||||
* added: double Big::ToDouble() /there was only Big::ToDouble(double &) /
|
||||
uint Big::ToFloat(float &)
|
||||
float Big::ToFloat()
|
||||
* changed: now asm version is available only on x86 and amd64
|
||||
(and only for GCC and MS VC compilers)
|
||||
* removed: macro TTMATH_RELEASE (now the 'release' version is default)
|
||||
for debug version define TTMATH_DEBUG macro
|
||||
TTMATH_DEBUG is also automatically defined when DEBUG or _DEBUG is set
|
||||
* removed: macro TTMATH_REFERENCE_ASSERT from all methods in public interface
|
||||
|
||||
|
||||
Version 0.9.1 (2010.02.07):
|
||||
* fixed: the parser didn't use characters for changing the base (# and &)
|
||||
those characters were skipped
|
||||
(this bug was introduced in 0.9.0)
|
||||
* fixed: added in the parser: operator's associativity
|
||||
operator ^ (powering) is right-associative:
|
||||
sample: 2^3^4 is equal 2^(3^4) and it is: 2.41e+24
|
||||
previously was: 2^3^4 = (2^3)^4 = 4096
|
||||
* fixed: in Big::ToString_CreateNewMantissaAndExponent() changed the formula:
|
||||
new_exp_ = [log base (2^exponent)] + 1
|
||||
now the part '+ 1' is only made when the logarithm is positive and with fraction
|
||||
if the value is negative we can only skip the fraction, previously
|
||||
we lost some last digits from the new mantissa
|
||||
Consider this binary value (32 bit mantissa):
|
||||
(bin)1.0000000000000000000000000000011
|
||||
previously ToString() gave 1, now we have: 1.000000001
|
||||
* changed: in Big::ToString() the base rounding is made only if the result value
|
||||
would not be an integer, e.g. if the value is 1.999999999999 then
|
||||
the base rounding will not be done - because as the result would be 2
|
||||
* added: IEEE 754 half-to-even rounding (bankers' rounding) to the following
|
||||
floating point algorithms: Big::Add, Big::Sub, Big::Mul, Big::Div
|
||||
* added: static sint UInt<value_size>::FindLowestBitInWord(uint x)
|
||||
this method is looking for the lowest set bit in a word
|
||||
* added: UInt::FindLowestBit(uint & table_id, uint & index)
|
||||
this method is looking for the lowest set bit
|
||||
|
||||
|
||||
Version 0.9.0 (2009.11.25):
|
||||
* added: support for wide characters (wchar_t, std::wstring)
|
||||
* added: Big::IsInteger()
|
||||
returns true if the value is integer (without fraction)
|
||||
(NaN flag is not checked)
|
||||
* added: global Gamma() function
|
||||
* added: gamma() function to the parser
|
||||
* added: CGamma<ValueType> class
|
||||
is used with Gamma() and Factorial() in multithreaded environment
|
||||
* added: multithread support for Big<> class
|
||||
you should compile with TTMATH_MULTITHREADS
|
||||
and use TTMATH_MULTITHREADS_HELPER macro somewhere in your *.cpp file
|
||||
* added: x86_64 asm code for Microsoft Visual compiler
|
||||
file: ttmathuint_x86_64_msvc.asm
|
||||
(this file should be compiled first because MS VC doesn't support inline assembler in x86_64 mode)
|
||||
* added: flag TTMATH_BIG_ZERO to Big<> class
|
||||
if this flag is set then there is a value zero
|
||||
Big::IsZero() is faster now
|
||||
* added: Big::ClearInfoBit(unsigned char)
|
||||
Big::SetInfoBit(unsigned char)
|
||||
Big::IsInfoBit(unsigned char)
|
||||
some methods for manipulating the info flags
|
||||
* added: macro: TTMATH_BITS(min_bits)
|
||||
which returns the number of machine words
|
||||
capable to hold min_bits bits
|
||||
* added: bool Parser::Calculated()
|
||||
this method returns true is something was calculated
|
||||
(at least one mathematical operator was used or a function or variable)
|
||||
* added: to the parser: operator percentage
|
||||
e.g. 1000-50%=1000-(1000*0,5)=500
|
||||
* added: struct: Conv
|
||||
consists of some parameters used
|
||||
in ToString() and FromString()
|
||||
* added: Big::ToString() can group digits
|
||||
e.g. 1234567 -> 1`234`567
|
||||
* added: Parser::SetGroup(int g)
|
||||
Parser::SetComma(int c, int c2 = 0)
|
||||
Parser::SetParamSep(int s)
|
||||
* added: std::string UInt::ToString(uint b = 10)
|
||||
std::wstring UInt::ToWString(uint b = 10)
|
||||
std::string Int::ToString(uint b = 10)
|
||||
std::wstring Int::ToWString(uint b = 10)
|
||||
uint Big::ToString(std::string & result, const Conv & conv)
|
||||
uint Big::ToString(std::wstring & result, const Conv & conv)
|
||||
std::string Big::ToString(const Conv & conv)
|
||||
std::string Big::ToString()
|
||||
std::wstring Big::ToWString(const Conv & conv)
|
||||
std::wstring Big::ToWString()
|
||||
* added: uint FromString(const char * source, const Conv & conv, const char **, bool *)
|
||||
uint FromString(const wchar_t * source, const Conv & conv, const wchar_t **, bool *)
|
||||
uint FromString(const std::string & string, const Conv & conv, const wchar_t **, bool *)
|
||||
uint FromString(const std::wstring & string, const Conv & conv, const wchar_t **, bool *)
|
||||
* added: UInt::Sqrt() - a new algorithm for calculating the square root
|
||||
* added: to the parser: function frac() - returns a value without the integer part
|
||||
(only fraction remains)
|
||||
* added: Int::DivInt(sint divisor, sint * remainder)
|
||||
* added: const char * UInt::LibTypeStr()
|
||||
const char * Big::LibTypeStr()
|
||||
LibTypeCode UInt::LibType()
|
||||
LibTypeCode Big::LibType()
|
||||
returning a string/enum represents the currect type of the library
|
||||
we have following types:
|
||||
asm_vc_32 - with asm code designed for Microsoft Visual C++ (32 bits)
|
||||
asm_gcc_32 - with asm code designed for GCC (32 bits)
|
||||
asm_vc_64 - with asm for VC (64 bit)
|
||||
asm_gcc_64 - with asm for GCC (64 bit)
|
||||
no_asm_32 - pure C++ version (32 bit) - without any asm code
|
||||
no_asm_64 - pure C++ version (64 bit) - without any asm code
|
||||
* added: UInt::operator>>(int)
|
||||
UInt::operator>>=(int)
|
||||
UInt::operator<<(int)
|
||||
UInt::operator<<=(int)
|
||||
* changed: Factorial() is using the Gamma() function now
|
||||
* changed: Big::Div(ss2)
|
||||
Big::Mod(ss2)
|
||||
they return 2 when ss2 is zero
|
||||
previously returned 1
|
||||
* changed: algorithms in Big::Sqrt() and ttmath::Root(x ; n)
|
||||
they were not too much accurate for some integers
|
||||
e.g. Root(16;4) returned a value very closed to 2 (not exactly 2)
|
||||
* changed: added specializations to Big::ToString() when the base is equal 4, 8 or 16
|
||||
the previous version was not accurate on some last digits (after the comma operator)
|
||||
consider this binary value (32 bit mantissa):
|
||||
base 2: 1.1111 1111 1111 1111 1111 1111 1110 101
|
||||
previous ToString() gave:
|
||||
base 4: 1.33333333333332
|
||||
base 8: 1.777777777
|
||||
base 16: 1.FFFFFF
|
||||
now we have:
|
||||
base 4: 1.3333333333333222
|
||||
base 8: 1.77777777724
|
||||
base 16: 1.FFFFFFEA
|
||||
* changed: in Big::ToString() some additional rounding (base_round) is now made only
|
||||
when the value is not an integer
|
||||
* changed: another compilers than MS VC or GCC by default use no asm version (TTMATH_NOASM)
|
||||
* removed: Parser<>::SetFactorialMax() method
|
||||
the factorial() is such a fast now that we don't need the method longer
|
||||
* removed: ErrorCode::err_too_big_factorial
|
||||
* removed: macros: TTMATH_COMMA_CHARACTER_1 and TTMATH_COMMA_CHARACTER_2
|
||||
the comma characters we have in Conv struct now
|
||||
|
||||
|
||||
Version 0.8.6 (2009.10.25):
|
||||
* fixed: UInt::SetBitInWord(uint & value, uint bit) set 1 if the bit was
|
||||
equal 1 (should be set 2)
|
||||
this affected only no-asm parts - when macro TTMATH_NOASM was defined
|
||||
* fixed: UInt<value_size>::MulInt(uint ss2)
|
||||
there was a buffer overflow when value_size was equal 1
|
||||
* fixed: UInt::AddVector() and UInt::SubVector() didn't want to compile
|
||||
when macro TTMATH_NOASM was defined
|
||||
* fixed: Big::operator>> didn't correctly recognize values in scientific mode (with 'e' character)
|
||||
* fixed: Int::FromString(const tt_string & s, uint b = 10)
|
||||
didn't use 'b' (always was '10')
|
||||
* fixed: buffer overflow in Big::ToInt(Int<int_size> & result)
|
||||
* fixed: powering algorithm in:
|
||||
UInt::Pow(UInt<value_size> pow)
|
||||
Big::Pow(UInt<pow_size> pow)
|
||||
Big::PowUInt(Big<exp, man> pow)
|
||||
when 'pow' was sufficient large the algorithm returned carry
|
||||
but the result could have been calculated correctly
|
||||
|
||||
|
||||
Version 0.8.5 (2009.06.16):
|
||||
* fixed: Big::Mod(x) didn't correctly return a carry
|
||||
and the result was sometimes very big (even greater than x)
|
||||
* fixed: global function Mod(x) didn't set an ErrorCode object
|
||||
* fixed: global function Round() didn't test a carry
|
||||
now it sets ErrorCode object
|
||||
* changed: function Sin(x) to Sin(x, ErrorCode * err=0)
|
||||
when x was very big the function returns zero
|
||||
now it sets ErrorCode object to err_overflow
|
||||
and the result has a NaN flag set
|
||||
the same is to Cos() function
|
||||
* changed: PrepareSin(x) is using Big::Mod() now when reducing 2PI period
|
||||
should be a little accurate especially on a very big 'x'
|
||||
* changed: uint Mul(const UInt<value_size> & ss2, uint algorithm = 100)
|
||||
void MulBig(const UInt<value_size> & ss2, UInt<value_size*2> & result, uint algorithm = 100)
|
||||
those methods by default use MulFastest() and MulFastestBig()
|
||||
* changed: changed a little Mul2Big() to cooperate with Mul3Big()
|
||||
* added: uint UInt::Mul3(const UInt<value_size> & ss2)
|
||||
void UInt::Mul3Big(const UInt<value_size> & ss2, UInt<value_size*2> & result)
|
||||
a new multiplication algorithm: Karatsuba multiplication,
|
||||
on a vector UInt<100> with all items different from zero this algorithm is faster
|
||||
about 3 times than Mul2Big(), and on a vector UInt<1000> with all items different from
|
||||
zero this algorithm is faster more than 5 times than Mul2Big()
|
||||
(measured on 32bit platform with GCC 4.3.3 with -O3 and -DTTMATH_RELEASE)
|
||||
* added: uint MulFastest(const UInt<value_size> & ss2)
|
||||
void MulFastestBig(const UInt<value_size> & ss2, UInt<value_size*2> & result)
|
||||
those methods are trying to select the fastest multiplication algorithm
|
||||
* added: uint AddVector(const uint * ss1, const uint * ss2, uint ss1_size, uint ss2_size, uint * result)
|
||||
uint SubVector(const uint * ss1, const uint * ss2, uint ss1_size, uint ss2_size, uint * result)
|
||||
three forms: asm x86, asm x86_64, no-asm
|
||||
those methods are used by the Karatsuba multiplication algorithm
|
||||
* added: to Big<> class: support for NaN flag (Not a Number)
|
||||
bool Big::IsNan() - returns true if the NaN flag is set
|
||||
void Big::SetNan() - sets the NaN flag
|
||||
The NaN flag is set by default after creating an object:
|
||||
Big<1, 2> a; // NaN is set (it means the object has not a valid number)
|
||||
std::cout << a; // cout gives "NaN"
|
||||
a = 123; // now NaN is not set
|
||||
std::cout << a; // cout gives "123"
|
||||
The NaN is set if there was a carry during calculations
|
||||
a.Mul(very_big_value); // a will have a NaN set
|
||||
The NaN is set if an argument is NaN too
|
||||
b.SetNan();
|
||||
a.Add(b); // a will have NaN because b has NaN too
|
||||
If you try to do something on a NaN object, the result is a NaN too
|
||||
a.SetNan();
|
||||
a.Add(2); // a is still a NaN
|
||||
The NaN is set if you use incorrect arguments
|
||||
a.Ln(-10); // a will have the NaN flag
|
||||
The only way to clear the NaN flag is to assign a correct value or other correct object,
|
||||
supposing 'a' has NaN flag, to remove the flag you can either:
|
||||
a = 10;
|
||||
a.FromInt(30);
|
||||
a.SetOne();
|
||||
a.FromBig(other_object_without_nan);
|
||||
etc.
|
||||
|
||||
|
||||
Version 0.8.4 (2009.05.08):
|
||||
* fixed: UInt::DivInt() didn't check whether the divisor is zero
|
||||
there was a hardware interruption when the divisor was zero
|
||||
(now the method returns one)
|
||||
* fixed: the problem with GCC optimization on x86_64
|
||||
sometimes when using -O2 or -O3 GCC doesn't set correctly
|
||||
the stack pointer (actually the stack is used for other things)
|
||||
and you can't use instructions like push/pop in assembler code.
|
||||
All the asm code in x86_64 have been rewritten, now instructions
|
||||
push/pop are not used, other thing which have access to stack
|
||||
(like "m" (mask) constraints in Rcl2 and Rcr2) have also gone away,
|
||||
now the library works well with -O2 and -O3 and the asm code
|
||||
is a little faster
|
||||
* added: UInt::PrintLog(const char * msg, std::ostream & output)
|
||||
used (for debugging purposes) by macro TTMATH_LOG(msg)
|
||||
(it is used in nearly all methods in UInt class)
|
||||
* added: macro TTMATH_DEBUG_LOG: when defined then TTMATH_LOG()
|
||||
put some debug information (to std::cout)
|
||||
* added: ttmathuint_x86.h, ttmathuint_x86_64.h, ttmathuint_noasm.h,
|
||||
all the methods which are using assembler code have been
|
||||
rewritten to no-asm forms, now we have:
|
||||
1. asm for x86 file: ttmathuint_x86.h
|
||||
2. asm for x86_64 file: ttmathuint_x86_64.h
|
||||
3. no asm file: ttmathuint_noasm.h
|
||||
(it's used when macro TTMATH_NOASM is defined)
|
||||
The third form can be used on x86 and x86_64 as well and
|
||||
on other platforms with a little effort.
|
||||
|
||||
|
||||
Version 0.8.3 (2009.04.06):
|
||||
* fixed: RclMoveAllWords() and RcrMoveAllWords() sometimes didn't return
|
||||
the proper carry, (when 'bits' was greater than or equal to 'value_size')
|
||||
this had impact on Rcl() and Rcr(), they also returned the wrong carry
|
||||
* fixed: UInt::Div() didn't return a correct result when the divisor was equal 1
|
||||
there was an error in UInt::DivInt() - when the divisor was 1 it returned
|
||||
zero and the carry was set
|
||||
* fixed: there was a TTMATH_REREFENCE_ASSERT error in Big::PowUInt() caused by: start.Mul(start)
|
||||
* fixed: Big::Add incorrectly rounded 'this' when both exponents were equal
|
||||
it caused that sometimes when adding a zero the result has changed
|
||||
this had impact among other things on FromString() method
|
||||
"0,8" had different binary representation from "0,80"
|
||||
* fixed: template Big::FromBig(const Big<another_exp, another_man> & another)
|
||||
didn't correctly set the exponent (when the mantisses had different size -
|
||||
when 'man' was different from 'another_man')
|
||||
this had impact on operator= too
|
||||
sample:
|
||||
Big<2,3> a = 100;
|
||||
Big<3,5> b;
|
||||
b = a; // b had a wrong value
|
||||
* fixed: Big::Pow(const Big<exp, man> & pow)
|
||||
it's using PowInt() only when pow.exponent is in range (-man*TTMATH_BITS_PER_UINT; 0]
|
||||
previously the powering 'hung' on an input like this: "(1+ 1e-10000) ^ 10e100000000"
|
||||
(there was 10e100000000 iterations in PowInt())
|
||||
* fixed: in function DegToRad(const ValueType & x, ErrorCode * err = 0) it is better
|
||||
to make division first and then mutliplication -- the result is more
|
||||
accurate especially when x is: 90,180,270 or 360
|
||||
* fixed: the parser didn't correctly treat operators for changing the base
|
||||
(radix) -- operators '#' and '&', e.g.:
|
||||
'#sin(1)' was equal '0' -- there was a zero from '#' and then
|
||||
it was multipied by 'sin(1)'
|
||||
the parser didn't check whether Big::FromString() has actually
|
||||
read a proper value -- the method Big::FromString() didn't have
|
||||
something to report such a situation
|
||||
* fixed: Big::FromString() when the base is 10, the method reads the scientific
|
||||
part only if such a part it correctly supplied, e.g:
|
||||
'1234e10', '1234e+10', '1234e-5'
|
||||
previous '1234e' was treated as: '1234e0' (now parsing stops on 'e' and
|
||||
the 'e' can be parsed by other parsers, e.g. the mathematical
|
||||
parser -- now in the parser would be: '1234e' = '1234 * e' = '3354,3597...' )
|
||||
* changed: renamed: Big::PowUInt(UInt<pow_size> pow) -> Big::Pow(UInt<pow_size> pow)
|
||||
it returns 2 when there is: 0^0
|
||||
* changed: renamed: Big::PowInt(Int<pow_size> pow) -> Big::Pow(Int<pow_size> pow)
|
||||
it returns 2 when there is: 0^0 or 0^(-something)
|
||||
* changed: renamed: Big::PowBUInt() -> PowUInt(), Big::PowBInt() -> Big::PowInt()
|
||||
they return 2 when the arguments are incorrect (like above)
|
||||
* changed: UInt::SetBitInWord(uint & value, uint bit) is taking the first argument by a reference now,
|
||||
the specific bit is set in the 'value' and the method returns the last state of the bit (zero or one)
|
||||
* changed: UInt::SetBit(uint bit_index) - it's using TTMATH_ASSERT now
|
||||
* changed: the size of built-in variables (constants) in ttmathbig.h
|
||||
now they consist of 256 32bit words
|
||||
macro TTMATH_BUILTIN_VARIABLES_SIZE is equal: 256u on a 32bit platform and 128ul on a 64bit platform
|
||||
* changed: the asm code in ttmathuint.h and ttmathuint64.h has been completely rewritten
|
||||
now UInt<> is faster about 15-30% than UInt<> from 0.8.2
|
||||
this has impact on Big<> too - it's faster about 10% now
|
||||
* changed: in the parser: the form with operators '#' and '&' is as follows:
|
||||
[-|+][#|&]numeric_value
|
||||
previous was: [-|+][#|&][-|+]numeric_value
|
||||
* changed: in the parser: the short form of multiplication has the same
|
||||
priority as the normal multiplication, e.g.:
|
||||
'2x^3' = 2 * (x^3)
|
||||
previous the priority was greater than powering priority
|
||||
previous: '2x^3' = (2*x) ^ 3
|
||||
* added: UInt::GetBit(uint bit_index) - returning the state of the specific bit
|
||||
* added: Big::operator=(double) and Big::Big(double)
|
||||
* added: UInt::Pow(UInt<value_size> pow) and Int::Pow(Int<value_size> pow)
|
||||
* added: global template functions in ttmath.h:
|
||||
ValueType GradToRad(const ValueType & x, ErrorCode * err = 0)
|
||||
ValueType RadToGrad(const ValueType & x, ErrorCode * err = 0)
|
||||
ValueType DegToGrad(const ValueType & x, ErrorCode * err = 0)
|
||||
ValueType DegToGrad(const ValueType & d, const ValueType & m,
|
||||
const ValueType & s, ErrorCode * err = 0)
|
||||
ValueType GradToDeg(const ValueType & x, ErrorCode * err = 0)
|
||||
* added: Parser::SetDegRadGrad(int angle) - 0 deg, 1 rad (default), 2 grad
|
||||
this affects following functions (in the parser only): sin, cos, tan, cot,
|
||||
asin, acos, atan, acot
|
||||
* added: functions to the parser: gradtorad(grad), radtograd(rad), degtograd(deg),
|
||||
degtograd(d,m,s), gradtodeg(grad)
|
||||
* added: UInt::FromString, added a parametr 'after_source'
|
||||
which is pointing at the end of the parsed string
|
||||
* added: Int::FromString(): parameter 'const char ** after_source = 0'
|
||||
if exists it's pointing at the end of the parsed string
|
||||
* added: to UInt::FromString(), Int::FromString(), Big::FromString():
|
||||
parameter 'bool * value_read = 0' - (if exists) tells
|
||||
whether something has actually been read (at least one digit)
|
||||
* added: Objects::IsDefined(const std::string & name)
|
||||
returning true if such an object is defined
|
||||
* removed: Big::FromString() this method doesn't longer recognize operators
|
||||
for changing the base ('#' and '&')
|
||||
|
||||
|
||||
Version 0.8.2 (2008.06.18):
|
||||
* added: UInt::BitNot2() this method has been proposed by
|
||||
Arek <kmicicc AnTispam users.sourceforge.net>
|
||||
* changed: Int::FromInt(const Int<argument_size> & p),
|
||||
Int::FromInt(sint value) (it returns zero now)
|
||||
Int::operator=(uint i)
|
||||
Int::Int(uint i)
|
||||
* added: Int::FromUInt(const UInt<argument_size> & p),
|
||||
Int::FromUInt(uint value)
|
||||
and appropriate constructors and assignment
|
||||
operators as well
|
||||
* changed: Big::FromInt(Int<int_size> value),
|
||||
* added: Big::FromUInt(UInt<int_size> value),
|
||||
Big::operator=(const UInt<int_size> & value)
|
||||
Big::Big(const UInt<int_size> & value)
|
||||
* changed: the parser is allowed to recognize values which
|
||||
begin with a dot, e.g '.5' is treated as '0.5'
|
||||
* added: a method Big::FromDouble(double) which converts from
|
||||
standard double into a Big
|
||||
* added: uint Big::ToDouble(double&) - converting into double
|
||||
* added: Big::FromBig() and an operator= and a contructor
|
||||
for converting from another kind of a Big class
|
||||
* added: to the parser: avg(), sum()
|
||||
* added: 'decimal_point' parameter into Big::ToString(...)
|
||||
* fixed: Big::operator>> didn't use TTMATH_COMMA_CHARACTER_2 macro
|
||||
* added: a short form of multiplication (without the '*' character)
|
||||
e.g. '5y', (it's used only if the second parameter
|
||||
is a variable or function)
|
||||
* changed: variables and functions are case-sensitive now
|
||||
* added: variables and functions can have underline characters
|
||||
in their names
|
||||
* changed: 'max_digit_after_comma' in Big::ToString()
|
||||
remove the -2 state
|
||||
* added: 'remove_trailing_zeroes' in Big::ToString()
|
||||
it's either true or false
|
||||
* fixed/changed: the way of using Big::SetSign()
|
||||
the method do not check whether there is a zero or not now
|
||||
(even if there's a zero the method can set a sign bit)
|
||||
I changed this due to some prior errors
|
||||
(errors corrected in revision 17, 49 and 58)
|
||||
|
||||
|
||||
Version 0.8.1 (2007.04.17):
|
||||
* fixed: Big::PowFrac(..) didn't return a correct error code
|
||||
(when 'this' was negative)
|
||||
* added: Root(x; index) (and to the parser as well)
|
||||
* added: macro: TTMATH_PRERELEASE_VER (can be either zero or one)
|
||||
* added: UInt::MulInt(int, UInt<int another_size>::&)
|
||||
* added: Big::MulUInt(uint)
|
||||
* changed: Big::MulInt(sint)
|
||||
* added: Big::ToUInt(uint &)
|
||||
* changed: Big::ToInt(sint&)
|
||||
* changed: Factorial() it uses Big::MulUInt() at the beginning
|
||||
(faster now especially more on a 32bit platform)
|
||||
* added: doxygen.cfg for generating a documentation from the doxygen
|
||||
* changed: UInt::Rcl(uint c=0) and UInt::Rcr(uint c=0) into
|
||||
UInt::Rcl2(uint bits, uint c) and UInt::Rcr2(uint bits, uint c)
|
||||
now they can move more than one bit and they are only private
|
||||
* fixed: UInt::Rcl(uint bits, uint c) and UInt::Rcr(uint bits, uint c)
|
||||
didn't correctly return a carry if the 'bits' were equal
|
||||
to 'value_size*TTMATH_BITS_PER_UINT'
|
||||
* changed: UInt::Rcl(uint bits, uint c) and UInt::Rcr(uint bits, uint c)
|
||||
into UInt::Rcl(uint bits, uint c=0) and
|
||||
UInt::Rcr(uint bits, uint c=0)
|
||||
they are faster now when the bits is greater than a half of
|
||||
the TTMATH_BITS_PER_UINT
|
||||
* changed: UInt::CompensationToLeft() it's faster now
|
||||
* changed: more small changes where there were UInt::Rcl(uint c=0) and
|
||||
UInt::Rcr(uint c=0) used
|
||||
* changed: as the Big type uses UInt::Rcl() and UInt::Rcr() a lot then
|
||||
it is much faster now (about 5-25%)
|
||||
* added: ASinh(), ACosh(), ATanh() /ATgh()/, ACoth() /ACtgh()/
|
||||
and to the parser as well
|
||||
* added: UInt::BitAnd(), UInt::BitOr(), UInt::BitXor(), UInt::BitNot(),
|
||||
Big::BitAnd(), Big::BitOr(), Big::BitXor()
|
||||
* added: to the parser: bitand(), bitor(), bitxor()
|
||||
/band(), bor(), bxor()/
|
||||
* changed: the way of parsing operators in the mathematical parser
|
||||
(the parser is not too much greedy now)
|
||||
|
||||
|
||||
Version 0.8.0 (2007.03.28):
|
||||
* added: into the parser: SetFactorialMax()
|
||||
* added: DegToDeg(deg, min, sec), DegToRad(deg), DegToRad(deg, min, sec),
|
||||
RadToDeg(rad), Ceil(x), Floor(x), Sqrt(x), Sinh(x), Cosh(x),
|
||||
Tanh(x) /Tgh(x)/, Coth(x) /Ctgh(x)/
|
||||
* changed: class Objects in ttmathobjects.h has been completely rewritten,
|
||||
we can change the names of user-defined variables or functions,
|
||||
and the names are case-sensitive now
|
||||
* added: class History which is used in functions which take a lot of time
|
||||
during calculating e.g. Factorial(x)
|
||||
* added: Tg(x) a wrapper for Tan(x)
|
||||
* changed: CTan(x) is Cot(x) now
|
||||
* added: Ctg(x) a wrapper for Cot(x)
|
||||
* added: ATg(x) a wrapper for ATan(x)
|
||||
* changed: ACTan(x) is ACot(x) now
|
||||
* added: ACtg(x) a wrapper for ACot(x)
|
||||
* added: UInt::PrintTable() (for debugging etc.)
|
||||
* changed: the methods Big::SetPi() Big::SetE() and Big::SetLn2() have
|
||||
been rewritten, now they have 128 32bit words (it's about
|
||||
1232 valid decimal digits)
|
||||
* fixed: previous values from Big::SetPi() Big::SetE() and
|
||||
Big::SetLn2() were not too much accurate (last 2-3 words were wrong)
|
||||
* added: Big::SetLn10() (128 32bit words as well)
|
||||
* added: macro TTMATH_BUILTIN_VARIABLES_SIZE which is equal 128u on
|
||||
32bit platforms and 64ul on 64bit platforms (128/2=64)
|
||||
* added: macros TTMATH_PLATFORM32 and TTMATH_PLATFORM64
|
||||
* changed: a small optimisation in UInt::Mul2Big()
|
||||
* added: at the end of ttmath.h: #include "ttmathparser.h"
|
||||
this is for convenience for a programmer, he can only use #include
|
||||
with ttmath.h even if he uses the parser
|
||||
* added: to samples: big.cpp, parser.cpp
|
||||
* added/changes/fixed: in copy-constructors and operators= in Int,
|
||||
Uint and Big (more info in the commit log)
|
||||
* renamed: Big::SetDotOne() into Big::Set05()
|
||||
* changes: a few small optimisations in Big
|
||||
* deleted: the word 'virtual' from destructors: UInt, Int, Big
|
||||
(types in this library are not projected to be base-classes for
|
||||
another ones derived from them)
|
||||
* and more small changes (look at the commit log)
|
||||
|
||||
|
||||
Version 0.7.2 (2007.03.09):
|
||||
* added: Big::Mod - the remainder from a division
|
||||
* added: Big::Sgn - the 'sign' from the value (-1,0,1)
|
||||
* added: global functions Mod and Sgn too
|
||||
* added: checking whether a user gives a correct value of a variable or function
|
||||
(user-defined variables/functions in the mathematical parser)
|
||||
* added: into the parser: logical operators: > < >= <= == != && ||
|
||||
* added: into the parser: logical functions: and() or() not() if()
|
||||
* added: ErrorCode::err_unknown_operator when the parser couldn't read an operator
|
||||
|
||||
|
||||
Version 0.7.1 (2007.02.27):
|
||||
* fixed: the error 'overflow during printing' which was caused
|
||||
by Big::FromInt(Int<int_size> value) (the sign has to be set at the end)
|
||||
* fixed: many small errors
|
||||
* added: ATan (arctan), ACTan (arc ctan) functions
|
||||
|
||||
|
||||
Version 0.7.0 (2007.02.24):
|
||||
* finished: support for 64bit platforms
|
||||
* added: ASin (arcsin), ACos (arccos) functions
|
||||
|
||||
|
||||
Version 0.6.4 (2007.01.29):
|
||||
* fixed: the problem with a sign in the mathematical parser /-(1) was 1/
|
||||
* added: UInt::AddInt and UInt::SubInt
|
||||
* changed: UInt::AddOne and UInt::SubOne (much faster now)
|
||||
* added: UInt::SetBitInWord
|
||||
* changed: UInt::SetBit (much faster now)
|
||||
UInt::AddTwoUints renamed to UInt::AddTwoInts
|
||||
UInt::FindLeadingBit32 renamed to UInt::FindLeadingBitInWord
|
||||
UInt::Mul64 renamed to UInt::MulTwoWords
|
||||
UInt::Div64 renamed to UInt::DivTwoWords
|
||||
* added: UInt::SetBitInWord
|
||||
* and more small changes in UInt type
|
||||
* start adding support for Amd64 (not finished yet) (added ttmathuint64.h)
|
||||
|
||||
|
||||
Version 0.6.3 (2007.01.22):
|
||||
* changed: position of arguments (x and base) in logarithm functions are swapped
|
||||
* changed: it's possible to use any multiplication algorithms in the same time
|
||||
(macros UINT_MUL_VERSION_'X' have gone)
|
||||
* added: ExceptionInfo, ReferenceError and RuntimeError classes
|
||||
* changed: the mess in macros has been cleaned up
|
||||
* added: TTMATH_RELEASE macro
|
||||
|
||||
|
||||
Version 0.6.2 (2007.01.10):
|
||||
* added: New division algorithm (radix b) where b is 2^32
|
28
3rd_party/ttmath-0.9.3/COPYRIGHT
vendored
Normal file
28
3rd_party/ttmath-0.9.3/COPYRIGHT
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
Copyright (c) 2006-2012, Tomasz Sowa
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
project may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
THE POSSIBILITY OF SUCH DAMAGE.
|
23
3rd_party/ttmath-0.9.3/README
vendored
Normal file
23
3rd_party/ttmath-0.9.3/README
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
A bignum library for C++
|
||||
|
||||
TTMath is a small library which allows one to perform arithmetic operations
|
||||
with big unsigned integer, big signed integer and big floating point numbers.
|
||||
It provides standard mathematical operations like adding, subtracting,
|
||||
multiplying, dividing. With the library also goes a mathematical parser to
|
||||
help you solving mathematical expressions.
|
||||
|
||||
TTMath is developed under the BSD licence which means that it is free for
|
||||
both personal and commercial use.
|
||||
|
||||
The main goal of the library is to allow one to use big values in the same
|
||||
way as the standard types like int or float. It does not need to be compiled
|
||||
first because the whole library is written as the C++ templates. This means
|
||||
only C++ developers can use this library and one thing they have to do is
|
||||
to use 'include' directive of the preprocessor. How big the values can be
|
||||
is set at compile time.
|
||||
|
||||
Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
WWW: http://www.ttmath.org
|
||||
|
||||
Contributors:
|
||||
Christian Kaiser <chk@online.de>
|
46
3rd_party/ttmath-0.9.3/samples/Makefile
vendored
Normal file
46
3rd_party/ttmath-0.9.3/samples/Makefile
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
CC = g++
|
||||
CFLAGS = -Wall -pedantic -s -O2 -I.. -DTTMATH_DONT_USE_WCHAR
|
||||
|
||||
|
||||
.SUFFIXES: .cpp .o
|
||||
|
||||
.cpp.o:
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
|
||||
|
||||
all: uint int big big2 parser
|
||||
|
||||
|
||||
uint: uint.o
|
||||
$(CC) -o uint $(CFLAGS) uint.o
|
||||
|
||||
int: int.o
|
||||
$(CC) -o int $(CFLAGS) int.o
|
||||
|
||||
big: big.o
|
||||
$(CC) -o big $(CFLAGS) big.o
|
||||
|
||||
big2: big2.o
|
||||
$(CC) -o big2 $(CFLAGS) big2.o
|
||||
|
||||
parser: parser.o
|
||||
$(CC) -o parser $(CFLAGS) parser.o
|
||||
|
||||
|
||||
uint.o: uint.cpp
|
||||
int.o: int.cpp
|
||||
big.o: big.cpp
|
||||
big2.o: big2.cpp
|
||||
parser.o: parser.cpp
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f *.s
|
||||
rm -f uint
|
||||
rm -f int
|
||||
rm -f big
|
||||
rm -f big2
|
||||
rm -f parser
|
||||
# on MS Windows can automatically be added suffixes .exe to the names of output programs
|
||||
rm -f *.exe
|
100
3rd_party/ttmath-0.9.3/samples/big.cpp
vendored
Normal file
100
3rd_party/ttmath-0.9.3/samples/big.cpp
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
#include <ttmath/ttmath.h>
|
||||
#include <iostream>
|
||||
|
||||
// for convenience we're defining MyBig type
|
||||
// this type has 2 words for its mantissa and 1 word for its exponent
|
||||
// (on a 32bit platform one word means a word of 32 bits,
|
||||
// and on a 64bit platform one word means a word of 64 bits)
|
||||
|
||||
// Big<exponent, mantissa>
|
||||
typedef ttmath::Big<1,2> MyBig;
|
||||
|
||||
|
||||
void SimpleCalculating(const MyBig & a, const MyBig & b)
|
||||
{
|
||||
std::cout << "Simple calculating" << std::endl;
|
||||
std::cout << "a = " << a << std::endl;
|
||||
std::cout << "b = " << b << std::endl;
|
||||
std::cout << "a + b = " << a+b << std::endl;
|
||||
std::cout << "a - b = " << a-b << std::endl;
|
||||
std::cout << "a * b = " << a*b << std::endl;
|
||||
std::cout << "a / b = " << a/b << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void CalculatingWithCarry(const MyBig & a, const MyBig & b)
|
||||
{
|
||||
MyBig atemp;
|
||||
|
||||
std::cout << "Calculating with a carry" << std::endl;
|
||||
std::cout << "a = " << a << std::endl;
|
||||
std::cout << "b = " << b << std::endl;
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Add(b) )
|
||||
std::cout << "a + b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a + b = (carry)" << std::endl;
|
||||
// it have no sense to print 'atemp' (it's undefined)
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Sub(b) )
|
||||
std::cout << "a - b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a - b = (carry)" << std::endl;
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Mul(b) )
|
||||
std::cout << "a * b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a * b = (carry)" << std::endl;
|
||||
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Div(b) )
|
||||
std::cout << "a / b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a / b = (carry or division by zero) " << std::endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
MyBig a,b;
|
||||
|
||||
// conversion from 'const char *'
|
||||
a = "123456.543456";
|
||||
b = "98767878.124322";
|
||||
|
||||
SimpleCalculating(a,b);
|
||||
|
||||
// 'a' will have the max value which can be held in this type
|
||||
a.SetMax();
|
||||
|
||||
// conversion from double
|
||||
b = 456.32;
|
||||
|
||||
// Look at the value 'a' and the product from a+b and a-b
|
||||
// Don't worry this is the nature of floating point numbers
|
||||
CalculatingWithCarry(a,b);
|
||||
}
|
||||
|
||||
/*
|
||||
the result (on 32 bit platform):
|
||||
|
||||
Simple calculating
|
||||
a = 123456.543456
|
||||
b = 98767878.124322
|
||||
a + b = 98891334.667778
|
||||
a - b = -98644421.580866
|
||||
a * b = 12193540837712.27076
|
||||
a / b = 0.00124996654580957646
|
||||
Calculating with a carry
|
||||
a = 1.6248012560666408782e+646457012
|
||||
b = 456.319999999999993
|
||||
a + b = 1.6248012560666408782e+646457012
|
||||
a - b = 1.6248012560666408782e+646457012
|
||||
a * b = (carry)
|
||||
a / b = 3.560661939136222174e+646457009
|
||||
*/
|
113
3rd_party/ttmath-0.9.3/samples/big2.cpp
vendored
Normal file
113
3rd_party/ttmath-0.9.3/samples/big2.cpp
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
#include <ttmath/ttmath.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
// this is a similar example to big.cpp
|
||||
// but now we're using TTMATH_BITS() macro
|
||||
// this macro returns how many words we need to store
|
||||
// the given number of bits
|
||||
|
||||
// TTMATH_BITS(64)
|
||||
// on a 32bit platform the macro returns 2 (2*32=64)
|
||||
// on a 64bit platform the macro returns 1
|
||||
|
||||
// TTMATH_BITS(128)
|
||||
// on a 32bit platform the macro returns 4 (4*32=128)
|
||||
// on a 64bit platform the macro returns 2 (2*64=128)
|
||||
|
||||
// Big<exponent, mantissa>
|
||||
typedef ttmath::Big<TTMATH_BITS(64), TTMATH_BITS(128)> MyBig;
|
||||
|
||||
// consequently on a 32bit platform we define: Big<2, 4>
|
||||
// and on a 64bit platform: Big<1, 2>
|
||||
// and the calculations will be the same on both platforms
|
||||
|
||||
|
||||
void SimpleCalculating(const MyBig & a, const MyBig & b)
|
||||
{
|
||||
std::cout << "Simple calculating" << std::endl;
|
||||
std::cout << "a = " << a << std::endl;
|
||||
std::cout << "b = " << b << std::endl;
|
||||
std::cout << "a + b = " << a+b << std::endl;
|
||||
std::cout << "a - b = " << a-b << std::endl;
|
||||
std::cout << "a * b = " << a*b << std::endl;
|
||||
std::cout << "a / b = " << a/b << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void CalculatingWithCarry(const MyBig & a, const MyBig & b)
|
||||
{
|
||||
MyBig atemp;
|
||||
|
||||
std::cout << "Calculating with a carry" << std::endl;
|
||||
std::cout << "a = " << a << std::endl;
|
||||
std::cout << "b = " << b << std::endl;
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Add(b) )
|
||||
std::cout << "a + b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a + b = (carry)" << std::endl;
|
||||
// it have no sense to print 'atemp' (it's undefined)
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Sub(b) )
|
||||
std::cout << "a - b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a - b = (carry)" << std::endl;
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Mul(b) )
|
||||
std::cout << "a * b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a * b = (carry)" << std::endl;
|
||||
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Div(b) )
|
||||
std::cout << "a / b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a / b = (carry or division by zero) " << std::endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
MyBig a,b;
|
||||
|
||||
// conversion from 'const char *'
|
||||
a = "123456.543456";
|
||||
b = "98767878.124322";
|
||||
|
||||
SimpleCalculating(a,b);
|
||||
|
||||
// 'a' will have the max value which can be held in this type
|
||||
a.SetMax();
|
||||
|
||||
// conversion from double
|
||||
b = 456.32;
|
||||
|
||||
// Look at the value 'a' and the product from a+b and a-b
|
||||
// Don't worry this is the nature of floating point numbers
|
||||
CalculatingWithCarry(a,b);
|
||||
}
|
||||
|
||||
/*
|
||||
the result (the same on a 32 or 64bit platform):
|
||||
|
||||
Simple calculating
|
||||
a = 123456.543456
|
||||
b = 98767878.124322
|
||||
a + b = 98891334.667778
|
||||
a - b = -98644421.580866
|
||||
a * b = 12193540837712.270763536832
|
||||
a / b = 0.0012499665458095764605964485261668609133
|
||||
Calculating with a carry
|
||||
a = 2.34953455457111777368832820909595050034e+2776511644261678604
|
||||
b = 456.3199999999999931787897367030382156
|
||||
a + b = 2.34953455457111777368832820909595050034e+2776511644261678604
|
||||
a - b = 2.34953455457111777368832820909595050034e+2776511644261678604
|
||||
a * b = (carry)
|
||||
a / b = 5.1488748127873374141170361292780486452e+2776511644261678601
|
||||
*/
|
92
3rd_party/ttmath-0.9.3/samples/int.cpp
vendored
Normal file
92
3rd_party/ttmath-0.9.3/samples/int.cpp
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
#include <ttmath/ttmath.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
void SimpleCalculating(const ttmath::Int<2> & a, const ttmath::Int<2> & b)
|
||||
{
|
||||
std::cout << "Simple calculating" << std::endl;
|
||||
std::cout << "a = " << a << std::endl;
|
||||
std::cout << "b = " << b << std::endl;
|
||||
std::cout << "a + b = " << a+b << std::endl;
|
||||
std::cout << "a - b = " << a-b << std::endl;
|
||||
std::cout << "a * b = " << a*b << std::endl;
|
||||
std::cout << "a / b = " << a/b << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void CalculatingWithCarry(const ttmath::Int<2> & a, const ttmath::Int<2> & b)
|
||||
{
|
||||
ttmath::Int<2> atemp;
|
||||
|
||||
std::cout << "Calculating with a carry" << std::endl;
|
||||
std::cout << "a = " << a << std::endl;
|
||||
std::cout << "b = " << b << std::endl;
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Add(b) )
|
||||
std::cout << "a + b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a + b = (carry) " << atemp << std::endl;
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Sub(b) )
|
||||
std::cout << "a - b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a - b = (carry) " << atemp << std::endl;
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Mul(b) )
|
||||
std::cout << "a * b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a * b = (carry: the result is too big) " << std::endl;
|
||||
// it have no sense to print 'atemp' (it's undefined)
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Div(b) )
|
||||
std::cout << "a / b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a / b = (division by zero) " << std::endl;
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// on 32bit platforms: 'a' and 'b' have 2-words (two 32bit words)
|
||||
// it means a,b are from <-2^63, 2^63 - 1>
|
||||
ttmath::Int<2> a,b;
|
||||
|
||||
// conversion from int
|
||||
a = 123456;
|
||||
|
||||
// conversion from 'const char *'
|
||||
b = "98767878";
|
||||
|
||||
SimpleCalculating(a,b);
|
||||
|
||||
// 'a' will have the max value which can be held in this type
|
||||
a.SetMax();
|
||||
|
||||
// conversion from 'int'
|
||||
b = 10;
|
||||
|
||||
CalculatingWithCarry(a,b);
|
||||
}
|
||||
|
||||
/*
|
||||
the result (on 32 bit platform):
|
||||
|
||||
Simple calculating
|
||||
a = 123456
|
||||
b = 98767878
|
||||
a + b = 98891334
|
||||
a - b = -98644422
|
||||
a * b = 12193487146368
|
||||
a / b = 0
|
||||
Calculating with a carry
|
||||
a = 9223372036854775807
|
||||
b = 10
|
||||
a + b = (carry) -9223372036854775799
|
||||
a - b = 9223372036854775797
|
||||
a * b = (carry) the result is too big)
|
||||
a / b = 922337203685477580
|
||||
*/
|
39
3rd_party/ttmath-0.9.3/samples/parser.cpp
vendored
Normal file
39
3rd_party/ttmath-0.9.3/samples/parser.cpp
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <ttmath/ttmath.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
// for convenience we're defining MyBig type
|
||||
// this type has 2 words for its mantissa and 1 word for its exponent
|
||||
// (on a 32bit platform one word means a word of 32 bits,
|
||||
// and on a 64bit platform one word means a word of 64 bits)
|
||||
typedef ttmath::Big<1,2> MyBig;
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
ttmath::Parser<MyBig> parser;
|
||||
|
||||
// the sine function takes its parameter as being in radians,
|
||||
// the product from the arcus tangent will be in radians as well
|
||||
const char equation[] = " (34 + 24) * 123 - 34.32 ^ 6 * sin(2.56) - atan(10)";
|
||||
|
||||
ttmath::ErrorCode err = parser.Parse(equation);
|
||||
|
||||
if( err == ttmath::err_ok )
|
||||
std::cout << parser.stack[0].value << std::endl;
|
||||
else
|
||||
std::cout << "Error: "
|
||||
<< static_cast<int>(err)
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
/*
|
||||
the result (on 32 bit platform):
|
||||
-897705014.525731067
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
the result (on 64 bit platform):
|
||||
-897705014.5257310676097719585259773124
|
||||
*/
|
93
3rd_party/ttmath-0.9.3/samples/uint.cpp
vendored
Normal file
93
3rd_party/ttmath-0.9.3/samples/uint.cpp
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
#include <ttmath/ttmath.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
void SimpleCalculating(const ttmath::UInt<2> & a, const ttmath::UInt<2> & b)
|
||||
{
|
||||
std::cout << "Simple calculating" << std::endl;
|
||||
std::cout << "a = " << a << std::endl;
|
||||
std::cout << "b = " << b << std::endl;
|
||||
std::cout << "a + b = " << a+b << std::endl;
|
||||
std::cout << "a - b = " << a-b << std::endl;
|
||||
std::cout << "a * b = " << a*b << std::endl;
|
||||
std::cout << "a / b = " << a/b << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void CalculatingWithCarry(const ttmath::UInt<2> & a, const ttmath::UInt<2> & b)
|
||||
{
|
||||
ttmath::UInt<2> atemp;
|
||||
|
||||
std::cout << "Calculating with a carry" << std::endl;
|
||||
std::cout << "a = " << a << std::endl;
|
||||
std::cout << "b = " << b << std::endl;
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Add(b) )
|
||||
std::cout << "a + b = " << atemp << std::endl;
|
||||
else
|
||||
// if there was a carry then atemp.Add(...) would have returned 1
|
||||
std::cout << "a + b = (carry: the result is too big) " << atemp << std::endl;
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Sub(b) )
|
||||
std::cout << "a - b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a - b = (carry: 'a' was smaller than 'b') " << atemp << std::endl;
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Mul(b) )
|
||||
std::cout << "a * b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a * b = (carry: the result is too big) " << std::endl;
|
||||
// it have no sense to print 'atemp' (it's undefined)
|
||||
|
||||
atemp = a;
|
||||
if( !atemp.Div(b) )
|
||||
std::cout << "a / b = " << atemp << std::endl;
|
||||
else
|
||||
std::cout << "a / b = (division by zero) " << std::endl;
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// on 32bit platforms: 'a' and 'b' have 2-words (two 32bit words)
|
||||
// it means a,b are from <0, 2^64 - 1>
|
||||
ttmath::UInt<2> a,b;
|
||||
|
||||
// conversion from 'const char *'
|
||||
a = "123456";
|
||||
|
||||
// conversion from int
|
||||
b = 9876;
|
||||
|
||||
SimpleCalculating(a,b);
|
||||
|
||||
// 'a' will have the max value which can be held in this type
|
||||
a.SetMax();
|
||||
|
||||
// conversion from 'int'
|
||||
b = 5;
|
||||
|
||||
CalculatingWithCarry(a,b);
|
||||
}
|
||||
|
||||
/*
|
||||
the result (on 32 bit platform):
|
||||
|
||||
Simple calculating
|
||||
a = 123456
|
||||
b = 9876
|
||||
a + b = 133332
|
||||
a - b = 113580
|
||||
a * b = 1219251456
|
||||
a / b = 12
|
||||
Calculating with a carry
|
||||
a = 18446744073709551615
|
||||
b = 5
|
||||
a + b = (carry: the result is too big) 4
|
||||
a - b = 18446744073709551610
|
||||
a * b = (carry: the result is too big)
|
||||
a / b = 3689348814741910323
|
||||
*/
|
2853
3rd_party/ttmath-0.9.3/ttmath/ttmath.h
vendored
Normal file
2853
3rd_party/ttmath-0.9.3/ttmath/ttmath.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
6045
3rd_party/ttmath-0.9.3/ttmath/ttmathbig.h
vendored
Normal file
6045
3rd_party/ttmath-0.9.3/ttmath/ttmathbig.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
419
3rd_party/ttmath-0.9.3/ttmath/ttmathdec.h
vendored
Normal file
419
3rd_party/ttmath-0.9.3/ttmath/ttmathdec.h
vendored
Normal file
@@ -0,0 +1,419 @@
|
||||
/*
|
||||
* This file is a part of TTMath Bignum Library
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef headerfilettmathdec
|
||||
#define headerfilettmathdec
|
||||
|
||||
#include "ttmathtypes.h"
|
||||
#include "ttmaththreads.h"
|
||||
#include "ttmathuint.h"
|
||||
|
||||
|
||||
|
||||
namespace ttmath
|
||||
{
|
||||
|
||||
template<uint value_size, uint dec_digits>
|
||||
class Dec
|
||||
{
|
||||
public:
|
||||
|
||||
UInt<value_size> value;
|
||||
unsigned char info;
|
||||
|
||||
|
||||
/*!
|
||||
Sign
|
||||
the mask of a bit from 'info' which means that there is a sign
|
||||
(when the bit is set)
|
||||
*/
|
||||
#define TTMATH_DEC_SIGN 128
|
||||
|
||||
|
||||
/*!
|
||||
Not a number
|
||||
if this bit is set that there is not a valid number
|
||||
*/
|
||||
#define TTMATH_DEC_NAN 64
|
||||
|
||||
|
||||
|
||||
|
||||
Dec()
|
||||
{
|
||||
info = TTMATH_DEC_NAN;
|
||||
}
|
||||
|
||||
|
||||
Dec(const char * s)
|
||||
{
|
||||
info = TTMATH_DEC_NAN;
|
||||
FromString(s);
|
||||
}
|
||||
|
||||
|
||||
Dec<value_size, dec_digits> & operator=(const char * s)
|
||||
{
|
||||
FromString(s);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
uint FromString(const char * s, const char ** after_source = 0, bool * value_read = 0)
|
||||
{
|
||||
return FromStringBase(s, after_source, value_read);
|
||||
}
|
||||
|
||||
|
||||
void ToString(std::string & result) const
|
||||
{
|
||||
ToStringBase(result);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
this method clears a specific bit in the 'info' variable
|
||||
|
||||
bit is one of:
|
||||
*/
|
||||
void ClearInfoBit(unsigned char bit)
|
||||
{
|
||||
info = info & (~bit);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
this method sets a specific bit in the 'info' variable
|
||||
|
||||
bit is one of:
|
||||
|
||||
*/
|
||||
void SetInfoBit(unsigned char bit)
|
||||
{
|
||||
info = info | bit;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
this method returns true if a specific bit in the 'info' variable is set
|
||||
|
||||
bit is one of:
|
||||
*/
|
||||
bool IsInfoBit(unsigned char bit) const
|
||||
{
|
||||
return (info & bit) != 0;
|
||||
}
|
||||
|
||||
|
||||
bool IsNan() const
|
||||
{
|
||||
return IsInfoBit(TTMATH_DEC_NAN);
|
||||
}
|
||||
|
||||
|
||||
bool IsSign() const
|
||||
{
|
||||
return IsInfoBit(TTMATH_DEC_SIGN);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
this method sets the sign
|
||||
|
||||
e.g.
|
||||
-1 -> -1
|
||||
2 -> -2
|
||||
|
||||
we do not check whether there is a zero or not, if you're using this method
|
||||
you must be sure that the value is (or will be afterwards) different from zero
|
||||
*/
|
||||
void SetSign()
|
||||
{
|
||||
SetInfoBit(TTMATH_DEC_SIGN);
|
||||
}
|
||||
|
||||
|
||||
void SetNaN()
|
||||
{
|
||||
SetInfoBit(TTMATH_DEC_NAN);
|
||||
}
|
||||
|
||||
|
||||
void Abs()
|
||||
{
|
||||
ClearInfoBit(TTMATH_DEC_SIGN);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint Add(const Dec<value_size, dec_digits> & arg)
|
||||
{
|
||||
uint c = 0;
|
||||
|
||||
if( IsSign() == arg.IsSign() )
|
||||
{
|
||||
c += value.Add(arg.value);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool is_sign;
|
||||
|
||||
if( value > arg.value )
|
||||
{
|
||||
is_sign = IsSign();
|
||||
value.Sub(arg.value);
|
||||
}
|
||||
else
|
||||
{
|
||||
is_sign = arg.IsSign();
|
||||
UInt<value_size> temp(this->value);
|
||||
value = arg.value;
|
||||
value.Sub(temp);
|
||||
}
|
||||
|
||||
is_sign ? SetSign() : Abs();
|
||||
}
|
||||
|
||||
if( c )
|
||||
SetNaN();
|
||||
|
||||
return (c==0)? 0 : 1;
|
||||
}
|
||||
|
||||
/*
|
||||
uint Sub(const Dec<value_size, dec_digits> & arg)
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef TTMATH_MULTITHREADS
|
||||
|
||||
/*!
|
||||
*/
|
||||
void SetMultipler(UInt<value_size> & result)
|
||||
{
|
||||
// this guardian is initialized before the program runs (static POD type)
|
||||
static int guardian = 0;
|
||||
static UInt<value_size> multipler;
|
||||
|
||||
if( guardian == 0 )
|
||||
{
|
||||
multipler = 10;
|
||||
multipler.Pow(dec_digits);
|
||||
guardian = 1;
|
||||
}
|
||||
|
||||
result = multipler;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/*!
|
||||
*/
|
||||
void SetMultipler(UInt<value_size> & result)
|
||||
{
|
||||
// this guardian is initialized before the program runs (static POD type)
|
||||
volatile static sig_atomic_t guardian = 0;
|
||||
static UInt<value_size> * pmultipler;
|
||||
|
||||
// double-checked locking
|
||||
if( guardian == 0 )
|
||||
{
|
||||
ThreadLock thread_lock;
|
||||
|
||||
// locking
|
||||
if( thread_lock.Lock() )
|
||||
{
|
||||
static UInt<value_size> multipler;
|
||||
|
||||
if( guardian == 0 )
|
||||
{
|
||||
pmultipler = &multipler;
|
||||
multipler = 10;
|
||||
multipler.Pow(dec_digits);
|
||||
guardian = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// there was a problem with locking, we store the result directly in 'result' object
|
||||
result = 10;
|
||||
result.Pow(dec_digits);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// automatically unlocking
|
||||
}
|
||||
|
||||
result = *pmultipler;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
an auxiliary method for converting from a string
|
||||
*/
|
||||
template<class char_type>
|
||||
uint FromStringBase(const char_type * s, const char_type ** after_source = 0, bool * value_read = 0)
|
||||
{
|
||||
UInt<value_size> multipler;
|
||||
const char_type * after;
|
||||
uint c = 0;
|
||||
info = 0;
|
||||
|
||||
Misc::SkipWhiteCharacters(s);
|
||||
|
||||
if( *s == '-' )
|
||||
{
|
||||
s += 1;
|
||||
SetSign();
|
||||
}
|
||||
else
|
||||
if( *s == '+' )
|
||||
{
|
||||
s += 1;
|
||||
}
|
||||
|
||||
c += value.FromString(s, 10, &after, value_read);
|
||||
|
||||
if( after_source )
|
||||
*after_source = after;
|
||||
|
||||
SetMultipler(multipler);
|
||||
c += value.Mul(multipler);
|
||||
|
||||
if( *after == '.' )
|
||||
c += FromStringBaseAfterComma(after+1, after_source);
|
||||
|
||||
if( c )
|
||||
SetInfoBit(TTMATH_DEC_NAN);
|
||||
|
||||
return (c==0)? 0 : 1;
|
||||
}
|
||||
|
||||
|
||||
template<class char_type>
|
||||
uint FromStringBaseAfterComma(const char_type * s, const char_type ** after_source = 0, bool * value_read = 0)
|
||||
{
|
||||
UInt<value_size> temp;
|
||||
UInt<value_size> multipler;
|
||||
sint z;
|
||||
uint c = 0;
|
||||
size_t i = dec_digits;
|
||||
|
||||
SetMultipler(multipler);
|
||||
|
||||
for( ; i>0 && (z=Misc::CharToDigit(*s, 10)) != -1 ; --i, ++s )
|
||||
{
|
||||
multipler.DivInt(10);
|
||||
temp.SetZero();
|
||||
|
||||
if( value_read )
|
||||
*value_read = true;
|
||||
|
||||
if( c == 0 )
|
||||
{
|
||||
temp.table[0] = z;
|
||||
c += temp.Mul(multipler);
|
||||
c += value.Add(temp);
|
||||
}
|
||||
}
|
||||
|
||||
if( i == 0 && (z=Misc::CharToDigit(*s, 10)) != -1 && z >= 5 )
|
||||
c += value.AddOne();
|
||||
|
||||
if( after_source )
|
||||
{
|
||||
while( (z=Misc::CharToDigit(*s, 10)) != -1 )
|
||||
s += 1;
|
||||
|
||||
*after_source = s;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class string_type>
|
||||
void ToStringBase(string_type & result) const
|
||||
{
|
||||
if( IsNan() )
|
||||
{
|
||||
result = "NaN";
|
||||
return;
|
||||
}
|
||||
|
||||
value.ToStringBase(result, 10, IsSign());
|
||||
|
||||
if( dec_digits > 0 )
|
||||
{
|
||||
size_t size = result.size();
|
||||
|
||||
if( IsSign() && size > 0 )
|
||||
size -= 1;
|
||||
|
||||
if( dec_digits >= size )
|
||||
{
|
||||
size_t zeroes = dec_digits - size + 1;
|
||||
size_t start = IsSign() ? 1 : 0;
|
||||
result.insert(start, zeroes, '0');
|
||||
}
|
||||
|
||||
result.insert(result.end() - dec_digits, '.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
1922
3rd_party/ttmath-0.9.3/ttmath/ttmathint.h
vendored
Normal file
1922
3rd_party/ttmath-0.9.3/ttmath/ttmathint.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
250
3rd_party/ttmath-0.9.3/ttmath/ttmathmisc.h
vendored
Normal file
250
3rd_party/ttmath-0.9.3/ttmath/ttmathmisc.h
vendored
Normal file
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
* This file is a part of TTMath Bignum Library
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef headerfilettmathmisc
|
||||
#define headerfilettmathmisc
|
||||
|
||||
|
||||
/*!
|
||||
\file ttmathmisc.h
|
||||
\brief some helpful functions
|
||||
*/
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace ttmath
|
||||
{
|
||||
|
||||
/*!
|
||||
some helpful functions
|
||||
*/
|
||||
class Misc
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* AssignString(result, str)
|
||||
* result = str
|
||||
*
|
||||
*/
|
||||
|
||||
/*!
|
||||
result = str
|
||||
*/
|
||||
static void AssignString(std::string & result, const char * str)
|
||||
{
|
||||
result = str;
|
||||
}
|
||||
|
||||
|
||||
#ifndef TTMATH_DONT_USE_WCHAR
|
||||
|
||||
/*!
|
||||
result = str
|
||||
*/
|
||||
static void AssignString(std::wstring & result, const char * str)
|
||||
{
|
||||
result.clear();
|
||||
|
||||
for( ; *str ; ++str )
|
||||
result += *str;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
result = str
|
||||
*/
|
||||
static void AssignString(std::wstring & result, const std::string & str)
|
||||
{
|
||||
return AssignString(result, str.c_str());
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
result = str
|
||||
*/
|
||||
static void AssignString(std::string & result, const wchar_t * str)
|
||||
{
|
||||
result.clear();
|
||||
|
||||
for( ; *str ; ++str )
|
||||
result += static_cast<char>(*str);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
result = str
|
||||
*/
|
||||
static void AssignString(std::string & result, const std::wstring & str)
|
||||
{
|
||||
return AssignString(result, str.c_str());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* AddString(result, str)
|
||||
* result += str
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
result += str
|
||||
*/
|
||||
static void AddString(std::string & result, const char * str)
|
||||
{
|
||||
result += str;
|
||||
}
|
||||
|
||||
|
||||
#ifndef TTMATH_DONT_USE_WCHAR
|
||||
|
||||
/*!
|
||||
result += str
|
||||
*/
|
||||
static void AddString(std::wstring & result, const char * str)
|
||||
{
|
||||
for( ; *str ; ++str )
|
||||
result += *str;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
this method omits any white characters from the string
|
||||
char_type is char or wchar_t
|
||||
*/
|
||||
template<class char_type>
|
||||
static void SkipWhiteCharacters(const char_type * & c)
|
||||
{
|
||||
// 13 is at the end in a DOS text file (\r\n)
|
||||
while( (*c==' ' ) || (*c=='\t') || (*c==13 ) || (*c=='\n') )
|
||||
++c;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this static method converts one character into its value
|
||||
|
||||
for example:
|
||||
1 -> 1
|
||||
8 -> 8
|
||||
A -> 10
|
||||
f -> 15
|
||||
|
||||
this method don't check whether c is correct or not
|
||||
*/
|
||||
static uint CharToDigit(uint c)
|
||||
{
|
||||
if(c>='0' && c<='9')
|
||||
return c-'0';
|
||||
|
||||
if(c>='a' && c<='z')
|
||||
return c-'a'+10;
|
||||
|
||||
return c-'A'+10;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
this method changes a character 'c' into its value
|
||||
(if there can't be a correct value it returns -1)
|
||||
|
||||
for example:
|
||||
c=2, base=10 -> function returns 2
|
||||
c=A, base=10 -> function returns -1
|
||||
c=A, base=16 -> function returns 10
|
||||
*/
|
||||
static sint CharToDigit(uint c, uint base)
|
||||
{
|
||||
if( c>='0' && c<='9' )
|
||||
c=c-'0';
|
||||
else
|
||||
if( c>='a' && c<='z' )
|
||||
c=c-'a'+10;
|
||||
else
|
||||
if( c>='A' && c<='Z' )
|
||||
c=c-'A'+10;
|
||||
else
|
||||
return -1;
|
||||
|
||||
|
||||
if( c >= base )
|
||||
return -1;
|
||||
|
||||
|
||||
return sint(c);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this method converts a digit into a char
|
||||
digit should be from <0,F>
|
||||
(we don't have to get a base)
|
||||
|
||||
for example:
|
||||
1 -> 1
|
||||
8 -> 8
|
||||
10 -> A
|
||||
15 -> F
|
||||
*/
|
||||
static uint DigitToChar(uint digit)
|
||||
{
|
||||
if( digit < 10 )
|
||||
return digit + '0';
|
||||
|
||||
return digit - 10 + 'A';
|
||||
}
|
||||
|
||||
|
||||
}; // struct Misc
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
809
3rd_party/ttmath-0.9.3/ttmath/ttmathobjects.h
vendored
Normal file
809
3rd_party/ttmath-0.9.3/ttmath/ttmathobjects.h
vendored
Normal file
@@ -0,0 +1,809 @@
|
||||
/*
|
||||
* This file is a part of TTMath Mathematical Library
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef headerfilettmathobject
|
||||
#define headerfilettmathobject
|
||||
|
||||
/*!
|
||||
\file ttmathobjects.h
|
||||
\brief Mathematic functions.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
#include "ttmathtypes.h"
|
||||
#include "ttmathmisc.h"
|
||||
|
||||
|
||||
namespace ttmath
|
||||
{
|
||||
|
||||
/*!
|
||||
objects of this class are used with the mathematical parser
|
||||
they hold variables or functions defined by a user
|
||||
|
||||
each object has its own table in which we're keeping variables or functions
|
||||
*/
|
||||
class Objects
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
/*!
|
||||
one item (variable or function)
|
||||
'items' will be on the table
|
||||
*/
|
||||
struct Item
|
||||
{
|
||||
// name of a variable of a function
|
||||
// internally we store variables and funcions as std::string (not std::wstring even when wide characters are used)
|
||||
std::string value;
|
||||
|
||||
// number of parameters required by the function
|
||||
// (if there's a variable this 'param' is ignored)
|
||||
int param;
|
||||
|
||||
Item() {}
|
||||
Item(const std::string & v, int p) : value(v), param(p) {}
|
||||
};
|
||||
|
||||
// 'Table' is the type of our table
|
||||
typedef std::map<std::string, Item> Table;
|
||||
typedef Table::iterator Iterator;
|
||||
typedef Table::const_iterator CIterator;
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this method returns true if a character 'c' is a character
|
||||
which can be in a name
|
||||
|
||||
if 'can_be_digit' is true that means when the 'c' is a digit this
|
||||
method returns true otherwise it returns false
|
||||
*/
|
||||
static bool CorrectCharacter(int c, bool can_be_digit)
|
||||
{
|
||||
if( (c>='a' && c<='z') || (c>='A' && c<='Z') )
|
||||
return true;
|
||||
|
||||
if( can_be_digit && ((c>='0' && c<='9') || c=='_') )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
this method returns true if the name can be as a name of an object
|
||||
*/
|
||||
template<class string_type>
|
||||
static bool IsNameCorrect(const string_type & name)
|
||||
{
|
||||
if( name.empty() )
|
||||
return false;
|
||||
|
||||
if( !CorrectCharacter(name[0], false) )
|
||||
return false;
|
||||
|
||||
typename string_type::const_iterator i = name.begin();
|
||||
|
||||
for(++i ; i!=name.end() ; ++i)
|
||||
if( !CorrectCharacter(*i, true) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
this method returns true if such an object is defined (name exists)
|
||||
*/
|
||||
bool IsDefined(const std::string & name)
|
||||
{
|
||||
Iterator i = table.find(name);
|
||||
|
||||
if( i != table.end() )
|
||||
// we have this object in our table
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifndef TTMATH_DONT_USE_WCHAR
|
||||
|
||||
/*!
|
||||
this method returns true if such an object is defined (name exists)
|
||||
*/
|
||||
bool IsDefined(const std::wstring & name)
|
||||
{
|
||||
// we should check whether the name (in wide characters) are correct
|
||||
// before calling AssignString() function
|
||||
if( !IsNameCorrect(name) )
|
||||
return false;
|
||||
|
||||
Misc::AssignString(str_tmp1, name);
|
||||
|
||||
return IsDefined(str_tmp1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
this method adds one object (variable of function) into the table
|
||||
*/
|
||||
ErrorCode Add(const std::string & name, const std::string & value, int param = 0)
|
||||
{
|
||||
if( !IsNameCorrect(name) )
|
||||
return err_incorrect_name;
|
||||
|
||||
Iterator i = table.find(name);
|
||||
|
||||
if( i != table.end() )
|
||||
// we have this object in our table
|
||||
return err_object_exists;
|
||||
|
||||
table.insert( std::make_pair(name, Item(value, param)) );
|
||||
|
||||
return err_ok;
|
||||
}
|
||||
|
||||
|
||||
#ifndef TTMATH_DONT_USE_WCHAR
|
||||
|
||||
/*!
|
||||
this method adds one object (variable of function) into the table
|
||||
*/
|
||||
ErrorCode Add(const std::wstring & name, const std::wstring & value, int param = 0)
|
||||
{
|
||||
// we should check whether the name (in wide characters) are correct
|
||||
// before calling AssignString() function
|
||||
if( !IsNameCorrect(name) )
|
||||
return err_incorrect_name;
|
||||
|
||||
Misc::AssignString(str_tmp1, name);
|
||||
Misc::AssignString(str_tmp2, value);
|
||||
|
||||
return Add(str_tmp1, str_tmp2, param);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
this method returns 'true' if the table is empty
|
||||
*/
|
||||
bool Empty() const
|
||||
{
|
||||
return table.empty();
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
this method clears the table
|
||||
*/
|
||||
void Clear()
|
||||
{
|
||||
return table.clear();
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
this method returns 'const_iterator' on the first item on the table
|
||||
*/
|
||||
CIterator Begin() const
|
||||
{
|
||||
return table.begin();
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
this method returns 'const_iterator' pointing at the space after last item
|
||||
(returns table.end())
|
||||
*/
|
||||
CIterator End() const
|
||||
{
|
||||
return table.end();
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
this method changes the value and the number of parameters for a specific object
|
||||
*/
|
||||
ErrorCode EditValue(const std::string & name, const std::string & value, int param = 0)
|
||||
{
|
||||
if( !IsNameCorrect(name) )
|
||||
return err_incorrect_name;
|
||||
|
||||
Iterator i = table.find(name);
|
||||
|
||||
if( i == table.end() )
|
||||
return err_unknown_object;
|
||||
|
||||
i->second.value = value;
|
||||
i->second.param = param;
|
||||
|
||||
return err_ok;
|
||||
}
|
||||
|
||||
|
||||
#ifndef TTMATH_DONT_USE_WCHAR
|
||||
|
||||
|
||||
/*!
|
||||
this method changes the value and the number of parameters for a specific object
|
||||
*/
|
||||
ErrorCode EditValue(const std::wstring & name, const std::wstring & value, int param = 0)
|
||||
{
|
||||
// we should check whether the name (in wide characters) are correct
|
||||
// before calling AssignString() function
|
||||
if( !IsNameCorrect(name) )
|
||||
return err_incorrect_name;
|
||||
|
||||
Misc::AssignString(str_tmp1, name);
|
||||
Misc::AssignString(str_tmp2, value);
|
||||
|
||||
return EditValue(str_tmp1, str_tmp2, param);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
this method changes the name of a specific object
|
||||
*/
|
||||
ErrorCode EditName(const std::string & old_name, const std::string & new_name)
|
||||
{
|
||||
if( !IsNameCorrect(old_name) || !IsNameCorrect(new_name) )
|
||||
return err_incorrect_name;
|
||||
|
||||
Iterator old_i = table.find(old_name);
|
||||
if( old_i == table.end() )
|
||||
return err_unknown_object;
|
||||
|
||||
if( old_name == new_name )
|
||||
// the new name is the same as the old one
|
||||
// we treat it as a normal situation
|
||||
return err_ok;
|
||||
|
||||
ErrorCode err = Add(new_name, old_i->second.value, old_i->second.param);
|
||||
|
||||
if( err == err_ok )
|
||||
{
|
||||
old_i = table.find(old_name);
|
||||
TTMATH_ASSERT( old_i != table.end() )
|
||||
|
||||
table.erase(old_i);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifndef TTMATH_DONT_USE_WCHAR
|
||||
|
||||
|
||||
/*!
|
||||
this method changes the name of a specific object
|
||||
*/
|
||||
ErrorCode EditName(const std::wstring & old_name, const std::wstring & new_name)
|
||||
{
|
||||
// we should check whether the name (in wide characters) are correct
|
||||
// before calling AssignString() function
|
||||
if( !IsNameCorrect(old_name) || !IsNameCorrect(new_name) )
|
||||
return err_incorrect_name;
|
||||
|
||||
Misc::AssignString(str_tmp1, old_name);
|
||||
Misc::AssignString(str_tmp2, new_name);
|
||||
|
||||
return EditName(str_tmp1, str_tmp2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
this method deletes an object
|
||||
*/
|
||||
ErrorCode Delete(const std::string & name)
|
||||
{
|
||||
if( !IsNameCorrect(name) )
|
||||
return err_incorrect_name;
|
||||
|
||||
Iterator i = table.find(name);
|
||||
|
||||
if( i == table.end() )
|
||||
return err_unknown_object;
|
||||
|
||||
table.erase( i );
|
||||
|
||||
return err_ok;
|
||||
}
|
||||
|
||||
|
||||
#ifndef TTMATH_DONT_USE_WCHAR
|
||||
|
||||
|
||||
/*!
|
||||
this method deletes an object
|
||||
*/
|
||||
ErrorCode Delete(const std::wstring & name)
|
||||
{
|
||||
// we should check whether the name (in wide characters) are correct
|
||||
// before calling AssignString() function
|
||||
if( !IsNameCorrect(name) )
|
||||
return err_incorrect_name;
|
||||
|
||||
Misc::AssignString(str_tmp1, name);
|
||||
|
||||
return Delete(str_tmp1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
this method gets the value of a specific object
|
||||
*/
|
||||
ErrorCode GetValue(const std::string & name, std::string & value) const
|
||||
{
|
||||
if( !IsNameCorrect(name) )
|
||||
return err_incorrect_name;
|
||||
|
||||
CIterator i = table.find(name);
|
||||
|
||||
if( i == table.end() )
|
||||
{
|
||||
value.clear();
|
||||
return err_unknown_object;
|
||||
}
|
||||
|
||||
value = i->second.value;
|
||||
|
||||
return err_ok;
|
||||
}
|
||||
|
||||
|
||||
#ifndef TTMATH_DONT_USE_WCHAR
|
||||
|
||||
/*!
|
||||
this method gets the value of a specific object
|
||||
*/
|
||||
ErrorCode GetValue(const std::wstring & name, std::wstring & value)
|
||||
{
|
||||
// we should check whether the name (in wide characters) are correct
|
||||
// before calling AssignString() function
|
||||
if( !IsNameCorrect(name) )
|
||||
return err_incorrect_name;
|
||||
|
||||
Misc::AssignString(str_tmp1, name);
|
||||
ErrorCode err = GetValue(str_tmp1, str_tmp2);
|
||||
Misc::AssignString(value, str_tmp2);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
this method gets the value of a specific object
|
||||
(this version is used for not copying the whole string)
|
||||
*/
|
||||
ErrorCode GetValue(const std::string & name, const char ** value) const
|
||||
{
|
||||
if( !IsNameCorrect(name) )
|
||||
return err_incorrect_name;
|
||||
|
||||
CIterator i = table.find(name);
|
||||
|
||||
if( i == table.end() )
|
||||
{
|
||||
*value = 0;
|
||||
return err_unknown_object;
|
||||
}
|
||||
|
||||
*value = i->second.value.c_str();
|
||||
|
||||
return err_ok;
|
||||
}
|
||||
|
||||
|
||||
#ifndef TTMATH_DONT_USE_WCHAR
|
||||
|
||||
/*!
|
||||
this method gets the value of a specific object
|
||||
(this version is used for not copying the whole string)
|
||||
*/
|
||||
ErrorCode GetValue(const std::wstring & name, const char ** value)
|
||||
{
|
||||
// we should check whether the name (in wide characters) are correct
|
||||
// before calling AssignString() function
|
||||
if( !IsNameCorrect(name) )
|
||||
return err_incorrect_name;
|
||||
|
||||
Misc::AssignString(str_tmp1, name);
|
||||
|
||||
return GetValue(str_tmp1, value);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
this method gets the value and the number of parameters
|
||||
of a specific object
|
||||
*/
|
||||
ErrorCode GetValueAndParam(const std::string & name, std::string & value, int * param) const
|
||||
{
|
||||
if( !IsNameCorrect(name) )
|
||||
return err_incorrect_name;
|
||||
|
||||
CIterator i = table.find(name);
|
||||
|
||||
if( i == table.end() )
|
||||
{
|
||||
value.empty();
|
||||
*param = 0;
|
||||
return err_unknown_object;
|
||||
}
|
||||
|
||||
value = i->second.value;
|
||||
*param = i->second.param;
|
||||
|
||||
return err_ok;
|
||||
}
|
||||
|
||||
|
||||
#ifndef TTMATH_DONT_USE_WCHAR
|
||||
|
||||
/*!
|
||||
this method gets the value and the number of parameters
|
||||
of a specific object
|
||||
*/
|
||||
ErrorCode GetValueAndParam(const std::wstring & name, std::wstring & value, int * param)
|
||||
{
|
||||
// we should check whether the name (in wide characters) are correct
|
||||
// before calling AssignString() function
|
||||
if( !IsNameCorrect(name) )
|
||||
return err_incorrect_name;
|
||||
|
||||
Misc::AssignString(str_tmp1, name);
|
||||
ErrorCode err = GetValueAndParam(str_tmp1, str_tmp2, param);
|
||||
Misc::AssignString(value, str_tmp2);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
this method sets the value and the number of parameters
|
||||
of a specific object
|
||||
(this version is used for not copying the whole string)
|
||||
*/
|
||||
ErrorCode GetValueAndParam(const std::string & name, const char ** value, int * param) const
|
||||
{
|
||||
if( !IsNameCorrect(name) )
|
||||
return err_incorrect_name;
|
||||
|
||||
CIterator i = table.find(name);
|
||||
|
||||
if( i == table.end() )
|
||||
{
|
||||
*value = 0;
|
||||
*param = 0;
|
||||
return err_unknown_object;
|
||||
}
|
||||
|
||||
*value = i->second.value.c_str();
|
||||
*param = i->second.param;
|
||||
|
||||
return err_ok;
|
||||
}
|
||||
|
||||
|
||||
#ifndef TTMATH_DONT_USE_WCHAR
|
||||
|
||||
|
||||
/*!
|
||||
this method sets the value and the number of parameters
|
||||
of a specific object
|
||||
(this version is used for not copying the whole string
|
||||
but in fact we make one copying during AssignString())
|
||||
*/
|
||||
ErrorCode GetValueAndParam(const std::wstring & name, const char ** value, int * param)
|
||||
{
|
||||
// we should check whether the name (in wide characters) are correct
|
||||
// before calling AssignString() function
|
||||
if( !IsNameCorrect(name) )
|
||||
return err_incorrect_name;
|
||||
|
||||
Misc::AssignString(str_tmp1, name);
|
||||
|
||||
return GetValueAndParam(str_tmp1, value, param);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
this method returns a pointer into the table
|
||||
*/
|
||||
Table * GetTable()
|
||||
{
|
||||
return &table;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Table table;
|
||||
std::string str_tmp1, str_tmp2;
|
||||
|
||||
}; // end of class Objects
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
objects of the class History are used to keep values in functions
|
||||
which take a lot of time during calculating, for instance in the
|
||||
function Factorial(x)
|
||||
|
||||
it means that when we're calculating e.g. Factorial(1000) and the
|
||||
Factorial finds that we have calculated it before, the value (result)
|
||||
is taken from the history
|
||||
*/
|
||||
template<class ValueType>
|
||||
class History
|
||||
{
|
||||
/*!
|
||||
one item in the History's object holds a key, a value for the key
|
||||
and a corresponding error code
|
||||
*/
|
||||
struct Item
|
||||
{
|
||||
ValueType key, value;
|
||||
ErrorCode err;
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
we use std::list for simply deleting the first item
|
||||
but because we're searching through the whole container
|
||||
(in the method Get) the container should not be too big
|
||||
(linear time of searching)
|
||||
*/
|
||||
typedef std::list<Item> buffer_type;
|
||||
buffer_type buffer;
|
||||
typename buffer_type::size_type buffer_max_size;
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
default constructor
|
||||
default max size of the History's container is 15 items
|
||||
*/
|
||||
History()
|
||||
{
|
||||
buffer_max_size = 15;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
a constructor which takes another value of the max size
|
||||
of the History's container
|
||||
*/
|
||||
History(typename buffer_type::size_type new_size)
|
||||
{
|
||||
buffer_max_size = new_size;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
this method adds one item into the History
|
||||
if the size of the container is greater than buffer_max_size
|
||||
the first item will be removed
|
||||
*/
|
||||
void Add(const ValueType & key, const ValueType & value, ErrorCode err)
|
||||
{
|
||||
Item item;
|
||||
item.key = key;
|
||||
item.value = value;
|
||||
item.err = err;
|
||||
|
||||
buffer.insert( buffer.end(), item );
|
||||
|
||||
if( buffer.size() > buffer_max_size )
|
||||
buffer.erase(buffer.begin());
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
this method checks whether we have an item which has the key equal 'key'
|
||||
|
||||
if there's such item the method sets the 'value' and the 'err'
|
||||
and returns true otherwise it returns false and 'value' and 'err'
|
||||
remain unchanged
|
||||
*/
|
||||
bool Get(const ValueType & key, ValueType & value, ErrorCode & err)
|
||||
{
|
||||
typename buffer_type::iterator i = buffer.begin();
|
||||
|
||||
for( ; i != buffer.end() ; ++i )
|
||||
{
|
||||
if( i->key == key )
|
||||
{
|
||||
value = i->value;
|
||||
err = i->err;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
this methods deletes an item
|
||||
|
||||
we assume that there is only one item with the 'key'
|
||||
(this methods removes the first one)
|
||||
*/
|
||||
bool Remove(const ValueType & key)
|
||||
{
|
||||
typename buffer_type::iterator i = buffer.begin();
|
||||
|
||||
for( ; i != buffer.end() ; ++i )
|
||||
{
|
||||
if( i->key == key )
|
||||
{
|
||||
buffer.erase(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}; // end of class History
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this is an auxiliary class used when calculating Gamma() or Factorial()
|
||||
|
||||
in multithreaded environment you can provide an object of this class to
|
||||
the Gamma() or Factorial() function, e.g;
|
||||
typedef Big<1, 3> MyBig;
|
||||
MyBig x = 123456;
|
||||
CGamma<MyBig> cgamma;
|
||||
std::cout << Gamma(x, cgamma);
|
||||
each thread should have its own CGamma<> object
|
||||
|
||||
in a single-thread environment a CGamma<> object is a static variable
|
||||
in a second version of Gamma() and you don't have to explicitly use it, e.g.
|
||||
typedef Big<1, 3> MyBig;
|
||||
MyBig x = 123456;
|
||||
std::cout << Gamma(x);
|
||||
*/
|
||||
template<class ValueType>
|
||||
struct CGamma
|
||||
{
|
||||
/*!
|
||||
this table holds factorials
|
||||
1
|
||||
1
|
||||
2
|
||||
6
|
||||
24
|
||||
120
|
||||
720
|
||||
.......
|
||||
*/
|
||||
std::vector<ValueType> fact;
|
||||
|
||||
|
||||
/*!
|
||||
this table holds Bernoulli numbers
|
||||
1
|
||||
-0.5
|
||||
0.166666666666666666666666667
|
||||
0
|
||||
-0.0333333333333333333333333333
|
||||
0
|
||||
0.0238095238095238095238095238
|
||||
0
|
||||
-0.0333333333333333333333333333
|
||||
0
|
||||
0.075757575757575757575757576
|
||||
.....
|
||||
*/
|
||||
std::vector<ValueType> bern;
|
||||
|
||||
|
||||
/*!
|
||||
here we store some calculated values
|
||||
(this is for speeding up, if the next argument of Gamma() or Factorial()
|
||||
is in the 'history' then the result we are not calculating but simply
|
||||
return from the 'history' object)
|
||||
*/
|
||||
History<ValueType> history;
|
||||
|
||||
|
||||
/*!
|
||||
this method prepares some coefficients: factorials and Bernoulli numbers
|
||||
stored in 'fact' and 'bern' objects
|
||||
|
||||
how many values should be depends on the size of the mantissa - if
|
||||
the mantissa is larger then we must calculate more values
|
||||
for a mantissa which consists of 256 bits (8 words on a 32bit platform)
|
||||
we have to calculate about 30 values (the size of fact and bern will be 30),
|
||||
and for a 2048 bits mantissa we have to calculate 306 coefficients
|
||||
|
||||
you don't have to call this method, these coefficients will be automatically calculated
|
||||
when they are needed
|
||||
|
||||
you must note that calculating these coefficients is a little time-consuming operation,
|
||||
(especially when the mantissa is large) and first call to Gamma() or Factorial()
|
||||
can take more time than next calls, and in the end this is the point when InitAll()
|
||||
comes in handy: you can call this method somewhere at the beginning of your program
|
||||
*/
|
||||
void InitAll();
|
||||
// definition is in ttmath.h
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
2777
3rd_party/ttmath-0.9.3/ttmath/ttmathparser.h
vendored
Normal file
2777
3rd_party/ttmath-0.9.3/ttmath/ttmathparser.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
250
3rd_party/ttmath-0.9.3/ttmath/ttmaththreads.h
vendored
Normal file
250
3rd_party/ttmath-0.9.3/ttmath/ttmaththreads.h
vendored
Normal file
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
* This file is a part of TTMath Bignum Library
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006-2009, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef headerfilettmaththreads
|
||||
#define headerfilettmaththreads
|
||||
|
||||
#include "ttmathtypes.h"
|
||||
|
||||
#ifdef TTMATH_WIN32_THREADS
|
||||
#include <windows.h>
|
||||
#include <cstdio>
|
||||
#endif
|
||||
|
||||
#ifdef TTMATH_POSIX_THREADS
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
\file ttmaththreads.h
|
||||
\brief Some objects used in multithreads environment
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
this is a simple skeleton of a program in multithreads environment:
|
||||
|
||||
#define TTMATH_MULTITHREADS
|
||||
#include<ttmath/ttmath.h>
|
||||
|
||||
TTMATH_MULTITHREADS_HELPER
|
||||
|
||||
int main()
|
||||
{
|
||||
[...]
|
||||
}
|
||||
|
||||
make sure that macro TTMATH_MULTITHREADS is defined and (somewhere in *.cpp file)
|
||||
use TTMATH_MULTITHREADS_HELPER macro (outside of any classes/functions/namespaces scope)
|
||||
*/
|
||||
|
||||
|
||||
namespace ttmath
|
||||
{
|
||||
|
||||
|
||||
#ifdef TTMATH_WIN32_THREADS
|
||||
|
||||
/*
|
||||
we use win32 threads
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
in multithreads environment you should use TTMATH_MULTITHREADS_HELPER macro
|
||||
somewhere in *.cpp file
|
||||
|
||||
(at the moment in win32 this macro does nothing)
|
||||
*/
|
||||
#define TTMATH_MULTITHREADS_HELPER
|
||||
|
||||
|
||||
/*!
|
||||
objects of this class are used to synchronize
|
||||
*/
|
||||
class ThreadLock
|
||||
{
|
||||
HANDLE mutex_handle;
|
||||
|
||||
|
||||
void CreateName(char * buffer) const
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (disable : 4996)
|
||||
// warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead.
|
||||
#endif
|
||||
|
||||
sprintf(buffer, "TTMATH_LOCK_%ul", (unsigned long)GetCurrentProcessId());
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (default : 4996)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
bool Lock()
|
||||
{
|
||||
char buffer[50];
|
||||
|
||||
CreateName(buffer);
|
||||
mutex_handle = CreateMutexA(0, false, buffer);
|
||||
|
||||
if( mutex_handle == 0 )
|
||||
return false;
|
||||
|
||||
WaitForSingleObject(mutex_handle, INFINITE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
ThreadLock()
|
||||
{
|
||||
mutex_handle = 0;
|
||||
}
|
||||
|
||||
|
||||
~ThreadLock()
|
||||
{
|
||||
if( mutex_handle != 0 )
|
||||
{
|
||||
ReleaseMutex(mutex_handle);
|
||||
CloseHandle(mutex_handle);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // #ifdef TTMATH_WIN32_THREADS
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef TTMATH_POSIX_THREADS
|
||||
|
||||
/*
|
||||
we use posix threads
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
in multithreads environment you should use TTMATH_MULTITHREADS_HELPER macro
|
||||
somewhere in *.cpp file
|
||||
(this macro defines a pthread_mutex_t object used by TTMath library)
|
||||
*/
|
||||
#define TTMATH_MULTITHREADS_HELPER \
|
||||
namespace ttmath \
|
||||
{ \
|
||||
pthread_mutex_t ttmath_mutex = PTHREAD_MUTEX_INITIALIZER; \
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
ttmath_mutex will be defined by TTMATH_MULTITHREADS_HELPER macro
|
||||
*/
|
||||
extern pthread_mutex_t ttmath_mutex;
|
||||
|
||||
|
||||
/*!
|
||||
objects of this class are used to synchronize
|
||||
*/
|
||||
class ThreadLock
|
||||
{
|
||||
public:
|
||||
|
||||
bool Lock()
|
||||
{
|
||||
if( pthread_mutex_lock(&ttmath_mutex) != 0 )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
~ThreadLock()
|
||||
{
|
||||
pthread_mutex_unlock(&ttmath_mutex);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // #ifdef TTMATH_POSIX_THREADS
|
||||
|
||||
|
||||
|
||||
|
||||
#if !defined(TTMATH_POSIX_THREADS) && !defined(TTMATH_WIN32_THREADS)
|
||||
|
||||
/*!
|
||||
we don't use win32 and pthreads
|
||||
*/
|
||||
|
||||
/*!
|
||||
*/
|
||||
#define TTMATH_MULTITHREADS_HELPER
|
||||
|
||||
|
||||
/*!
|
||||
objects of this class are used to synchronize
|
||||
actually we don't synchronize, the method Lock() returns always 'false'
|
||||
*/
|
||||
class ThreadLock
|
||||
{
|
||||
public:
|
||||
|
||||
bool Lock()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // #if !defined(TTMATH_POSIX_THREADS) && !defined(TTMATH_WIN32_THREADS)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
|
676
3rd_party/ttmath-0.9.3/ttmath/ttmathtypes.h
vendored
Normal file
676
3rd_party/ttmath-0.9.3/ttmath/ttmathtypes.h
vendored
Normal file
@@ -0,0 +1,676 @@
|
||||
/*
|
||||
* This file is a part of TTMath Bignum Library
|
||||
* and is distributed under the (new) BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006-2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
||||
* project may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef headerfilettmathtypes
|
||||
#define headerfilettmathtypes
|
||||
|
||||
/*!
|
||||
\file ttmathtypes.h
|
||||
\brief constants used in the library
|
||||
|
||||
As our library is written in header files (templates) we cannot use
|
||||
constants like 'const int' etc. because we should have some source files
|
||||
*.cpp to define this variables. Only what we can have are constants
|
||||
defined by #define preprocessor macros.
|
||||
|
||||
All macros are preceded by TTMATH_ prefix
|
||||
*/
|
||||
|
||||
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <stdint.h>
|
||||
// for uint64_t and int64_t on a 32 bit platform
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
the version of the library
|
||||
|
||||
TTMATH_PRERELEASE_VER is either zero or one
|
||||
zero means that this is the release version of the library
|
||||
(one means something like beta)
|
||||
*/
|
||||
#define TTMATH_MAJOR_VER 0
|
||||
#define TTMATH_MINOR_VER 9
|
||||
#define TTMATH_REVISION_VER 3
|
||||
|
||||
#define TTMATH_PRERELEASE_VER 0
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
you can define a platform explicitly by defining either
|
||||
TTMATH_PLATFORM32 or TTMATH_PLATFORM64 macro
|
||||
*/
|
||||
#if !defined TTMATH_PLATFORM32 && !defined TTMATH_PLATFORM64
|
||||
|
||||
#if !defined _M_X64 && !defined __x86_64__
|
||||
|
||||
/*
|
||||
other platforms than x86 and amd64 are not recognized at the moment
|
||||
so you should set TTMATH_PLATFORMxx manually
|
||||
*/
|
||||
|
||||
// we're using a 32bit platform
|
||||
#define TTMATH_PLATFORM32
|
||||
|
||||
#else
|
||||
|
||||
// we're using a 64bit platform
|
||||
#define TTMATH_PLATFORM64
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
asm version of the library is available by default only for:
|
||||
x86 and amd64 platforms and for Microsoft Visual and GCC compilers
|
||||
|
||||
but you can force using asm version (the same asm as for Microsoft Visual)
|
||||
by defining TTMATH_FORCEASM macro
|
||||
you have to be sure that your compiler accept such an asm format
|
||||
*/
|
||||
#ifndef TTMATH_FORCEASM
|
||||
|
||||
#if !defined __i386__ && !defined _X86_ && !defined _M_IX86 && !defined __x86_64__ && !defined _M_X64
|
||||
/*!
|
||||
x86 architecture:
|
||||
__i386__ defined by GNU C
|
||||
_X86_ defined by MinGW32
|
||||
_M_IX86 defined by Visual Studio, Intel C/C++, Digital Mars and Watcom C/C++
|
||||
|
||||
amd64 architecture:
|
||||
__x86_64__ defined by GNU C, CLANG (LLVM) and Sun Studio
|
||||
_M_X64 defined by Visual Studio
|
||||
|
||||
asm version is available only for x86 or amd64 platforms
|
||||
*/
|
||||
#define TTMATH_NOASM
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined _MSC_VER && !defined __GNUC__
|
||||
/*!
|
||||
another compilers than MS VC or GCC or CLANG (LLVM) by default use no asm version
|
||||
(CLANG defines __GNUC__ too)
|
||||
*/
|
||||
#define TTMATH_NOASM
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
namespace ttmath
|
||||
{
|
||||
|
||||
|
||||
#ifdef TTMATH_PLATFORM32
|
||||
|
||||
/*!
|
||||
on 32bit platforms one word (uint, sint) will be equal 32bits
|
||||
*/
|
||||
typedef unsigned int uint;
|
||||
typedef signed int sint;
|
||||
|
||||
/*!
|
||||
on 32 bit platform ulint and slint will be equal 64 bits
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
// long long on MS Windows (Visual and GCC mingw compilers) have 64 bits
|
||||
// stdint.h is not available on Visual Studio prior to VS 2010 version
|
||||
typedef unsigned long long int ulint;
|
||||
typedef signed long long int slint;
|
||||
#else
|
||||
// we do not use 'long' here because there is a difference in unix and windows
|
||||
// environments: in unix 'long' has 64 bits but in windows it has only 32 bits
|
||||
typedef uint64_t ulint;
|
||||
typedef int64_t slint;
|
||||
#endif
|
||||
|
||||
/*!
|
||||
how many bits there are in the uint type
|
||||
*/
|
||||
#define TTMATH_BITS_PER_UINT 32u
|
||||
|
||||
/*!
|
||||
the mask for the highest bit in the unsigned 32bit word (2^31)
|
||||
*/
|
||||
#define TTMATH_UINT_HIGHEST_BIT 2147483648u
|
||||
|
||||
/*!
|
||||
the max value of the unsigned 32bit word (2^32 - 1)
|
||||
(all bits equal one)
|
||||
*/
|
||||
#define TTMATH_UINT_MAX_VALUE 4294967295u
|
||||
|
||||
/*!
|
||||
the number of words (32bit words on 32bit platform)
|
||||
which are kept in built-in variables for a Big<> type
|
||||
(these variables are defined in ttmathbig.h)
|
||||
*/
|
||||
#define TTMATH_BUILTIN_VARIABLES_SIZE 256u
|
||||
|
||||
/*!
|
||||
this macro returns the number of machine words
|
||||
capable to hold min_bits bits
|
||||
e.g. TTMATH_BITS(128) returns 4
|
||||
*/
|
||||
#define TTMATH_BITS(min_bits) ((min_bits-1)/32 + 1)
|
||||
|
||||
#else
|
||||
|
||||
/*!
|
||||
on 64bit platforms one word (uint, sint) will be equal 64bits
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
/* in VC 'long' type has 32 bits, __int64 is VC extension */
|
||||
typedef unsigned __int64 uint;
|
||||
typedef signed __int64 sint;
|
||||
#else
|
||||
typedef unsigned long uint;
|
||||
typedef signed long sint;
|
||||
#endif
|
||||
|
||||
/*!
|
||||
on 64bit platforms we do not define ulint and slint
|
||||
*/
|
||||
|
||||
/*!
|
||||
how many bits there are in the uint type
|
||||
*/
|
||||
#define TTMATH_BITS_PER_UINT 64ul
|
||||
|
||||
/*!
|
||||
the mask for the highest bit in the unsigned 64bit word (2^63)
|
||||
*/
|
||||
#define TTMATH_UINT_HIGHEST_BIT 9223372036854775808ul
|
||||
|
||||
/*!
|
||||
the max value of the unsigned 64bit word (2^64 - 1)
|
||||
(all bits equal one)
|
||||
*/
|
||||
#define TTMATH_UINT_MAX_VALUE 18446744073709551615ul
|
||||
|
||||
/*!
|
||||
the number of words (64bit words on 64bit platforms)
|
||||
which are kept in built-in variables for a Big<> type
|
||||
(these variables are defined in ttmathbig.h)
|
||||
*/
|
||||
#define TTMATH_BUILTIN_VARIABLES_SIZE 128ul
|
||||
|
||||
/*!
|
||||
this macro returns the number of machine words
|
||||
capable to hold min_bits bits
|
||||
e.g. TTMATH_BITS(128) returns 2
|
||||
*/
|
||||
#define TTMATH_BITS(min_bits) ((min_bits-1)/64 + 1)
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if defined(TTMATH_MULTITHREADS) && !defined(TTMATH_MULTITHREADS_NOSYNC)
|
||||
#if !defined(TTMATH_POSIX_THREADS) && !defined(TTMATH_WIN32_THREADS)
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define TTMATH_WIN32_THREADS
|
||||
#elif defined(unix) || defined(__unix__) || defined(__unix)
|
||||
#define TTMATH_POSIX_THREADS
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this variable defines how many iterations are performed
|
||||
during some kind of calculating when we're making any long formulas
|
||||
(for example Taylor series)
|
||||
|
||||
it's used in ExpSurrounding0(...), LnSurrounding1(...), Sin0pi05(...), etc.
|
||||
|
||||
note! there'll not be so many iterations, iterations are stopped when
|
||||
there is no sense to continue calculating (for example when the result
|
||||
still remains unchanged after adding next series and we know that the next
|
||||
series are smaller than previous ones)
|
||||
*/
|
||||
#define TTMATH_ARITHMETIC_MAX_LOOP 10000
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this is a limit when calculating Karatsuba multiplication
|
||||
if the size of a vector is smaller than TTMATH_USE_KARATSUBA_MULTIPLICATION_FROM_SIZE
|
||||
the Karatsuba algorithm will use standard schoolbook multiplication
|
||||
*/
|
||||
#ifdef TTMATH_DEBUG_LOG
|
||||
// if TTMATH_DEBUG_LOG is defined then we should use the same size regardless of the compiler
|
||||
#define TTMATH_USE_KARATSUBA_MULTIPLICATION_FROM_SIZE 3
|
||||
#else
|
||||
#ifdef __GNUC__
|
||||
#define TTMATH_USE_KARATSUBA_MULTIPLICATION_FROM_SIZE 3
|
||||
#else
|
||||
#define TTMATH_USE_KARATSUBA_MULTIPLICATION_FROM_SIZE 5
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
this is a special value used when calculating the Gamma(x) function
|
||||
if x is greater than this value then the Gamma(x) will be calculated using
|
||||
some kind of series
|
||||
|
||||
don't use smaller values than about 100
|
||||
*/
|
||||
#define TTMATH_GAMMA_BOUNDARY 2000
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace ttmath
|
||||
{
|
||||
|
||||
/*!
|
||||
lib type codes:
|
||||
asm_vc_32 - with asm code designed for Microsoft Visual C++ (32 bits)
|
||||
asm_gcc_32 - with asm code designed for GCC (32 bits)
|
||||
asm_vc_64 - with asm for VC (64 bit)
|
||||
asm_gcc_64 - with asm for GCC (64 bit)
|
||||
no_asm_32 - pure C++ version (32 bit) - without any asm code
|
||||
no_asm_64 - pure C++ version (64 bit) - without any asm code
|
||||
*/
|
||||
enum LibTypeCode
|
||||
{
|
||||
asm_vc_32 = 0,
|
||||
asm_gcc_32,
|
||||
asm_vc_64,
|
||||
asm_gcc_64,
|
||||
no_asm_32,
|
||||
no_asm_64
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
error codes
|
||||
*/
|
||||
enum ErrorCode
|
||||
{
|
||||
err_ok = 0,
|
||||
err_nothing_has_read,
|
||||
err_unknown_character,
|
||||
err_unexpected_final_bracket,
|
||||
err_stack_not_clear,
|
||||
err_unknown_variable,
|
||||
err_division_by_zero,
|
||||
err_interrupt,
|
||||
err_overflow,
|
||||
err_unknown_function,
|
||||
err_unknown_operator,
|
||||
err_unexpected_semicolon_operator,
|
||||
err_improper_amount_of_arguments,
|
||||
err_improper_argument,
|
||||
err_unexpected_end,
|
||||
err_internal_error,
|
||||
err_incorrect_name,
|
||||
err_incorrect_value,
|
||||
err_variable_exists,
|
||||
err_variable_loop,
|
||||
err_functions_loop,
|
||||
err_must_be_only_one_value,
|
||||
err_object_exists,
|
||||
err_unknown_object,
|
||||
err_still_calculating,
|
||||
err_in_short_form_used_function,
|
||||
err_percent_from
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
this struct is used when converting to/from a string
|
||||
/temporarily only in Big::ToString() and Big::FromString()/
|
||||
*/
|
||||
struct Conv
|
||||
{
|
||||
/*!
|
||||
base (radix) on which the value will be shown (or read)
|
||||
default: 10
|
||||
*/
|
||||
uint base;
|
||||
|
||||
|
||||
/*!
|
||||
used only in Big::ToString()
|
||||
if true the value will be always shown in the scientific mode, e.g: 123e+30
|
||||
default: false
|
||||
*/
|
||||
bool scient;
|
||||
|
||||
|
||||
/*!
|
||||
used only in Big::ToString()
|
||||
if scient is false then the value will be printed in the scientific mode
|
||||
only if the exponent is greater than scien_from
|
||||
default: 15
|
||||
*/
|
||||
sint scient_from;
|
||||
|
||||
|
||||
/*!
|
||||
if 'base_round' is true and 'base' is different from 2, 4, 8, or 16
|
||||
and the result value is not an integer then we make an additional rounding
|
||||
(after converting the last digit from the result is skipped)
|
||||
default: true
|
||||
|
||||
e.g.
|
||||
Conv c;
|
||||
c.base_round = false;
|
||||
Big<1, 1> a = "0.1"; // decimal input
|
||||
std::cout << a.ToString(c) << std::endl; // the result is: 0.099999999
|
||||
*/
|
||||
bool base_round;
|
||||
|
||||
|
||||
/*!
|
||||
used only in Big::ToString()
|
||||
tells how many digits after comma are possible
|
||||
default: -1 which means all digits are printed
|
||||
|
||||
set it to zero if you want integer value only
|
||||
|
||||
for example when the value is:
|
||||
12.345678 and 'round' is 4
|
||||
then the result will be
|
||||
12.3457 (the last digit was rounded)
|
||||
*/
|
||||
sint round;
|
||||
|
||||
|
||||
/*!
|
||||
if true that not mattered digits in the mantissa will be cut off
|
||||
(zero characters at the end -- after the comma operator)
|
||||
e.g. 1234,78000 will be: 1234,78
|
||||
default: true
|
||||
*/
|
||||
bool trim_zeroes;
|
||||
|
||||
|
||||
/*!
|
||||
the main comma operator (used when reading and writing)
|
||||
default is a dot '.'
|
||||
*/
|
||||
uint comma;
|
||||
|
||||
|
||||
/*!
|
||||
additional comma operator (used only when reading)
|
||||
if you don't want it just set it to zero
|
||||
default is a comma ','
|
||||
|
||||
this allowes you to convert from a value:
|
||||
123.45 as well as from 123,45
|
||||
*/
|
||||
uint comma2;
|
||||
|
||||
|
||||
/*!
|
||||
it sets the character which is used for grouping
|
||||
if group=' ' then: 1234,56789 will be printed as: 1 234,567 89
|
||||
|
||||
if you don't want grouping just set it to zero (which is default)
|
||||
*/
|
||||
uint group;
|
||||
|
||||
|
||||
/*!
|
||||
how many digits should be grouped (it is used if 'group' is non zero)
|
||||
default: 3
|
||||
*/
|
||||
uint group_digits;
|
||||
|
||||
|
||||
/*!
|
||||
*/
|
||||
uint group_exp; // not implemented yet
|
||||
|
||||
|
||||
|
||||
|
||||
Conv()
|
||||
{
|
||||
// default values
|
||||
base = 10;
|
||||
scient = false;
|
||||
scient_from = 15;
|
||||
base_round = true;
|
||||
round = -1;
|
||||
trim_zeroes = true;
|
||||
comma = '.';
|
||||
comma2 = ',';
|
||||
group = 0;
|
||||
group_digits = 3;
|
||||
group_exp = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
this simple class can be used in multithreading model
|
||||
(you can write your own class derived from this one)
|
||||
|
||||
for example: in some functions like Factorial()
|
||||
/at the moment only Factorial/ you can give a pointer to
|
||||
the 'stop object', if the method WasStopSignal() of this
|
||||
object returns true that means we should break the calculating
|
||||
and return
|
||||
*/
|
||||
class StopCalculating
|
||||
{
|
||||
public:
|
||||
virtual bool WasStopSignal() const volatile { return false; }
|
||||
virtual ~StopCalculating(){}
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
a small class which is useful when compiling with gcc
|
||||
|
||||
object of this type holds the name and the line of a file
|
||||
in which the macro TTMATH_ASSERT or TTMATH_REFERENCE_ASSERT was used
|
||||
*/
|
||||
class ExceptionInfo
|
||||
{
|
||||
const char * file;
|
||||
int line;
|
||||
|
||||
public:
|
||||
ExceptionInfo() : file(0), line(0) {}
|
||||
ExceptionInfo(const char * f, int l) : file(f), line(l) {}
|
||||
|
||||
std::string Where() const
|
||||
{
|
||||
if( !file )
|
||||
return "unknown";
|
||||
|
||||
std::ostringstream result;
|
||||
result << file << ":" << line;
|
||||
|
||||
return result.str();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
A small class used for reporting 'reference' errors
|
||||
|
||||
In the library is used macro TTMATH_REFERENCE_ASSERT which
|
||||
can throw an exception of this type
|
||||
|
||||
** from version 0.9.2 this macro is removed from all methods
|
||||
in public interface so you don't have to worry about it **
|
||||
|
||||
If you compile with gcc you can get a small benefit
|
||||
from using method Where() (it returns std::string) with
|
||||
the name and the line of a file where the macro TTMATH_REFERENCE_ASSERT
|
||||
was used)
|
||||
*/
|
||||
class ReferenceError : public std::logic_error, public ExceptionInfo
|
||||
{
|
||||
public:
|
||||
|
||||
ReferenceError() : std::logic_error("reference error")
|
||||
{
|
||||
}
|
||||
|
||||
ReferenceError(const char * f, int l) :
|
||||
std::logic_error("reference error"), ExceptionInfo(f,l)
|
||||
{
|
||||
}
|
||||
|
||||
std::string Where() const
|
||||
{
|
||||
return ExceptionInfo::Where();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
a small class used for reporting errors
|
||||
|
||||
in the library is used macro TTMATH_ASSERT which
|
||||
(if the condition in it is false) throw an exception
|
||||
of this type
|
||||
|
||||
if you compile with gcc you can get a small benefit
|
||||
from using method Where() (it returns std::string) with
|
||||
the name and the line of a file where the macro TTMATH_ASSERT
|
||||
was used)
|
||||
*/
|
||||
class RuntimeError : public std::runtime_error, public ExceptionInfo
|
||||
{
|
||||
public:
|
||||
|
||||
RuntimeError() : std::runtime_error("internal error")
|
||||
{
|
||||
}
|
||||
|
||||
RuntimeError(const char * f, int l) :
|
||||
std::runtime_error("internal error"), ExceptionInfo(f,l)
|
||||
{
|
||||
}
|
||||
|
||||
std::string Where() const
|
||||
{
|
||||
return ExceptionInfo::Where();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
TTMATH_DEBUG
|
||||
this macro enables further testing during writing your code
|
||||
you don't have to define it in a release mode
|
||||
|
||||
if this macro is set then macros TTMATH_ASSERT and TTMATH_REFERENCE_ASSERT
|
||||
are set as well and these macros can throw an exception if a condition in it
|
||||
is not fulfilled (look at the definition of TTMATH_ASSERT and TTMATH_REFERENCE_ASSERT)
|
||||
|
||||
TTMATH_DEBUG is set automatically if DEBUG or _DEBUG are defined
|
||||
*/
|
||||
#if defined DEBUG || defined _DEBUG
|
||||
#define TTMATH_DEBUG
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef TTMATH_DEBUG
|
||||
|
||||
#if defined(__FILE__) && defined(__LINE__)
|
||||
|
||||
#define TTMATH_REFERENCE_ASSERT(expression) \
|
||||
if( &(expression) == this ) throw ttmath::ReferenceError(__FILE__, __LINE__);
|
||||
|
||||
#define TTMATH_ASSERT(expression) \
|
||||
if( !(expression) ) throw ttmath::RuntimeError(__FILE__, __LINE__);
|
||||
|
||||
#else
|
||||
|
||||
#define TTMATH_REFERENCE_ASSERT(expression) \
|
||||
if( &(expression) == this ) throw ReferenceError();
|
||||
|
||||
#define TTMATH_ASSERT(expression) \
|
||||
if( !(expression) ) throw RuntimeError();
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define TTMATH_REFERENCE_ASSERT(expression)
|
||||
#define TTMATH_ASSERT(expression)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef TTMATH_DEBUG_LOG
|
||||
#define TTMATH_LOG(msg) PrintLog(msg, std::cout);
|
||||
#define TTMATH_LOGC(msg, carry) PrintLog(msg, carry, std::cout);
|
||||
#define TTMATH_VECTOR_LOG(msg, vector, len) PrintVectorLog(msg, std::cout, vector, len);
|
||||
#define TTMATH_VECTOR_LOGC(msg, carry, vector, len) PrintVectorLog(msg, carry, std::cout, vector, len);
|
||||
#else
|
||||
#define TTMATH_LOG(msg)
|
||||
#define TTMATH_LOGC(msg, carry)
|
||||
#define TTMATH_VECTOR_LOG(msg, vector, len)
|
||||
#define TTMATH_VECTOR_LOGC(msg, carry, vector, len)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
#endif
|
||||
|
4165
3rd_party/ttmath-0.9.3/ttmath/ttmathuint.h
vendored
Normal file
4165
3rd_party/ttmath-0.9.3/ttmath/ttmathuint.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1017
3rd_party/ttmath-0.9.3/ttmath/ttmathuint_noasm.h
vendored
Normal file
1017
3rd_party/ttmath-0.9.3/ttmath/ttmathuint_noasm.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1602
3rd_party/ttmath-0.9.3/ttmath/ttmathuint_x86.h
vendored
Normal file
1602
3rd_party/ttmath-0.9.3/ttmath/ttmathuint_x86.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1146
3rd_party/ttmath-0.9.3/ttmath/ttmathuint_x86_64.h
vendored
Normal file
1146
3rd_party/ttmath-0.9.3/ttmath/ttmathuint_x86_64.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user