aboutsummaryrefslogtreecommitdiff
path: root/src/serialize.h
Commit message (Collapse)AuthorAgeFilesLines
* Rename IMPLEMENT_SERIALIZE to ADD_SERIALIZE_METHODSPieter Wuille2014-09-021-3/+3
|
* Merge pull request #4737Pieter Wuille2014-09-011-61/+36
|\ | | | | | | | | | | | | 31e9a83 Use CSizeComputer to avoid counting sizes in SerializationOp (Pieter Wuille) 84881f8 rework overhauled serialization methods to non-static (Kamil Domanski) 5d96b4a remove fields of ser_streamplaceholder (Kamil Domanski) 3d796f8 overhaul serialization code (Kamil Domanski)
| * Use CSizeComputer to avoid counting sizes in SerializationOpPieter Wuille2014-08-311-28/+23
| |
| * rework overhauled serialization methods to non-staticKamil Domanski2014-08-311-7/+7
| | | | | | | | | | | | | | Thanks to Pieter Wuille for most of the work on this commit. I did not fixup the overhaul commit, because a rebase conflicted with "remove fields of ser_streamplaceholder". I prefer not to risk making a mistake while resolving it.
| * remove fields of ser_streamplaceholderKamil Domanski2014-08-311-9/+1
| | | | | | | | | | | | | | The nType and nVersion fields of stream objects are never accessed from outside the class (or perhaps from the inside too, I haven't checked). Thus no need to have them in a placeholder, whose only purpose is to fill the "Stream" template parameter in serialization implementation.
| * overhaul serialization codeKamil Domanski2014-08-311-40/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The implementation of each class' serialization/deserialization is no longer passed within a macro. The implementation now lies within a template of form: template <typename T, typename Stream, typename Operation> inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { size_t nSerSize = 0; /* CODE */ return nSerSize; } In cases when codepath should depend on whether or not we are just deserializing (old fGetSize, fWrite, fRead flags) an additional clause can be used: bool fRead = boost::is_same<Operation, CSerActionUnserialize>(); The IMPLEMENT_SERIALIZE macro will now be a freestanding clause added within class' body (similiar to Qt's Q_OBJECT) to implement GetSerializeSize, Serialize and Unserialize. These are now wrappers around the "SerializationOp" template.
* | add missing header end commentsPhilip Kaufmann2014-08-281-1/+1
|/ | | | | | - ensures a consistent usage in header files - also add a blank line after the copyright header where missing - also remove orphan new-lines at the end of some files
* Merge pull request #4618Pieter Wuille2014-08-241-57/+6
|\ | | | | | | eb0b56b Simplify serialize.h's exception handling (Pieter Wuille)
| * Simplify serialize.h's exception handlingPieter Wuille2014-08-091-57/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove the 'state' and 'exceptmask' from serialize.h's stream implementations, as well as related methods. As exceptmask always included 'failbit', and setstate was always called with bits = failbit, all it did was immediately raise an exception. Get rid of those variables, and replace the setstate with direct exception throwing (which also removes some dead code). As a result, good() is never reached after a failure (there are only 2 calls, one of which is in tests), and can just be replaced by !eof(). fail(), clear(n) and exceptions() are just never called. Delete them.
* | replace int with size_t in stream methodsKamil Domanski2014-08-181-6/+4
| | | | | | | | | | Thus the read(...) and write(...) methods of all stream classes now have identical parameter lists. This will bring these classes one step closer to a common interface.
* | Add a way to limit deserialized string lengthsPieter Wuille2014-08-091-2/+37
|/ | | | and use it for most strings being serialized.
* Break up CAddrMan's IMPLEMENT_SERIALIZEPieter Wuille2014-07-161-0/+29
|
* Avoid undefined behavior using CFlatData in CScript serializationWladimir J. van der Laan2014-06-231-0/+34
| | | | | | | | | | | | | | | `&vch[vch.size()]` and even `&vch[0]` on vectors can cause assertion errors with VC in debug mode. This is the problem mentioned in #4239. The deeper problem with this is that we rely on undefined behavior. - Add `begin_ptr` and `end_ptr` functions that get the beginning and end pointer of vector in a reliable way that copes with empty vectors and doesn't reference outside the vector (see https://stackoverflow.com/questions/1339470/how-to-get-the-address-of-the-stdvector-buffer-start-most-elegantly/1339767#1339767). - Add a convenience constructor to CFlatData that wraps a vector. I added `begin_ptr` and `end_ptr` as separate functions as I imagine they will be useful in more places.
* remove an assignment which is never used.Yoichi Hirai2014-03-281-3/+0
|
* Cleanup code using forward declarations.Brandon Dahler2013-11-101-77/+76
| | | | | | | | | Use misc methods of avoiding unnecesary header includes. Replace int typedefs with int##_t from stdint.h. Replace PRI64[xdu] with PRI[xdu]64 from inttypes.h. Normalize QT_VERSION ifs where possible. Resolve some indirect dependencies as direct ones. Remove extern declarations from .cpp files.
* Merge pull request #3173 from gavinandresen/fuzzmessagesGavin Andresen2013-10-301-2/+2
|\ | | | | -fuzzmessagestest=N : randomly corrupt 1-of-N sent messages
| * Bug fix: CDataStream::GetAndClear() when nReadPos > 0Gavin Andresen2013-10-291-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | Changed CDataStream::GetAndClear() to use the most obvious get get and clear instead of a tricky swap(). Added a unit test for CDataStream insert/erase/GetAndClear. Note: GetAndClear() is not performance critical, it is used only by the send-a-message-to-the-network code. Bug was not noticed before now because the send-a-message code never erased from the stream.
* | Remove redundant insert method in serialize.Pieter Wuille2013-10-261-13/+0
|/ | | | | | | | | This seems to cause problems on recent clang, and looks totally redundant and unused. The const_iterator version is identical to the vector::const_iterator one (which is a typedef thereof). Marking it private (instead of removing) compiles fine, so this version is effectively unused even.
* Merge pull request #3119Pieter Wuille2013-10-201-1/+1
|\ | | | | | | db0e8cc Bump Year Number to 2013 (super3)
| * Bump Year Number to 2013super32013-10-201-1/+1
| |
* | Reject non-canonically-encoded sizesGavin Andresen2013-08-091-0/+6
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The length of vectors, maps, sets, etc are serialized using Write/ReadCompactSize -- which, unfortunately, do not use a unique encoding. So deserializing and then re-serializing a transaction (for example) can give you different bits than you started with. That doesn't cause any problems that we are aware of, but it is exactly the type of subtle mismatch that can lead to exploits. With this pull, reading a non-canonical CompactSize throws an exception, which means nodes will ignore 'tx' or 'block' or other messages that are not properly encoded. Please check my logic... but this change is safe with respect to causing a network split. Old clients that receive non-canonically-encoded transactions or blocks deserialize them into CTransaction/CBlock structures in memory, and then re-serialize them before relaying them to peers. And please check my logic with respect to causing a blockchain split: there are no CompactSize fields in the block header, so the block hash is always canonical. The merkle root in the block header is computed on a vector<CTransaction>, so any non-canonical encoding of the transactions in 'tx' or 'block' messages is erased as they are read into memory by old clients, and does not affect the block hash. And, as noted above, old clients re-serialize (with canonical encoding) 'tx' and 'block' messages before relaying to peers.
* Use per-message send buffer, rather than per connectionPieter Wuille2013-03-291-1/+7
|
* Split off CBlockHeader from CBlockPieter Wuille2012-11-161-4/+0
| | | | | Cleaner and removes the need for the application-specific flags in serialize.h.
* Add CBufferedFilePieter Wuille2012-11-091-0/+144
|
* Compact serialization for variable-length integersPieter Wuille2012-10-201-1/+93
| | | | | | | | | | | | | | | Variable-length integers: bytes are a MSB base-128 encoding of the number. The high bit in each byte signifies whether another digit follows. To make the encoding is one-to-one, one is subtracted from all but the last digit. Thus, the byte sequence a[] with length len, where all but the last byte has bit 128 set, encodes the number: (a[len-1] & 0x7F) + sum(i=1..len-1, 128^i*((a[len-i-1] & 0x7F)+1)) Properties: * Very small (0-127: 1 byte, 128-16511: 2 bytes, 16512-2113663: 3 bytes) * Every integer has exactly one encoding * Encoding does not depend on size of original integer type
* Remove VC6 comment and pointless #ifdef'd benchmark codeWladimir J. van der Laan2012-09-091-52/+0
| | | | | | | | | | | | We're in a wholly different world now, C++-compiler-wise. Current std::stringstream implementations don't have the stated problem anymore, and are just as fast as CDataStream. The #ifdef'd block does not even compile anymore; CDataStream constructor changed, and missing some std::. Also timing in whole seconds is also way too granular to say anything sensible in such microbenchmarks. Just remove it, it can always be found again in git history.
* Fix signed/unsigned warnings in {script,serialize}.h (fixes #1541)Matt Corallo2012-07-021-3/+6
|
* Update License in File HeadersFordy2012-05-181-1/+1
| | | | | | I originally created a pull to replace the "COPYING" in crypter.cpp and crypter.h, but it turned out that COPYING was actually the correct file.
* remove unused typedef in serialize.hPhilip Kaufmann2012-05-011-2/+0
|
* Further reduce header dependenciesPieter Wuille2012-04-171-36/+36
| | | | | | | This commit removes the dependency of serialize.h on PROTOCOL_VERSION, and makes this parameter required instead of implicit. This is much saner, as it makes the places where changing a version number can have an influence obvious.
* Merge pull request #1106 from jgarzik/sign-compareGavin Andresen2012-04-171-2/+2
|\ | | | | Fix many sign-comparison warnings found in bitcoin codebase
| * serialize.h: CAutoFile's read and write may take size_t nSizeJeff Garzik2012-04-151-2/+2
| |
* | Merge pull request #1115 from laanwj/2012_04_cleanupmiscGavin Andresen2012-04-171-51/+0
|\ \ | | | | | | Delete unused, unreachable and commented code, add missing initializer
| * | Remove unused and unreachable codeWladimir J. van der Laan2012-04-171-51/+0
| |/
* / version.h: separate client, net sections. Move more constants to this file.Jeff Garzik2012-04-121-2/+1
|/ | | | | | | | * move PROTOCOL_VERSION to version.h * move CLIENT_VERSION* to version.h, make available past cpp stage * clearly separate client, network version portions of version.h
* remove dependency on serialize.h and util.h for SecureStringWladimir J. van der Laan2012-04-041-104/+2
|
* VC2010 compile fixesWladimir J. van der Laan2012-04-031-1/+4
|
* Begin doxygen-compatible commentsPieter Wuille2012-03-261-18/+16
|
* Fix compilation warning.Matt Corallo2012-02-181-0/+1
|
* Update all copyrights to 2012Gavin Andresen2012-02-071-1/+1
|
* Compile with extra warnings turned on. And more makefile/code tidying up.Gavin Andresen2012-01-121-0/+3
| | | | | | | This turns on most gcc warnings, and removes some unused variables and other code that triggers warnings. Exceptions are: -Wno-sign-compare : triggered by lots of comparisons of signed integer to foo.size(), which is unsigned. -Wno-char-subscripts : triggered by the convert-to-hex functions (I may fix this in a future commit).
* Fix horrific performance found by gmaxwell.Matt Corallo2012-01-041-1/+33
|
* Revert "Use standard C99 (and Qt) types for 64-bit integers"Wladimir J. van der Laan2011-12-211-16/+17
| | | | This reverts commit 21d9f36781604e4ca9fc35dc65265593423b73e9.
* Use standard C99 (and Qt) types for 64-bit integersLuke Dashjr2011-12-201-17/+16
|
* Include limits, not climints (using std::numeric_limits now)Gavin Andresen2011-12-201-1/+1
|
* Use std::numeric_limits<> for typesafe INT_MAX/etcGavin Andresen2011-12-191-4/+4
|
* Cleanup: removed dead code, and use C99 typedefs for int64 (supported by all ↵Gavin Andresen2011-12-191-8/+0
| | | | modern c++ compilers)
* Implement BIP 14 : separate protocol version from client versionGavin Andresen2011-12-191-39/+37
|
* Bump version 0.5.99 (prep for pulling for version 0.6)Gavin Andresen2011-12-161-1/+1
|
* Bump version to 0.5.1Gavin Andresen2011-11-211-1/+1
|