aboutsummaryrefslogtreecommitdiffstats
path: root/ethdb/database_test.go
Commit message (Expand)AuthorAgeFilesLines
* cmd, eth, ethdb, node: prioritise chaindata for resources, bump cachePéter Szilágyi2016-03-091-1/+1
* Merge pull request #1515 from fjl/license-fixesJeffrey Wilcke2015-07-281-1/+1
|\
| * all: fix license headers one more timeFelix Lange2015-07-241-1/+1
* | Merge pull request #1510 from fjl/license-fixesJeffrey Wilcke2015-07-231-4/+4
|\|
| * all: update license headers to distiguish GPL/LGPLFelix Lange2015-07-231-4/+4
* | cmd, core, eth, ethdb: cache flag to allocate memory for db internal usePéter Szilágyi2015-07-221-2/+1
|/
* all: update license informationFelix Lange2015-07-071-0/+16
* removed redundant newlines in import blockBas van Kervel2015-05-121-1/+0
* replaced several path.* with filepath.* which is platform independentBas van Kervel2015-05-121-2/+3
* Queued level db writes and batch writes. Closes #647obscuren2015-04-081-17/+10
* cmd/evm, core, ethdb, state, tests/helper: remove ReadConfig callsFelix Lange2015-03-101-2/+0
* Compress data on db level. Closes #174obscuren2014-11-031-2/+24
* The great mergeobscuren2014-02-151-0/+6
version. // // The go-ethereum library 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 Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. package enr import ( "crypto/ecdsa" "fmt" "io" "net" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/rlp" ) // Entry is implemented by known node record entry types. // // To define a new entry that is to be included in a node record, // create a Go type that satisfies this interface. The type should // also implement rlp.Decoder if additional checks are needed on the value. type Entry interface { ENRKey() string } type generic struct { key string value interface{} } func (g generic) ENRKey() string { return g.key } func (g generic) EncodeRLP(w io.Writer) error { return rlp.Encode(w, g.value) } func (g *generic) DecodeRLP(s *rlp.Stream) error { return s.Decode(g.value) } // WithEntry wraps any value with a key name. It can be used to set and load arbitrary values // in a record. The value v must be supported by rlp. To use WithEntry with Load, the value // must be a pointer. func WithEntry(k string, v interface{}) Entry { return &generic{key: k, value: v} } // DiscPort is the "discv5" key, which holds the UDP port for discovery v5. type DiscPort uint16 func (v DiscPort) ENRKey() string { return "discv5" } // ID is the "id" key, which holds the name of the identity scheme. type ID string func (v ID) ENRKey() string { return "id" } // IP4 is the "ip4" key, which holds a 4-byte IPv4 address. type IP4 net.IP func (v IP4) ENRKey() string { return "ip4" } // EncodeRLP implements rlp.Encoder. func (v IP4) EncodeRLP(w io.Writer) error { ip4 := net.IP(v).To4() if ip4 == nil { return fmt.Errorf("invalid IPv4 address: %v", v) } return rlp.Encode(w, ip4) } // DecodeRLP implements rlp.Decoder. func (v *IP4) DecodeRLP(s *rlp.Stream) error { if err := s.Decode((*net.IP)(v)); err != nil { return err } if len(*v) != 4 { return fmt.Errorf("invalid IPv4 address, want 4 bytes: %v", *v) } return nil } // IP6 is the "ip6" key, which holds a 16-byte IPv6 address. type IP6 net.IP func (v IP6) ENRKey() string { return "ip6" } // EncodeRLP implements rlp.Encoder. func (v IP6) EncodeRLP(w io.Writer) error { ip6 := net.IP(v) return rlp.Encode(w, ip6) } // DecodeRLP implements rlp.Decoder. func (v *IP6) DecodeRLP(s *rlp.Stream) error { if err := s.Decode((*net.IP)(v)); err != nil { return err } if len(*v) != 16 { return fmt.Errorf("invalid IPv6 address, want 16 bytes: %v", *v) } return nil } // Secp256k1 is the "secp256k1" key, which holds a public key. type Secp256k1 ecdsa.PublicKey func (v Secp256k1) ENRKey() string { return "secp256k1" } // EncodeRLP implements rlp.Encoder. func (v Secp256k1) EncodeRLP(w io.Writer) error { return rlp.Encode(w, crypto.CompressPubkey((*ecdsa.PublicKey)(&v))) } // DecodeRLP implements rlp.Decoder. func (v *Secp256k1) DecodeRLP(s *rlp.Stream) error { buf, err := s.Bytes() if err != nil { return err } pk, err := crypto.DecompressPubkey(buf) if err != nil { return err } *v = (Secp256k1)(*pk) return nil } // KeyError is an error related to a key. type KeyError struct { Key string Err error } // Error implements error. func (err *KeyError) Error() string { if err.Err == errNotFound { return fmt.Sprintf("missing ENR key %q", err.Key) } return fmt.Sprintf("ENR key %q: %v", err.Key, err.Err) } // IsNotFound reports whether the given error means that a key/value pair is // missing from a record. func IsNotFound(err error) bool { kerr, ok := err.(*KeyError) return ok && kerr.Err == errNotFound }