@ -0,0 +1,19 @@ | |||||
# top-most EditorConfig file | |||||
root = true | |||||
# Unix-style newlines with a newline ending every file | |||||
[*] | |||||
charset = utf-8 | |||||
end_of_line = lf | |||||
insert_final_newline = true | |||||
trim_trailing_whitespace = true | |||||
[Makefile] | |||||
indent_style = tab | |||||
[*.sh] | |||||
indent_style = tab | |||||
[*.proto] | |||||
indent_style = space | |||||
indent_size = 2 |
@ -0,0 +1,5 @@ | |||||
*.sw[opqr] | |||||
vendor | |||||
.glide | |||||
pubsub/query/fuzz_test/output |
@ -0,0 +1,438 @@ | |||||
# Changelog | |||||
## 0.9.0 | |||||
*June 24th, 2018* | |||||
BREAKING: | |||||
- [events, pubsub] Removed - moved to github.com/tendermint/tendermint | |||||
- [merkle] Use 20-bytes of SHA256 instead of RIPEMD160. NOTE: this package is | |||||
moving to github.com/tendermint/go-crypto ! | |||||
- [common] Remove gogoproto from KVPair types | |||||
- [common] Error simplification, #220 | |||||
FEATURES: | |||||
- [db/remotedb] New DB type using an external CLevelDB process via | |||||
GRPC | |||||
- [autofile] logjack command for piping stdin to a rotating file | |||||
- [bech32] New package. NOTE: should move out of here - it's just two small | |||||
functions | |||||
- [common] ColoredBytes([]byte) string for printing mixed ascii and bytes | |||||
- [db] DebugDB uses ColoredBytes() | |||||
## 0.8.4 | |||||
*June 5, 2018* | |||||
IMPROVEMENTS: | |||||
- [autofile] Flush on Stop; Close() method to Flush and close file | |||||
## 0.8.3 | |||||
*May 21, 2018* | |||||
FEATURES: | |||||
- [common] ASCIITrim() | |||||
## 0.8.2 (April 23rd, 2018) | |||||
FEATURES: | |||||
- [pubsub] TagMap, NewTagMap | |||||
- [merkle] SimpleProofsFromMap() | |||||
- [common] IsASCIIText() | |||||
- [common] PrefixEndBytes // e.g. increment or nil | |||||
- [common] BitArray.MarshalJSON/.UnmarshalJSON | |||||
- [common] BitArray uses 'x' not 'X' for String() and above. | |||||
- [db] DebugDB shows better colorized output | |||||
BUG FIXES: | |||||
- [common] Fix TestParallelAbort nondeterministic failure #201/#202 | |||||
- [db] PrefixDB Iterator/ReverseIterator fixes | |||||
- [db] DebugDB fixes | |||||
## 0.8.1 (April 5th, 2018) | |||||
FEATURES: | |||||
- [common] Error.Error() includes cause | |||||
- [common] IsEmpty() for 0 length | |||||
## 0.8.0 (April 4th, 2018) | |||||
BREAKING: | |||||
- [merkle] `PutVarint->PutUvarint` in encodeByteSlice | |||||
- [db] batch.WriteSync() | |||||
- [common] Refactored and fixed `Parallel` function | |||||
- [common] Refactored `Rand` functionality | |||||
- [common] Remove unused `Right/LeftPadString` functions | |||||
- [common] Remove StackError, introduce Error interface (to replace use of pkg/errors) | |||||
FEATURES: | |||||
- [db] NewPrefixDB for a DB with all keys prefixed | |||||
- [db] NewDebugDB prints everything during operation | |||||
- [common] SplitAndTrim func | |||||
- [common] rand.Float64(), rand.Int63n(n), rand.Int31n(n) and global equivalents | |||||
- [common] HexBytes Format() | |||||
BUG FIXES: | |||||
- [pubsub] Fix unsubscribing | |||||
- [cli] Return config errors | |||||
- [common] Fix WriteFileAtomic Windows bug | |||||
## 0.7.1 (March 22, 2018) | |||||
IMPROVEMENTS: | |||||
- glide -> dep | |||||
BUG FIXES: | |||||
- [common] Fix panic in NewBitArray for negative bits | |||||
- [common] Fix and simplify WriteFileAtomic so it cleans up properly | |||||
## 0.7.0 (February 20, 2018) | |||||
BREAKING: | |||||
- [db] Major API upgrade. See `db/types.go`. | |||||
- [common] added `Quit() <-chan struct{}` to Service interface. | |||||
The returned channel is closed when service is stopped. | |||||
- [common] Remove HTTP functions | |||||
- [common] Heap.Push takes an `int`, new Heap.PushComparable takes the comparable. | |||||
- [logger] Removed. Use `log` | |||||
- [merkle] Major API updade - uses cmn.KVPairs. | |||||
- [cli] WriteDemoConfig -> WriteConfigValues | |||||
- [all] Remove go-wire dependency! | |||||
FEATURES: | |||||
- [db] New FSDB that uses the filesystem directly | |||||
- [common] HexBytes | |||||
- [common] KVPair and KI64Pair (protobuf based key-value pair objects) | |||||
IMPROVEMENTS: | |||||
- [clist] add WaitChan() to CList, NextWaitChan() and PrevWaitChan() | |||||
to CElement. These can be used instead of blocking `*Wait()` methods | |||||
if you need to be able to send quit signal and not block forever | |||||
- [common] IsHex handles 0x-prefix | |||||
BUG FIXES: | |||||
- [common] BitArray check for nil arguments | |||||
- [common] Fix memory leak in RepeatTimer | |||||
## 0.6.0 (December 29, 2017) | |||||
BREAKING: | |||||
- [cli] remove --root | |||||
- [pubsub] add String() method to Query interface | |||||
IMPROVEMENTS: | |||||
- [common] use a thread-safe and well seeded non-crypto rng | |||||
BUG FIXES | |||||
- [clist] fix misuse of wait group | |||||
- [common] introduce Ticker interface and logicalTicker for better testing of timers | |||||
## 0.5.0 (December 5, 2017) | |||||
BREAKING: | |||||
- [common] replace Service#Start, Service#Stop first return value (bool) with an | |||||
error (ErrAlreadyStarted, ErrAlreadyStopped) | |||||
- [common] replace Service#Reset first return value (bool) with an error | |||||
- [process] removed | |||||
FEATURES: | |||||
- [common] IntInSlice and StringInSlice functions | |||||
- [pubsub/query] introduce `Condition` struct, expose `Operator`, and add `query.Conditions()` | |||||
## 0.4.1 (November 27, 2017) | |||||
FEATURES: | |||||
- [common] `Keys()` method on `CMap` | |||||
IMPROVEMENTS: | |||||
- [log] complex types now encoded as "%+v" by default if `String()` method is undefined (previously resulted in error) | |||||
- [log] logger logs its own errors | |||||
BUG FIXES: | |||||
- [common] fixed `Kill()` to build on Windows (Windows does not have `syscall.Kill`) | |||||
## 0.4.0 (October 26, 2017) | |||||
BREAKING: | |||||
- [common] GoPath is now a function | |||||
- [db] `DB` and `Iterator` interfaces have new methods to better support iteration | |||||
FEATURES: | |||||
- [autofile] `Read([]byte)` and `Write([]byte)` methods on `Group` to support binary WAL | |||||
- [common] `Kill()` sends SIGTERM to the current process | |||||
IMPROVEMENTS: | |||||
- comments and linting | |||||
BUG FIXES: | |||||
- [events] fix allocation error prefixing cache with 1000 empty events | |||||
## 0.3.2 (October 2, 2017) | |||||
BUG FIXES: | |||||
- [autofile] fix AutoFile.Sync() to open file if it's been closed | |||||
- [db] fix MemDb.Close() to not empty the database (ie. its just a noop) | |||||
## 0.3.1 (September 22, 2017) | |||||
BUG FIXES: | |||||
- [common] fix WriteFileAtomic to not use /tmp, which can be on another device | |||||
## 0.3.0 (September 22, 2017) | |||||
BREAKING CHANGES: | |||||
- [log] logger functions no longer returns an error | |||||
- [common] NewBaseService takes the new logger | |||||
- [cli] RunCaptureWithArgs now captures stderr and stdout | |||||
- +func RunCaptureWithArgs(cmd Executable, args []string, env map[string]string) (stdout, stderr string, err error) | |||||
- -func RunCaptureWithArgs(cmd Executable, args []string, env map[string]string) (output string, err error) | |||||
FEATURES: | |||||
- [common] various common HTTP functionality | |||||
- [common] Date range parsing from string (ex. "2015-12-31:2017-12-31") | |||||
- [common] ProtocolAndAddress function | |||||
- [pubsub] New package for publish-subscribe with more advanced filtering | |||||
BUG FIXES: | |||||
- [common] fix atomicity of WriteFileAtomic by calling fsync | |||||
- [db] fix memDb iteration index out of range | |||||
- [autofile] fix Flush by calling fsync | |||||
## 0.2.2 (June 16, 2017) | |||||
FEATURES: | |||||
- [common] IsHex and StripHex for handling `0x` prefixed hex strings | |||||
- [log] NewTracingLogger returns a logger that output error traces, ala `github.com/pkg/errors` | |||||
IMPROVEMENTS: | |||||
- [cli] Error handling for tests | |||||
- [cli] Support dashes in ENV variables | |||||
BUG FIXES: | |||||
- [flowrate] Fix non-deterministic test failures | |||||
## 0.2.1 (June 2, 2017) | |||||
FEATURES: | |||||
- [cli] Log level parsing moved here from tendermint repo | |||||
## 0.2.0 (May 18, 2017) | |||||
BREAKING CHANGES: | |||||
- [common] NewBaseService takes the new logger | |||||
FEATURES: | |||||
- [cli] New library to standardize building command line tools | |||||
- [log] New logging library | |||||
BUG FIXES: | |||||
- [autofile] Close file before rotating | |||||
## 0.1.0 (May 1, 2017) | |||||
Initial release, combines what were previously independent repos: | |||||
- go-autofile | |||||
- go-clist | |||||
- go-common | |||||
- go-db | |||||
- go-events | |||||
- go-flowrate | |||||
- go-logger | |||||
- go-merkle | |||||
- go-process | |||||
@ -0,0 +1,3 @@ | |||||
* @melekes @ebuchman | |||||
*.md @zramsay | |||||
*.rst @zramsay |
@ -0,0 +1,281 @@ | |||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. | |||||
[[projects]] | |||||
branch = "master" | |||||
name = "github.com/btcsuite/btcutil" | |||||
packages = ["bech32"] | |||||
revision = "d4cc87b860166d00d6b5b9e0d3b3d71d6088d4d4" | |||||
[[projects]] | |||||
name = "github.com/davecgh/go-spew" | |||||
packages = ["spew"] | |||||
revision = "346938d642f2ec3594ed81d874461961cd0faa76" | |||||
version = "v1.1.0" | |||||
[[projects]] | |||||
branch = "master" | |||||
name = "github.com/fortytw2/leaktest" | |||||
packages = ["."] | |||||
revision = "3b724c3d7b8729a35bf4e577f71653aec6e53513" | |||||
[[projects]] | |||||
name = "github.com/fsnotify/fsnotify" | |||||
packages = ["."] | |||||
revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9" | |||||
version = "v1.4.7" | |||||
[[projects]] | |||||
name = "github.com/go-kit/kit" | |||||
packages = [ | |||||
"log", | |||||
"log/level", | |||||
"log/term" | |||||
] | |||||
revision = "4dc7be5d2d12881735283bcab7352178e190fc71" | |||||
version = "v0.6.0" | |||||
[[projects]] | |||||
name = "github.com/go-logfmt/logfmt" | |||||
packages = ["."] | |||||
revision = "390ab7935ee28ec6b286364bba9b4dd6410cb3d5" | |||||
version = "v0.3.0" | |||||
[[projects]] | |||||
name = "github.com/go-stack/stack" | |||||
packages = ["."] | |||||
revision = "817915b46b97fd7bb80e8ab6b69f01a53ac3eebf" | |||||
version = "v1.6.0" | |||||
[[projects]] | |||||
name = "github.com/golang/protobuf" | |||||
packages = [ | |||||
"proto", | |||||
"ptypes", | |||||
"ptypes/any", | |||||
"ptypes/duration", | |||||
"ptypes/timestamp" | |||||
] | |||||
revision = "b4deda0973fb4c70b50d226b1af49f3da59f5265" | |||||
version = "v1.1.0" | |||||
[[projects]] | |||||
branch = "master" | |||||
name = "github.com/golang/snappy" | |||||
packages = ["."] | |||||
revision = "553a641470496b2327abcac10b36396bd98e45c9" | |||||
[[projects]] | |||||
branch = "master" | |||||
name = "github.com/hashicorp/hcl" | |||||
packages = [ | |||||
".", | |||||
"hcl/ast", | |||||
"hcl/parser", | |||||
"hcl/scanner", | |||||
"hcl/strconv", | |||||
"hcl/token", | |||||
"json/parser", | |||||
"json/scanner", | |||||
"json/token" | |||||
] | |||||
revision = "23c074d0eceb2b8a5bfdbb271ab780cde70f05a8" | |||||
[[projects]] | |||||
name = "github.com/inconshreveable/mousetrap" | |||||
packages = ["."] | |||||
revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" | |||||
version = "v1.0" | |||||
[[projects]] | |||||
branch = "master" | |||||
name = "github.com/jmhodges/levigo" | |||||
packages = ["."] | |||||
revision = "c42d9e0ca023e2198120196f842701bb4c55d7b9" | |||||
[[projects]] | |||||
branch = "master" | |||||
name = "github.com/kr/logfmt" | |||||
packages = ["."] | |||||
revision = "b84e30acd515aadc4b783ad4ff83aff3299bdfe0" | |||||
[[projects]] | |||||
name = "github.com/magiconair/properties" | |||||
packages = ["."] | |||||
revision = "49d762b9817ba1c2e9d0c69183c2b4a8b8f1d934" | |||||
[[projects]] | |||||
name = "github.com/mitchellh/mapstructure" | |||||
packages = ["."] | |||||
revision = "b4575eea38cca1123ec2dc90c26529b5c5acfcff" | |||||
[[projects]] | |||||
name = "github.com/pelletier/go-toml" | |||||
packages = ["."] | |||||
revision = "acdc4509485b587f5e675510c4f2c63e90ff68a8" | |||||
version = "v1.1.0" | |||||
[[projects]] | |||||
name = "github.com/pkg/errors" | |||||
packages = ["."] | |||||
revision = "645ef00459ed84a119197bfb8d8205042c6df63d" | |||||
version = "v0.8.0" | |||||
[[projects]] | |||||
name = "github.com/pmezard/go-difflib" | |||||
packages = ["difflib"] | |||||
revision = "792786c7400a136282c1664665ae0a8db921c6c2" | |||||
version = "v1.0.0" | |||||
[[projects]] | |||||
name = "github.com/spf13/afero" | |||||
packages = [ | |||||
".", | |||||
"mem" | |||||
] | |||||
revision = "bb8f1927f2a9d3ab41c9340aa034f6b803f4359c" | |||||
version = "v1.0.2" | |||||
[[projects]] | |||||
name = "github.com/spf13/cast" | |||||
packages = ["."] | |||||
revision = "acbeb36b902d72a7a4c18e8f3241075e7ab763e4" | |||||
version = "v1.1.0" | |||||
[[projects]] | |||||
name = "github.com/spf13/cobra" | |||||
packages = ["."] | |||||
revision = "7b2c5ac9fc04fc5efafb60700713d4fa609b777b" | |||||
version = "v0.0.1" | |||||
[[projects]] | |||||
branch = "master" | |||||
name = "github.com/spf13/jwalterweatherman" | |||||
packages = ["."] | |||||
revision = "7c0cea34c8ece3fbeb2b27ab9b59511d360fb394" | |||||
[[projects]] | |||||
name = "github.com/spf13/pflag" | |||||
packages = ["."] | |||||
revision = "97afa5e7ca8a08a383cb259e06636b5e2cc7897f" | |||||
[[projects]] | |||||
name = "github.com/spf13/viper" | |||||
packages = ["."] | |||||
revision = "25b30aa063fc18e48662b86996252eabdcf2f0c7" | |||||
version = "v1.0.0" | |||||
[[projects]] | |||||
name = "github.com/stretchr/testify" | |||||
packages = [ | |||||
"assert", | |||||
"require" | |||||
] | |||||
revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71" | |||||
version = "v1.2.1" | |||||
[[projects]] | |||||
name = "github.com/syndtr/goleveldb" | |||||
packages = [ | |||||
"leveldb", | |||||
"leveldb/cache", | |||||
"leveldb/comparer", | |||||
"leveldb/errors", | |||||
"leveldb/filter", | |||||
"leveldb/iterator", | |||||
"leveldb/journal", | |||||
"leveldb/memdb", | |||||
"leveldb/opt", | |||||
"leveldb/storage", | |||||
"leveldb/table", | |||||
"leveldb/util" | |||||
] | |||||
revision = "b89cc31ef7977104127d34c1bd31ebd1a9db2199" | |||||
[[projects]] | |||||
branch = "master" | |||||
name = "golang.org/x/net" | |||||
packages = [ | |||||
"context", | |||||
"http/httpguts", | |||||
"http2", | |||||
"http2/hpack", | |||||
"idna", | |||||
"internal/timeseries", | |||||
"trace" | |||||
] | |||||
revision = "d11bb6cd8e3c4e60239c9cb20ef68586d74500d0" | |||||
[[projects]] | |||||
name = "golang.org/x/sys" | |||||
packages = ["unix"] | |||||
revision = "37707fdb30a5b38865cfb95e5aab41707daec7fd" | |||||
[[projects]] | |||||
name = "golang.org/x/text" | |||||
packages = [ | |||||
"collate", | |||||
"collate/build", | |||||
"internal/colltab", | |||||
"internal/gen", | |||||
"internal/tag", | |||||
"internal/triegen", | |||||
"internal/ucd", | |||||
"language", | |||||
"secure/bidirule", | |||||
"transform", | |||||
"unicode/bidi", | |||||
"unicode/cldr", | |||||
"unicode/norm", | |||||
"unicode/rangetable" | |||||
] | |||||
revision = "c01e4764d870b77f8abe5096ee19ad20d80e8075" | |||||
[[projects]] | |||||
branch = "master" | |||||
name = "google.golang.org/genproto" | |||||
packages = ["googleapis/rpc/status"] | |||||
revision = "86e600f69ee4704c6efbf6a2a40a5c10700e76c2" | |||||
[[projects]] | |||||
name = "google.golang.org/grpc" | |||||
packages = [ | |||||
".", | |||||
"balancer", | |||||
"balancer/base", | |||||
"balancer/roundrobin", | |||||
"codes", | |||||
"connectivity", | |||||
"credentials", | |||||
"encoding", | |||||
"encoding/proto", | |||||
"grpclb/grpc_lb_v1/messages", | |||||
"grpclog", | |||||
"internal", | |||||
"keepalive", | |||||
"metadata", | |||||
"naming", | |||||
"peer", | |||||
"resolver", | |||||
"resolver/dns", | |||||
"resolver/passthrough", | |||||
"stats", | |||||
"status", | |||||
"tap", | |||||
"transport" | |||||
] | |||||
revision = "d11072e7ca9811b1100b80ca0269ac831f06d024" | |||||
version = "v1.11.3" | |||||
[[projects]] | |||||
name = "gopkg.in/yaml.v2" | |||||
packages = ["."] | |||||
revision = "d670f9405373e636a5a2765eea47fac0c9bc91a4" | |||||
version = "v2.0.0" | |||||
[solve-meta] | |||||
analyzer-name = "dep" | |||||
analyzer-version = 1 | |||||
inputs-digest = "e0c0af880b57928787ea78a820abefd2759e6aee4cba18e67ab36b80e62ad581" | |||||
solver-name = "gps-cdcl" | |||||
solver-version = 1 |
@ -0,0 +1,69 @@ | |||||
# Gopkg.toml example | |||||
# | |||||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | |||||
# for detailed Gopkg.toml documentation. | |||||
# | |||||
# required = ["github.com/user/thing/cmd/thing"] | |||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | |||||
# | |||||
# [[constraint]] | |||||
# name = "github.com/user/project" | |||||
# version = "1.0.0" | |||||
# | |||||
# [[constraint]] | |||||
# name = "github.com/user/project2" | |||||
# branch = "dev" | |||||
# source = "github.com/myfork/project2" | |||||
# | |||||
# [[override]] | |||||
# name = "github.com/x/y" | |||||
# version = "2.4.0" | |||||
# | |||||
# [prune] | |||||
# non-go = false | |||||
# go-tests = true | |||||
# unused-packages = true | |||||
[[constraint]] | |||||
branch = "master" | |||||
name = "github.com/fortytw2/leaktest" | |||||
[[constraint]] | |||||
name = "github.com/go-kit/kit" | |||||
version = "0.6.0" | |||||
[[constraint]] | |||||
name = "github.com/go-logfmt/logfmt" | |||||
version = "0.3.0" | |||||
[[constraint]] | |||||
name = "github.com/gogo/protobuf" | |||||
version = "1.0.0" | |||||
[[constraint]] | |||||
branch = "master" | |||||
name = "github.com/jmhodges/levigo" | |||||
[[constraint]] | |||||
name = "github.com/pkg/errors" | |||||
version = "0.8.0" | |||||
[[constraint]] | |||||
name = "github.com/spf13/cobra" | |||||
version = "0.0.1" | |||||
[[constraint]] | |||||
name = "github.com/spf13/viper" | |||||
version = "1.0.0" | |||||
[[constraint]] | |||||
name = "github.com/stretchr/testify" | |||||
version = "1.2.1" | |||||
[[constraint]] | |||||
name = "github.com/btcsuite/btcutil" | |||||
branch ="master" | |||||
[prune] | |||||
go-tests = true | |||||
unused-packages = true |
@ -0,0 +1,193 @@ | |||||
Tendermint Libraries | |||||
Copyright (C) 2017 Tendermint | |||||
Apache License | |||||
Version 2.0, January 2004 | |||||
https://www.apache.org/licenses/ | |||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION | |||||
1. Definitions. | |||||
"License" shall mean the terms and conditions for use, reproduction, | |||||
and distribution as defined by Sections 1 through 9 of this document. | |||||
"Licensor" shall mean the copyright owner or entity authorized by | |||||
the copyright owner that is granting the License. | |||||
"Legal Entity" shall mean the union of the acting entity and all | |||||
other entities that control, are controlled by, or are under common | |||||
control with that entity. For the purposes of this definition, | |||||
"control" means (i) the power, direct or indirect, to cause the | |||||
direction or management of such entity, whether by contract or | |||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the | |||||
outstanding shares, or (iii) beneficial ownership of such entity. | |||||
"You" (or "Your") shall mean an individual or Legal Entity | |||||
exercising permissions granted by this License. | |||||
"Source" form shall mean the preferred form for making modifications, | |||||
including but not limited to software source code, documentation | |||||
source, and configuration files. | |||||
"Object" form shall mean any form resulting from mechanical | |||||
transformation or translation of a Source form, including but | |||||
not limited to compiled object code, generated documentation, | |||||
and conversions to other media types. | |||||
"Work" shall mean the work of authorship, whether in Source or | |||||
Object form, made available under the License, as indicated by a | |||||
copyright notice that is included in or attached to the work | |||||
(an example is provided in the Appendix below). | |||||
"Derivative Works" shall mean any work, whether in Source or Object | |||||
form, that is based on (or derived from) the Work and for which the | |||||
editorial revisions, annotations, elaborations, or other modifications | |||||
represent, as a whole, an original work of authorship. For the purposes | |||||
of this License, Derivative Works shall not include works that remain | |||||
separable from, or merely link (or bind by name) to the interfaces of, | |||||
the Work and Derivative Works thereof. | |||||
"Contribution" shall mean any work of authorship, including | |||||
the original version of the Work and any modifications or additions | |||||
to that Work or Derivative Works thereof, that is intentionally | |||||
submitted to Licensor for inclusion in the Work by the copyright owner | |||||
or by an individual or Legal Entity authorized to submit on behalf of | |||||
the copyright owner. For the purposes of this definition, "submitted" | |||||
means any form of electronic, verbal, or written communication sent | |||||
to the Licensor or its representatives, including but not limited to | |||||
communication on electronic mailing lists, source code control systems, | |||||
and issue tracking systems that are managed by, or on behalf of, the | |||||
Licensor for the purpose of discussing and improving the Work, but | |||||
excluding communication that is conspicuously marked or otherwise | |||||
designated in writing by the copyright owner as "Not a Contribution." | |||||
"Contributor" shall mean Licensor and any individual or Legal Entity | |||||
on behalf of whom a Contribution has been received by Licensor and | |||||
subsequently incorporated within the Work. | |||||
2. Grant of Copyright License. Subject to the terms and conditions of | |||||
this License, each Contributor hereby grants to You a perpetual, | |||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable | |||||
copyright license to reproduce, prepare Derivative Works of, | |||||
publicly display, publicly perform, sublicense, and distribute the | |||||
Work and such Derivative Works in Source or Object form. | |||||
3. Grant of Patent License. Subject to the terms and conditions of | |||||
this License, each Contributor hereby grants to You a perpetual, | |||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable | |||||
(except as stated in this section) patent license to make, have made, | |||||
use, offer to sell, sell, import, and otherwise transfer the Work, | |||||
where such license applies only to those patent claims licensable | |||||
by such Contributor that are necessarily infringed by their | |||||
Contribution(s) alone or by combination of their Contribution(s) | |||||
with the Work to which such Contribution(s) was submitted. If You | |||||
institute patent litigation against any entity (including a | |||||
cross-claim or counterclaim in a lawsuit) alleging that the Work | |||||
or a Contribution incorporated within the Work constitutes direct | |||||
or contributory patent infringement, then any patent licenses | |||||
granted to You under this License for that Work shall terminate | |||||
as of the date such litigation is filed. | |||||
4. Redistribution. You may reproduce and distribute copies of the | |||||
Work or Derivative Works thereof in any medium, with or without | |||||
modifications, and in Source or Object form, provided that You | |||||
meet the following conditions: | |||||
(a) You must give any other recipients of the Work or | |||||
Derivative Works a copy of this License; and | |||||
(b) You must cause any modified files to carry prominent notices | |||||
stating that You changed the files; and | |||||
(c) You must retain, in the Source form of any Derivative Works | |||||
that You distribute, all copyright, patent, trademark, and | |||||
attribution notices from the Source form of the Work, | |||||
excluding those notices that do not pertain to any part of | |||||
the Derivative Works; and | |||||
(d) If the Work includes a "NOTICE" text file as part of its | |||||
distribution, then any Derivative Works that You distribute must | |||||
include a readable copy of the attribution notices contained | |||||
within such NOTICE file, excluding those notices that do not | |||||
pertain to any part of the Derivative Works, in at least one | |||||
of the following places: within a NOTICE text file distributed | |||||
as part of the Derivative Works; within the Source form or | |||||
documentation, if provided along with the Derivative Works; or, | |||||
within a display generated by the Derivative Works, if and | |||||
wherever such third-party notices normally appear. The contents | |||||
of the NOTICE file are for informational purposes only and | |||||
do not modify the License. You may add Your own attribution | |||||
notices within Derivative Works that You distribute, alongside | |||||
or as an addendum to the NOTICE text from the Work, provided | |||||
that such additional attribution notices cannot be construed | |||||
as modifying the License. | |||||
You may add Your own copyright statement to Your modifications and | |||||
may provide additional or different license terms and conditions | |||||
for use, reproduction, or distribution of Your modifications, or | |||||
for any such Derivative Works as a whole, provided Your use, | |||||
reproduction, and distribution of the Work otherwise complies with | |||||
the conditions stated in this License. | |||||
5. Submission of Contributions. Unless You explicitly state otherwise, | |||||
any Contribution intentionally submitted for inclusion in the Work | |||||
by You to the Licensor shall be under the terms and conditions of | |||||
this License, without any additional terms or conditions. | |||||
Notwithstanding the above, nothing herein shall supersede or modify | |||||
the terms of any separate license agreement you may have executed | |||||
with Licensor regarding such Contributions. | |||||
6. Trademarks. This License does not grant permission to use the trade | |||||
names, trademarks, service marks, or product names of the Licensor, | |||||
except as required for reasonable and customary use in describing the | |||||
origin of the Work and reproducing the content of the NOTICE file. | |||||
7. Disclaimer of Warranty. Unless required by applicable law or | |||||
agreed to in writing, Licensor provides the Work (and each | |||||
Contributor provides its Contributions) on an "AS IS" BASIS, | |||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | |||||
implied, including, without limitation, any warranties or conditions | |||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A | |||||
PARTICULAR PURPOSE. You are solely responsible for determining the | |||||
appropriateness of using or redistributing the Work and assume any | |||||
risks associated with Your exercise of permissions under this License. | |||||
8. Limitation of Liability. In no event and under no legal theory, | |||||
whether in tort (including negligence), contract, or otherwise, | |||||
unless required by applicable law (such as deliberate and grossly | |||||
negligent acts) or agreed to in writing, shall any Contributor be | |||||
liable to You for damages, including any direct, indirect, special, | |||||
incidental, or consequential damages of any character arising as a | |||||
result of this License or out of the use or inability to use the | |||||
Work (including but not limited to damages for loss of goodwill, | |||||
work stoppage, computer failure or malfunction, or any and all | |||||
other commercial damages or losses), even if such Contributor | |||||
has been advised of the possibility of such damages. | |||||
9. Accepting Warranty or Additional Liability. While redistributing | |||||
the Work or Derivative Works thereof, You may choose to offer, | |||||
and charge a fee for, acceptance of support, warranty, indemnity, | |||||
or other liability obligations and/or rights consistent with this | |||||
License. However, in accepting such obligations, You may act only | |||||
on Your own behalf and on Your sole responsibility, not on behalf | |||||
of any other Contributor, and only if You agree to indemnify, | |||||
defend, and hold each Contributor harmless for any liability | |||||
incurred by, or claims asserted against, such Contributor by reason | |||||
of your accepting any such warranty or additional liability. | |||||
END OF TERMS AND CONDITIONS | |||||
Licensed under the Apache License, Version 2.0 (the "License"); | |||||
you may not use this file except in compliance with the License. | |||||
You may obtain a copy of the License at | |||||
https://www.apache.org/licenses/LICENSE-2.0 | |||||
Unless required by applicable law or agreed to in writing, software | |||||
distributed under the License is distributed on an "AS IS" BASIS, | |||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
See the License for the specific language governing permissions and | |||||
limitations under the License. |
@ -0,0 +1,137 @@ | |||||
GOTOOLS = \ | |||||
github.com/golang/dep/cmd/dep \ | |||||
github.com/golang/protobuf/protoc-gen-go \ | |||||
github.com/square/certstrap | |||||
# github.com/alecthomas/gometalinter.v2 \ | |||||
GOTOOLS_CHECK = dep gometalinter.v2 protoc protoc-gen-go | |||||
INCLUDE = -I=. -I=${GOPATH}/src | |||||
all: check get_vendor_deps protoc grpc_dbserver build test install metalinter | |||||
check: check_tools | |||||
######################################## | |||||
### Build | |||||
protoc: | |||||
## If you get the following error, | |||||
## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory" | |||||
## See https://stackoverflow.com/a/25518702 | |||||
protoc $(INCLUDE) --go_out=plugins=grpc:. common/*.proto | |||||
@echo "--> adding nolint declarations to protobuf generated files" | |||||
@awk '/package common/ { print "//nolint: gas"; print; next }1' common/types.pb.go > common/types.pb.go.new | |||||
@mv common/types.pb.go.new common/types.pb.go | |||||
build: | |||||
# Nothing to build! | |||||
install: | |||||
# Nothing to install! | |||||
######################################## | |||||
### Tools & dependencies | |||||
check_tools: | |||||
@# https://stackoverflow.com/a/25668869 | |||||
@echo "Found tools: $(foreach tool,$(GOTOOLS_CHECK),\ | |||||
$(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))" | |||||
get_tools: | |||||
@echo "--> Installing tools" | |||||
go get -u -v $(GOTOOLS) | |||||
# @gometalinter.v2 --install | |||||
get_protoc: | |||||
@# https://github.com/google/protobuf/releases | |||||
curl -L https://github.com/google/protobuf/releases/download/v3.4.1/protobuf-cpp-3.4.1.tar.gz | tar xvz && \ | |||||
cd protobuf-3.4.1 && \ | |||||
DIST_LANG=cpp ./configure && \ | |||||
make && \ | |||||
make install && \ | |||||
cd .. && \ | |||||
rm -rf protobuf-3.4.1 | |||||
update_tools: | |||||
@echo "--> Updating tools" | |||||
@go get -u $(GOTOOLS) | |||||
get_vendor_deps: | |||||
@rm -rf vendor/ | |||||
@echo "--> Running dep ensure" | |||||
@dep ensure | |||||
######################################## | |||||
### Testing | |||||
gen_certs: clean_certs | |||||
## Generating certificates for TLS testing... | |||||
certstrap init --common-name "tendermint.com" --passphrase "" | |||||
certstrap request-cert -ip "::" --passphrase "" | |||||
certstrap sign "::" --CA "tendermint.com" --passphrase "" | |||||
mv out/::.crt out/::.key db/remotedb | |||||
clean_certs: | |||||
## Cleaning TLS testing certificates... | |||||
rm -rf out | |||||
rm -f db/remotedb/::.crt db/remotedb/::.key | |||||
test: gen_certs | |||||
GOCACHE=off go test -tags gcc $(shell go list ./... | grep -v vendor) | |||||
make clean_certs | |||||
test100: | |||||
@for i in {1..100}; do make test; done | |||||
######################################## | |||||
### Formatting, linting, and vetting | |||||
fmt: | |||||
@go fmt ./... | |||||
metalinter: | |||||
@echo "==> Running linter" | |||||
gometalinter.v2 --vendor --deadline=600s --disable-all \ | |||||
--enable=deadcode \ | |||||
--enable=goconst \ | |||||
--enable=goimports \ | |||||
--enable=gosimple \ | |||||
--enable=ineffassign \ | |||||
--enable=megacheck \ | |||||
--enable=misspell \ | |||||
--enable=staticcheck \ | |||||
--enable=safesql \ | |||||
--enable=structcheck \ | |||||
--enable=unconvert \ | |||||
--enable=unused \ | |||||
--enable=varcheck \ | |||||
--enable=vetshadow \ | |||||
./... | |||||
#--enable=maligned \ | |||||
#--enable=gas \ | |||||
#--enable=aligncheck \ | |||||
#--enable=dupl \ | |||||
#--enable=errcheck \ | |||||
#--enable=gocyclo \ | |||||
#--enable=golint \ <== comments on anything exported | |||||
#--enable=gotype \ | |||||
#--enable=interfacer \ | |||||
#--enable=unparam \ | |||||
#--enable=vet \ | |||||
metalinter_all: | |||||
protoc $(INCLUDE) --lint_out=. types/*.proto | |||||
gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./... | |||||
# To avoid unintended conflicts with file names, always add to .PHONY | |||||
# unless there is a reason not to. | |||||
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html | |||||
.PHONY: check protoc build check_tools get_tools get_protoc update_tools get_vendor_deps test fmt metalinter metalinter_all gen_certs clean_certs | |||||
grpc_dbserver: | |||||
protoc -I db/remotedb/proto/ db/remotedb/proto/defs.proto --go_out=plugins=grpc:db/remotedb/proto |
@ -0,0 +1,49 @@ | |||||
# TMLIBS | |||||
This repo is a home for various small packages. | |||||
## autofile | |||||
Autofile is file access with automatic log rotation. A group of files is maintained and rotation happens | |||||
when the leading file gets too big. Provides a reader for reading from the file group. | |||||
## cli | |||||
CLI wraps the `cobra` and `viper` packages and handles some common elements of building a CLI like flags and env vars for the home directory and the logger. | |||||
## clist | |||||
Clist provides a linekd list that is safe for concurrent access by many readers. | |||||
## common | |||||
Common provides a hodgepodge of useful functions. | |||||
## db | |||||
DB provides a database interface and a number of implementions, including ones using an in-memory map, the filesystem directory structure, | |||||
an implemention of LevelDB in Go, and the official LevelDB in C. | |||||
## events | |||||
Events is a synchronous PubSub package. | |||||
## flowrate | |||||
Flowrate is a fork of https://github.com/mxk/go-flowrate that added a `SetREMA` method. | |||||
## log | |||||
Log is a log package structured around key-value pairs that allows logging level to be set differently for different keys. | |||||
## merkle | |||||
Merkle provides a simple static merkle tree and corresponding proofs. | |||||
## process | |||||
Process is a simple utility for spawning OS processes. | |||||
## pubsub | |||||
PubSub is an asynchronous PubSub package. |
@ -0,0 +1 @@ | |||||
# go-autofile |
@ -0,0 +1,142 @@ | |||||
package autofile | |||||
import ( | |||||
"os" | |||||
"sync" | |||||
"time" | |||||
cmn "github.com/tendermint/tendermint/libs/common" | |||||
) | |||||
/* AutoFile usage | |||||
// Create/Append to ./autofile_test | |||||
af, err := OpenAutoFile("autofile_test") | |||||
if err != nil { | |||||
panic(err) | |||||
} | |||||
// Stream of writes. | |||||
// During this time, the file may be moved e.g. by logRotate. | |||||
for i := 0; i < 60; i++ { | |||||
af.Write([]byte(Fmt("LOOP(%v)", i))) | |||||
time.Sleep(time.Second) | |||||
} | |||||
// Close the AutoFile | |||||
err = af.Close() | |||||
if err != nil { | |||||
panic(err) | |||||
} | |||||
*/ | |||||
const autoFileOpenDuration = 1000 * time.Millisecond | |||||
// Automatically closes and re-opens file for writing. | |||||
// This is useful for using a log file with the logrotate tool. | |||||
type AutoFile struct { | |||||
ID string | |||||
Path string | |||||
ticker *time.Ticker | |||||
mtx sync.Mutex | |||||
file *os.File | |||||
} | |||||
func OpenAutoFile(path string) (af *AutoFile, err error) { | |||||
af = &AutoFile{ | |||||
ID: cmn.RandStr(12) + ":" + path, | |||||
Path: path, | |||||
ticker: time.NewTicker(autoFileOpenDuration), | |||||
} | |||||
if err = af.openFile(); err != nil { | |||||
return | |||||
} | |||||
go af.processTicks() | |||||
sighupWatchers.addAutoFile(af) | |||||
return | |||||
} | |||||
func (af *AutoFile) Close() error { | |||||
af.ticker.Stop() | |||||
err := af.closeFile() | |||||
sighupWatchers.removeAutoFile(af) | |||||
return err | |||||
} | |||||
func (af *AutoFile) processTicks() { | |||||
for { | |||||
_, ok := <-af.ticker.C | |||||
if !ok { | |||||
return // Done. | |||||
} | |||||
af.closeFile() | |||||
} | |||||
} | |||||
func (af *AutoFile) closeFile() (err error) { | |||||
af.mtx.Lock() | |||||
defer af.mtx.Unlock() | |||||
file := af.file | |||||
if file == nil { | |||||
return nil | |||||
} | |||||
af.file = nil | |||||
return file.Close() | |||||
} | |||||
func (af *AutoFile) Write(b []byte) (n int, err error) { | |||||
af.mtx.Lock() | |||||
defer af.mtx.Unlock() | |||||
if af.file == nil { | |||||
if err = af.openFile(); err != nil { | |||||
return | |||||
} | |||||
} | |||||
n, err = af.file.Write(b) | |||||
return | |||||
} | |||||
func (af *AutoFile) Sync() error { | |||||
af.mtx.Lock() | |||||
defer af.mtx.Unlock() | |||||
if af.file == nil { | |||||
if err := af.openFile(); err != nil { | |||||
return err | |||||
} | |||||
} | |||||
return af.file.Sync() | |||||
} | |||||
func (af *AutoFile) openFile() error { | |||||
file, err := os.OpenFile(af.Path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
af.file = file | |||||
return nil | |||||
} | |||||
func (af *AutoFile) Size() (int64, error) { | |||||
af.mtx.Lock() | |||||
defer af.mtx.Unlock() | |||||
if af.file == nil { | |||||
err := af.openFile() | |||||
if err != nil { | |||||
if err == os.ErrNotExist { | |||||
return 0, nil | |||||
} | |||||
return -1, err | |||||
} | |||||
} | |||||
stat, err := af.file.Stat() | |||||
if err != nil { | |||||
return -1, err | |||||
} | |||||
return stat.Size(), nil | |||||
} |
@ -0,0 +1,71 @@ | |||||
package autofile | |||||
import ( | |||||
"os" | |||||
"sync/atomic" | |||||
"syscall" | |||||
"testing" | |||||
"time" | |||||
cmn "github.com/tendermint/tendermint/libs/common" | |||||
) | |||||
func TestSIGHUP(t *testing.T) { | |||||
// First, create an AutoFile writing to a tempfile dir | |||||
file, name := cmn.Tempfile("sighup_test") | |||||
if err := file.Close(); err != nil { | |||||
t.Fatalf("Error creating tempfile: %v", err) | |||||
} | |||||
// Here is the actual AutoFile | |||||
af, err := OpenAutoFile(name) | |||||
if err != nil { | |||||
t.Fatalf("Error creating autofile: %v", err) | |||||
} | |||||
// Write to the file. | |||||
_, err = af.Write([]byte("Line 1\n")) | |||||
if err != nil { | |||||
t.Fatalf("Error writing to autofile: %v", err) | |||||
} | |||||
_, err = af.Write([]byte("Line 2\n")) | |||||
if err != nil { | |||||
t.Fatalf("Error writing to autofile: %v", err) | |||||
} | |||||
// Move the file over | |||||
err = os.Rename(name, name+"_old") | |||||
if err != nil { | |||||
t.Fatalf("Error moving autofile: %v", err) | |||||
} | |||||
// Send SIGHUP to self. | |||||
oldSighupCounter := atomic.LoadInt32(&sighupCounter) | |||||
syscall.Kill(syscall.Getpid(), syscall.SIGHUP) | |||||
// Wait a bit... signals are not handled synchronously. | |||||
for atomic.LoadInt32(&sighupCounter) == oldSighupCounter { | |||||
time.Sleep(time.Millisecond * 10) | |||||
} | |||||
// Write more to the file. | |||||
_, err = af.Write([]byte("Line 3\n")) | |||||
if err != nil { | |||||
t.Fatalf("Error writing to autofile: %v", err) | |||||
} | |||||
_, err = af.Write([]byte("Line 4\n")) | |||||
if err != nil { | |||||
t.Fatalf("Error writing to autofile: %v", err) | |||||
} | |||||
if err := af.Close(); err != nil { | |||||
t.Fatalf("Error closing autofile") | |||||
} | |||||
// Both files should exist | |||||
if body := cmn.MustReadFile(name + "_old"); string(body) != "Line 1\nLine 2\n" { | |||||
t.Errorf("Unexpected body %s", body) | |||||
} | |||||
if body := cmn.MustReadFile(name); string(body) != "Line 3\nLine 4\n" { | |||||
t.Errorf("Unexpected body %s", body) | |||||
} | |||||
} |
@ -0,0 +1,107 @@ | |||||
package main | |||||
import ( | |||||
"flag" | |||||
"fmt" | |||||
"io" | |||||
"os" | |||||
"strconv" | |||||
"strings" | |||||
auto "github.com/tendermint/tendermint/libs/autofile" | |||||
cmn "github.com/tendermint/tendermint/libs/common" | |||||
) | |||||
const Version = "0.0.1" | |||||
const readBufferSize = 1024 // 1KB at a time | |||||
// Parse command-line options | |||||
func parseFlags() (headPath string, chopSize int64, limitSize int64, version bool) { | |||||
var flagSet = flag.NewFlagSet(os.Args[0], flag.ExitOnError) | |||||
var chopSizeStr, limitSizeStr string | |||||
flagSet.StringVar(&headPath, "head", "logjack.out", "Destination (head) file.") | |||||
flagSet.StringVar(&chopSizeStr, "chop", "100M", "Move file if greater than this") | |||||
flagSet.StringVar(&limitSizeStr, "limit", "10G", "Only keep this much (for each specified file). Remove old files.") | |||||
flagSet.BoolVar(&version, "version", false, "Version") | |||||
flagSet.Parse(os.Args[1:]) | |||||
chopSize = parseBytesize(chopSizeStr) | |||||
limitSize = parseBytesize(limitSizeStr) | |||||
return | |||||
} | |||||
func main() { | |||||
// Read options | |||||
headPath, chopSize, limitSize, version := parseFlags() | |||||
if version { | |||||
fmt.Printf("logjack version %v\n", Version) | |||||
return | |||||
} | |||||
// Open Group | |||||
group, err := auto.OpenGroup(headPath) | |||||
if err != nil { | |||||
fmt.Printf("logjack couldn't create output file %v\n", headPath) | |||||
os.Exit(1) | |||||
} | |||||
group.SetHeadSizeLimit(chopSize) | |||||
group.SetTotalSizeLimit(limitSize) | |||||
err = group.Start() | |||||
if err != nil { | |||||
fmt.Printf("logjack couldn't start with file %v\n", headPath) | |||||
os.Exit(1) | |||||
} | |||||
go func() { | |||||
// Forever, read from stdin and write to AutoFile. | |||||
buf := make([]byte, readBufferSize) | |||||
for { | |||||
n, err := os.Stdin.Read(buf) | |||||
group.Write(buf[:n]) | |||||
group.Flush() | |||||
if err != nil { | |||||
group.Stop() | |||||
if err == io.EOF { | |||||
os.Exit(0) | |||||
} else { | |||||
fmt.Println("logjack errored") | |||||
os.Exit(1) | |||||
} | |||||
} | |||||
} | |||||
}() | |||||
// Trap signal | |||||
cmn.TrapSignal(func() { | |||||
fmt.Println("logjack shutting down") | |||||
}) | |||||
} | |||||
func parseBytesize(chopSize string) int64 { | |||||
// Handle suffix multiplier | |||||
var multiplier int64 = 1 | |||||
if strings.HasSuffix(chopSize, "T") { | |||||
multiplier = 1042 * 1024 * 1024 * 1024 | |||||
chopSize = chopSize[:len(chopSize)-1] | |||||
} | |||||
if strings.HasSuffix(chopSize, "G") { | |||||
multiplier = 1042 * 1024 * 1024 | |||||
chopSize = chopSize[:len(chopSize)-1] | |||||
} | |||||
if strings.HasSuffix(chopSize, "M") { | |||||
multiplier = 1042 * 1024 | |||||
chopSize = chopSize[:len(chopSize)-1] | |||||
} | |||||
if strings.HasSuffix(chopSize, "K") { | |||||
multiplier = 1042 | |||||
chopSize = chopSize[:len(chopSize)-1] | |||||
} | |||||
// Parse the numeric part | |||||
chopSizeInt, err := strconv.Atoi(chopSize) | |||||
if err != nil { | |||||
panic(err) | |||||
} | |||||
return int64(chopSizeInt) * multiplier | |||||
} |