aboutsummaryrefslogtreecommitdiff
path: root/src/serialize.h
AgeCommit message (Collapse)Author
2014-09-14header include cleanupPhilip Kaufmann
- ensures alphabetical ordering for includes etc. in source file headers
2014-09-02Rename IMPLEMENT_SERIALIZE to ADD_SERIALIZE_METHODSPieter Wuille
2014-09-01Merge pull request #4737Pieter Wuille
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)
2014-08-31Use CSizeComputer to avoid counting sizes in SerializationOpPieter Wuille
2014-08-31rework overhauled serialization methods to non-staticKamil Domanski
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.
2014-08-31remove fields of ser_streamplaceholderKamil Domanski
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.
2014-08-31overhaul serialization codeKamil Domanski
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.
2014-08-28add missing header end commentsPhilip Kaufmann
- 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
2014-08-24Merge pull request #4618Pieter Wuille
eb0b56b Simplify serialize.h's exception handling (Pieter Wuille)
2014-08-18replace int with size_t in stream methodsKamil Domanski
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.
2014-08-09Simplify serialize.h's exception handlingPieter Wuille
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.
2014-08-09Add a way to limit deserialized string lengthsPieter Wuille
and use it for most strings being serialized.
2014-07-16Break up CAddrMan's IMPLEMENT_SERIALIZEPieter Wuille
2014-06-23Avoid undefined behavior using CFlatData in CScript serializationWladimir J. van der Laan
`&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.
2014-03-28remove an assignment which is never used.Yoichi Hirai
2013-11-10Cleanup code using forward declarations.Brandon Dahler
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.
2013-10-30Merge pull request #3173 from gavinandresen/fuzzmessagesGavin Andresen
-fuzzmessagestest=N : randomly corrupt 1-of-N sent messages
2013-10-29Bug fix: CDataStream::GetAndClear() when nReadPos > 0Gavin Andresen
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.
2013-10-26Remove redundant insert method in serialize.Pieter Wuille
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.
2013-10-20Merge pull request #3119Pieter Wuille
db0e8cc Bump Year Number to 2013 (super3)
2013-10-20Bump Year Number to 2013super3
2013-08-09Reject non-canonically-encoded sizesGavin Andresen
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.
2013-03-29Use per-message send buffer, rather than per connectionPieter Wuille
2012-11-16Split off CBlockHeader from CBlockPieter Wuille
Cleaner and removes the need for the application-specific flags in serialize.h.
2012-11-09Add CBufferedFilePieter Wuille
2012-10-20Compact serialization for variable-length integersPieter Wuille
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
2012-09-09Remove VC6 comment and pointless #ifdef'd benchmark codeWladimir J. van der Laan
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.
2012-07-02Fix signed/unsigned warnings in {script,serialize}.h (fixes #1541)Matt Corallo
2012-05-18Update License in File HeadersFordy
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.
2012-05-01remove unused typedef in serialize.hPhilip Kaufmann
2012-04-17Further reduce header dependenciesPieter Wuille
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.
2012-04-17Merge pull request #1106 from jgarzik/sign-compareGavin Andresen
Fix many sign-comparison warnings found in bitcoin codebase
2012-04-17Merge pull request #1115 from laanwj/2012_04_cleanupmiscGavin Andresen
Delete unused, unreachable and commented code, add missing initializer
2012-04-17Remove unused and unreachable codeWladimir J. van der Laan
2012-04-15serialize.h: CAutoFile's read and write may take size_t nSizeJeff Garzik
2012-04-12version.h: separate client, net sections. Move more constants to this file.Jeff Garzik
* 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
2012-04-04remove dependency on serialize.h and util.h for SecureStringWladimir J. van der Laan
2012-04-03VC2010 compile fixesWladimir J. van der Laan
2012-03-26Begin doxygen-compatible commentsPieter Wuille
2012-02-18Fix compilation warning.Matt Corallo
2012-02-07Update all copyrights to 2012Gavin Andresen
2012-01-12Compile with extra warnings turned on. And more makefile/code tidying up.Gavin Andresen
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).
2012-01-04Fix horrific performance found by gmaxwell.Matt Corallo
2011-12-21Revert "Use standard C99 (and Qt) types for 64-bit integers"Wladimir J. van der Laan
This reverts commit 21d9f36781604e4ca9fc35dc65265593423b73e9.
2011-12-20Use standard C99 (and Qt) types for 64-bit integersLuke Dashjr
2011-12-20Include limits, not climints (using std::numeric_limits now)Gavin Andresen
2011-12-19Use std::numeric_limits<> for typesafe INT_MAX/etcGavin Andresen
2011-12-19Cleanup: removed dead code, and use C99 typedefs for int64 (supported by all ↵Gavin Andresen
modern c++ compilers)
2011-12-19Implement BIP 14 : separate protocol version from client versionGavin Andresen
2011-12-16Bump version 0.5.99 (prep for pulling for version 0.6)Gavin Andresen