storj/pkg/kademlia/routing_test.go

243 lines
6.1 KiB
Go
Raw Normal View History

2019-01-24 20:15:10 +00:00
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information
package kademlia
Testcoverage kademlia (#154) * Unit test covarege increased for kademlia pkg go style formatting added Removed DHT param from newTestKademlia method, added comments for Bucket methods that informs that these tests will need to be updated unnecessary comment deleted from newTestKademlia Adjust Segment Store to the updated interface (#160) * Adjust Segment Store to the updated interface * Move /pkg/storage/segment to /pkg/storage/segments * Fix overlay client tests * Revert changes in NewOverlayClient return value * Rename `rem` to `seg` * Implement Meta() captplanet (#159) * captplanet I kind of went overboard this weekend. The major goal of this changeset is to provide an environment for local development where all of the various services can be easily run together. Developing on Storj v3 should be as easy as running a setup command and a run command! To do this, this changeset introduces a new tool called captplanet, which combines the powers of the Overlay Cache, the PointerDB, the PieceStore, Kademlia, the Minio Gateway, etc. Running 40 farmers and a heavy client inside the same process forced a rethinking of the "services" that we had. To avoid confusion by reusing prior terms, this changeset introduces two new types: Providers and Responsibilities. I wanted to avoid as many merge conflicts as possible, so I left the existing Services and code for now, but if people like this route we can clean up the duplication. A Responsibility is a collection of gRPC methods and corresponding state. The following systems are examples of Responsibilities: * Kademlia * OverlayCache * PointerDB * StatDB * PieceStore * etc. A Provider is a collection of Responsibilities that share an Identity, such as: * The heavy client * The farmer * The gateway An Identity is a public/private key pair, a node id, etc. Farmers all need different Identities, so captplanet needs to support running multiple concurrent Providers with different Identities. Each Responsibility and Provider should allow for configuration of multiple copies on its own so creating Responsibilities and Providers use a new workflow. To make a Responsibility, one should create a "config" struct, such as: ``` type Config struct { RepairThreshold int `help:"If redundancy falls below this number of pieces, repair is triggered" default:"30"` SuccessThreshold int `help:"If redundancy is above this number then no additional uploads are needed" default:"40"` } ``` To use "config" structs, this changeset introduces another new library called 'cfgstruct', which allows for the configuration of arbitrary structs through flagsets, and thus through cobra and viper. cfgstruct relies on Go's "struct tags" feature to document help information and default values. Config structs can be configured via cfgstruct.Bind for binding the struct to a flagset. Because this configuration system makes setup and configuration easier *in general*, additional commands are provided that allow for easy standup of separate Providers. Please make sure to check out: * cmd/captplanet/farmer/main.go (a new farmer binary) * cmd/captplanet/hc/main.go (a new heavy client binary) * cmd/captplanet/gw/main.go (a new minio gateway binary) Usage: ``` $ go install -v storj.io/storj/cmd/captplanet $ captplanet setup $ captplanet run ``` Configuration is placed by default in `~/.storj/capt/` Other changes: * introduces new config structs for currently existing Responsibilities that conform to the new Responsibility interface. Please see the `pkg/*/config.go` files for examples. * integrates the PointerDB API key with other global configuration via flags, instead of through environment variables through viper like it's been doing. (ultimately this should also change to use the PointerDB config struct but this is an okay shortterm solution). * changes the Overlay cache to use a URL for database configuration instead of separate redis and bolt config settings. * stubs out some peer identity skeleton code (but not the meat). * Fixes the SegmentStore to use the overlay client and pointerdb clients instead of gRPC client code directly * Leaves a very clear spot where we need to tie the object to stream to segment store together. There's sort of a "golden spike" opportunity to connect all the train tracks together at the bottom of pkg/miniogw/config.go, labeled with a bunch of TODOs. Future stuff: * I now prefer this design over the original pkg/process.Service thing I had been pushing before (sorry!) * The experience of trying to have multiple farmers configurable concurrently led me to prefer config structs over global flags (I finally came around) or using viper directly. I think global flags are okay sometimes but in general going forward we should try and get all relevant config into config structs. * If you all like this direction, I think we can go delete my old Service interfaces and a bunch of flags and clean up a bunch of stuff. * If you don't like this direction, it's no sweat at all, and despite how much code there is here I'm not very tied to any of this! Considering a lot of this was written between midnight and 6 am, it might not be any good! * bind tests Add files for testing builds in docker (#161) * Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis pkg/provider: with pkg/provider merged, make a single heavy client binary, gateway binary, and deprecate old services (#165) * pkg/provider: with pkg/provider merged, make a single heavy client binary and deprecate old services * add setup to gw binary too * captplanet: output what addresses everything is listening on * revert peertls/io_util changes * define config flag across all commands * use trimsuffix fix docker makefile (#170) * fix makefile protos: update protobufs with go generate (#169) the import for timestamp and duration should use the path provided by a standard protocol buffer library installation Refactor List in PointerDB (#163) * Refactor List in Pointer DB * Fix pointerdb-client example * Fix issue in Path type related to empty paths * Test for the PointerDB service with some fixes * Fixed debug message in example: trancated --> more * GoDoc comments for unexported methods * TODO comment to check if Put is overwriting * Log warning if protobuf timestamp cannot be converted * TODO comment to make ListPageLimit configurable * Rename 'segment' package to 'segments' to reflect folder name Minio integration with Object store (#156) * initial WIP integration with Object store * List WIP * minio listobject function changes complete * Code review changes and work in progress for the mock objectstore unit testing cases * Warning fix redeclaration of err * Warning fix redeclaration of err * code review comments & unit testing inprogress * fix compilation bug * Fixed code review comments & added GetObject Mock test case * rearraged the mock test file and gateway storj test file in to the proper directory * added the missing file * code clean up * fix lint error on the mock generated code * modified per code review comments * added the PutObject mock test case * added the GetObjectInfo mock test case * added listobject mock test case * fixed package from storj to miniogw * resolved the gateway-storj.go initialization merge conflict update readme (#174) added assertion for unused errors (#152) merging this PR to avoid future issues updating github user to personal account (#171) Test coverage ranger (#168) * Fixed go panic for corner case * Initial test coverage for ranger pkg streamstore: add passthrough implementation (#176) this doesn't implement streamstore, this just allows us to try and get the june demo working again in the meantime StatDB (#144) * add statdb proto and example client * server logic * update readme * remove boltdb from service.go * sqlite3 * add statdb server executable file * create statdb node table if it does not exist already * get UpdateBatch working * update based on jt review * remove some commented lines * fix linting issues * reformat * apiKey -> APIKey * update statdb client apiKey->APIKey Update README.md Update README.md overlay: correct dockerfile db (#179) cmd/hc, cmd/gw, cmd/captplanet: simplify setup/run commands (#178) also allows much more customization of services within captain planet, such as reconfiguring the overlay service to use redis pkg/process: don't require json formatting (#177) Cleanup metadata across layers (#180) * Cleanup metadata across layers * Fix pointer db tests Kademlia Routing Table (#164) * adds comment * runs deps * creates boltdb kademlia routing table * protobuf updates * adds reverselist to mockkeyvaluestore interface * xor wip * xor wip * fixes xor sort * runs go fmt * fixes * goimports again * trying to fix travis tests * fixes mock tests Ranger refactoring (#158) * Fixed go panic for corner case * Cosmetic changes, and small error fixes miniogw: log all errors (#182) * miniogw: log all errors * tests added * doc comment to satisfy linter * fix test failure Jennifer added to CLA list * Temporary fix for storage/redis list method test
2018-08-02 19:36:57 +01:00
import (
"bytes"
Testcoverage kademlia (#154) * Unit test covarege increased for kademlia pkg go style formatting added Removed DHT param from newTestKademlia method, added comments for Bucket methods that informs that these tests will need to be updated unnecessary comment deleted from newTestKademlia Adjust Segment Store to the updated interface (#160) * Adjust Segment Store to the updated interface * Move /pkg/storage/segment to /pkg/storage/segments * Fix overlay client tests * Revert changes in NewOverlayClient return value * Rename `rem` to `seg` * Implement Meta() captplanet (#159) * captplanet I kind of went overboard this weekend. The major goal of this changeset is to provide an environment for local development where all of the various services can be easily run together. Developing on Storj v3 should be as easy as running a setup command and a run command! To do this, this changeset introduces a new tool called captplanet, which combines the powers of the Overlay Cache, the PointerDB, the PieceStore, Kademlia, the Minio Gateway, etc. Running 40 farmers and a heavy client inside the same process forced a rethinking of the "services" that we had. To avoid confusion by reusing prior terms, this changeset introduces two new types: Providers and Responsibilities. I wanted to avoid as many merge conflicts as possible, so I left the existing Services and code for now, but if people like this route we can clean up the duplication. A Responsibility is a collection of gRPC methods and corresponding state. The following systems are examples of Responsibilities: * Kademlia * OverlayCache * PointerDB * StatDB * PieceStore * etc. A Provider is a collection of Responsibilities that share an Identity, such as: * The heavy client * The farmer * The gateway An Identity is a public/private key pair, a node id, etc. Farmers all need different Identities, so captplanet needs to support running multiple concurrent Providers with different Identities. Each Responsibility and Provider should allow for configuration of multiple copies on its own so creating Responsibilities and Providers use a new workflow. To make a Responsibility, one should create a "config" struct, such as: ``` type Config struct { RepairThreshold int `help:"If redundancy falls below this number of pieces, repair is triggered" default:"30"` SuccessThreshold int `help:"If redundancy is above this number then no additional uploads are needed" default:"40"` } ``` To use "config" structs, this changeset introduces another new library called 'cfgstruct', which allows for the configuration of arbitrary structs through flagsets, and thus through cobra and viper. cfgstruct relies on Go's "struct tags" feature to document help information and default values. Config structs can be configured via cfgstruct.Bind for binding the struct to a flagset. Because this configuration system makes setup and configuration easier *in general*, additional commands are provided that allow for easy standup of separate Providers. Please make sure to check out: * cmd/captplanet/farmer/main.go (a new farmer binary) * cmd/captplanet/hc/main.go (a new heavy client binary) * cmd/captplanet/gw/main.go (a new minio gateway binary) Usage: ``` $ go install -v storj.io/storj/cmd/captplanet $ captplanet setup $ captplanet run ``` Configuration is placed by default in `~/.storj/capt/` Other changes: * introduces new config structs for currently existing Responsibilities that conform to the new Responsibility interface. Please see the `pkg/*/config.go` files for examples. * integrates the PointerDB API key with other global configuration via flags, instead of through environment variables through viper like it's been doing. (ultimately this should also change to use the PointerDB config struct but this is an okay shortterm solution). * changes the Overlay cache to use a URL for database configuration instead of separate redis and bolt config settings. * stubs out some peer identity skeleton code (but not the meat). * Fixes the SegmentStore to use the overlay client and pointerdb clients instead of gRPC client code directly * Leaves a very clear spot where we need to tie the object to stream to segment store together. There's sort of a "golden spike" opportunity to connect all the train tracks together at the bottom of pkg/miniogw/config.go, labeled with a bunch of TODOs. Future stuff: * I now prefer this design over the original pkg/process.Service thing I had been pushing before (sorry!) * The experience of trying to have multiple farmers configurable concurrently led me to prefer config structs over global flags (I finally came around) or using viper directly. I think global flags are okay sometimes but in general going forward we should try and get all relevant config into config structs. * If you all like this direction, I think we can go delete my old Service interfaces and a bunch of flags and clean up a bunch of stuff. * If you don't like this direction, it's no sweat at all, and despite how much code there is here I'm not very tied to any of this! Considering a lot of this was written between midnight and 6 am, it might not be any good! * bind tests Add files for testing builds in docker (#161) * Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis pkg/provider: with pkg/provider merged, make a single heavy client binary, gateway binary, and deprecate old services (#165) * pkg/provider: with pkg/provider merged, make a single heavy client binary and deprecate old services * add setup to gw binary too * captplanet: output what addresses everything is listening on * revert peertls/io_util changes * define config flag across all commands * use trimsuffix fix docker makefile (#170) * fix makefile protos: update protobufs with go generate (#169) the import for timestamp and duration should use the path provided by a standard protocol buffer library installation Refactor List in PointerDB (#163) * Refactor List in Pointer DB * Fix pointerdb-client example * Fix issue in Path type related to empty paths * Test for the PointerDB service with some fixes * Fixed debug message in example: trancated --> more * GoDoc comments for unexported methods * TODO comment to check if Put is overwriting * Log warning if protobuf timestamp cannot be converted * TODO comment to make ListPageLimit configurable * Rename 'segment' package to 'segments' to reflect folder name Minio integration with Object store (#156) * initial WIP integration with Object store * List WIP * minio listobject function changes complete * Code review changes and work in progress for the mock objectstore unit testing cases * Warning fix redeclaration of err * Warning fix redeclaration of err * code review comments & unit testing inprogress * fix compilation bug * Fixed code review comments & added GetObject Mock test case * rearraged the mock test file and gateway storj test file in to the proper directory * added the missing file * code clean up * fix lint error on the mock generated code * modified per code review comments * added the PutObject mock test case * added the GetObjectInfo mock test case * added listobject mock test case * fixed package from storj to miniogw * resolved the gateway-storj.go initialization merge conflict update readme (#174) added assertion for unused errors (#152) merging this PR to avoid future issues updating github user to personal account (#171) Test coverage ranger (#168) * Fixed go panic for corner case * Initial test coverage for ranger pkg streamstore: add passthrough implementation (#176) this doesn't implement streamstore, this just allows us to try and get the june demo working again in the meantime StatDB (#144) * add statdb proto and example client * server logic * update readme * remove boltdb from service.go * sqlite3 * add statdb server executable file * create statdb node table if it does not exist already * get UpdateBatch working * update based on jt review * remove some commented lines * fix linting issues * reformat * apiKey -> APIKey * update statdb client apiKey->APIKey Update README.md Update README.md overlay: correct dockerfile db (#179) cmd/hc, cmd/gw, cmd/captplanet: simplify setup/run commands (#178) also allows much more customization of services within captain planet, such as reconfiguring the overlay service to use redis pkg/process: don't require json formatting (#177) Cleanup metadata across layers (#180) * Cleanup metadata across layers * Fix pointer db tests Kademlia Routing Table (#164) * adds comment * runs deps * creates boltdb kademlia routing table * protobuf updates * adds reverselist to mockkeyvaluestore interface * xor wip * xor wip * fixes xor sort * runs go fmt * fixes * goimports again * trying to fix travis tests * fixes mock tests Ranger refactoring (#158) * Fixed go panic for corner case * Cosmetic changes, and small error fixes miniogw: log all errors (#182) * miniogw: log all errors * tests added * doc comment to satisfy linter * fix test failure Jennifer added to CLA list * Temporary fix for storage/redis list method test
2018-08-02 19:36:57 +01:00
"testing"
"time"
"github.com/stretchr/testify/assert"
"storj.io/storj/internal/teststorj"
"storj.io/storj/pkg/pb"
2018-11-30 13:40:13 +00:00
"storj.io/storj/pkg/storj"
"storj.io/storj/storage"
Testcoverage kademlia (#154) * Unit test covarege increased for kademlia pkg go style formatting added Removed DHT param from newTestKademlia method, added comments for Bucket methods that informs that these tests will need to be updated unnecessary comment deleted from newTestKademlia Adjust Segment Store to the updated interface (#160) * Adjust Segment Store to the updated interface * Move /pkg/storage/segment to /pkg/storage/segments * Fix overlay client tests * Revert changes in NewOverlayClient return value * Rename `rem` to `seg` * Implement Meta() captplanet (#159) * captplanet I kind of went overboard this weekend. The major goal of this changeset is to provide an environment for local development where all of the various services can be easily run together. Developing on Storj v3 should be as easy as running a setup command and a run command! To do this, this changeset introduces a new tool called captplanet, which combines the powers of the Overlay Cache, the PointerDB, the PieceStore, Kademlia, the Minio Gateway, etc. Running 40 farmers and a heavy client inside the same process forced a rethinking of the "services" that we had. To avoid confusion by reusing prior terms, this changeset introduces two new types: Providers and Responsibilities. I wanted to avoid as many merge conflicts as possible, so I left the existing Services and code for now, but if people like this route we can clean up the duplication. A Responsibility is a collection of gRPC methods and corresponding state. The following systems are examples of Responsibilities: * Kademlia * OverlayCache * PointerDB * StatDB * PieceStore * etc. A Provider is a collection of Responsibilities that share an Identity, such as: * The heavy client * The farmer * The gateway An Identity is a public/private key pair, a node id, etc. Farmers all need different Identities, so captplanet needs to support running multiple concurrent Providers with different Identities. Each Responsibility and Provider should allow for configuration of multiple copies on its own so creating Responsibilities and Providers use a new workflow. To make a Responsibility, one should create a "config" struct, such as: ``` type Config struct { RepairThreshold int `help:"If redundancy falls below this number of pieces, repair is triggered" default:"30"` SuccessThreshold int `help:"If redundancy is above this number then no additional uploads are needed" default:"40"` } ``` To use "config" structs, this changeset introduces another new library called 'cfgstruct', which allows for the configuration of arbitrary structs through flagsets, and thus through cobra and viper. cfgstruct relies on Go's "struct tags" feature to document help information and default values. Config structs can be configured via cfgstruct.Bind for binding the struct to a flagset. Because this configuration system makes setup and configuration easier *in general*, additional commands are provided that allow for easy standup of separate Providers. Please make sure to check out: * cmd/captplanet/farmer/main.go (a new farmer binary) * cmd/captplanet/hc/main.go (a new heavy client binary) * cmd/captplanet/gw/main.go (a new minio gateway binary) Usage: ``` $ go install -v storj.io/storj/cmd/captplanet $ captplanet setup $ captplanet run ``` Configuration is placed by default in `~/.storj/capt/` Other changes: * introduces new config structs for currently existing Responsibilities that conform to the new Responsibility interface. Please see the `pkg/*/config.go` files for examples. * integrates the PointerDB API key with other global configuration via flags, instead of through environment variables through viper like it's been doing. (ultimately this should also change to use the PointerDB config struct but this is an okay shortterm solution). * changes the Overlay cache to use a URL for database configuration instead of separate redis and bolt config settings. * stubs out some peer identity skeleton code (but not the meat). * Fixes the SegmentStore to use the overlay client and pointerdb clients instead of gRPC client code directly * Leaves a very clear spot where we need to tie the object to stream to segment store together. There's sort of a "golden spike" opportunity to connect all the train tracks together at the bottom of pkg/miniogw/config.go, labeled with a bunch of TODOs. Future stuff: * I now prefer this design over the original pkg/process.Service thing I had been pushing before (sorry!) * The experience of trying to have multiple farmers configurable concurrently led me to prefer config structs over global flags (I finally came around) or using viper directly. I think global flags are okay sometimes but in general going forward we should try and get all relevant config into config structs. * If you all like this direction, I think we can go delete my old Service interfaces and a bunch of flags and clean up a bunch of stuff. * If you don't like this direction, it's no sweat at all, and despite how much code there is here I'm not very tied to any of this! Considering a lot of this was written between midnight and 6 am, it might not be any good! * bind tests Add files for testing builds in docker (#161) * Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis pkg/provider: with pkg/provider merged, make a single heavy client binary, gateway binary, and deprecate old services (#165) * pkg/provider: with pkg/provider merged, make a single heavy client binary and deprecate old services * add setup to gw binary too * captplanet: output what addresses everything is listening on * revert peertls/io_util changes * define config flag across all commands * use trimsuffix fix docker makefile (#170) * fix makefile protos: update protobufs with go generate (#169) the import for timestamp and duration should use the path provided by a standard protocol buffer library installation Refactor List in PointerDB (#163) * Refactor List in Pointer DB * Fix pointerdb-client example * Fix issue in Path type related to empty paths * Test for the PointerDB service with some fixes * Fixed debug message in example: trancated --> more * GoDoc comments for unexported methods * TODO comment to check if Put is overwriting * Log warning if protobuf timestamp cannot be converted * TODO comment to make ListPageLimit configurable * Rename 'segment' package to 'segments' to reflect folder name Minio integration with Object store (#156) * initial WIP integration with Object store * List WIP * minio listobject function changes complete * Code review changes and work in progress for the mock objectstore unit testing cases * Warning fix redeclaration of err * Warning fix redeclaration of err * code review comments & unit testing inprogress * fix compilation bug * Fixed code review comments & added GetObject Mock test case * rearraged the mock test file and gateway storj test file in to the proper directory * added the missing file * code clean up * fix lint error on the mock generated code * modified per code review comments * added the PutObject mock test case * added the GetObjectInfo mock test case * added listobject mock test case * fixed package from storj to miniogw * resolved the gateway-storj.go initialization merge conflict update readme (#174) added assertion for unused errors (#152) merging this PR to avoid future issues updating github user to personal account (#171) Test coverage ranger (#168) * Fixed go panic for corner case * Initial test coverage for ranger pkg streamstore: add passthrough implementation (#176) this doesn't implement streamstore, this just allows us to try and get the june demo working again in the meantime StatDB (#144) * add statdb proto and example client * server logic * update readme * remove boltdb from service.go * sqlite3 * add statdb server executable file * create statdb node table if it does not exist already * get UpdateBatch working * update based on jt review * remove some commented lines * fix linting issues * reformat * apiKey -> APIKey * update statdb client apiKey->APIKey Update README.md Update README.md overlay: correct dockerfile db (#179) cmd/hc, cmd/gw, cmd/captplanet: simplify setup/run commands (#178) also allows much more customization of services within captain planet, such as reconfiguring the overlay service to use redis pkg/process: don't require json formatting (#177) Cleanup metadata across layers (#180) * Cleanup metadata across layers * Fix pointer db tests Kademlia Routing Table (#164) * adds comment * runs deps * creates boltdb kademlia routing table * protobuf updates * adds reverselist to mockkeyvaluestore interface * xor wip * xor wip * fixes xor sort * runs go fmt * fixes * goimports again * trying to fix travis tests * fixes mock tests Ranger refactoring (#158) * Fixed go panic for corner case * Cosmetic changes, and small error fixes miniogw: log all errors (#182) * miniogw: log all errors * tests added * doc comment to satisfy linter * fix test failure Jennifer added to CLA list * Temporary fix for storage/redis list method test
2018-08-02 19:36:57 +01:00
)
func TestLocal(t *testing.T) {
rt, cleanup := createRoutingTable(t, teststorj.NodeIDFromString("AA"))
2018-09-11 14:57:12 +01:00
defer cleanup()
assert.Equal(t, rt.Local().Id.Bytes()[:2], []byte("AA"))
Testcoverage kademlia (#154) * Unit test covarege increased for kademlia pkg go style formatting added Removed DHT param from newTestKademlia method, added comments for Bucket methods that informs that these tests will need to be updated unnecessary comment deleted from newTestKademlia Adjust Segment Store to the updated interface (#160) * Adjust Segment Store to the updated interface * Move /pkg/storage/segment to /pkg/storage/segments * Fix overlay client tests * Revert changes in NewOverlayClient return value * Rename `rem` to `seg` * Implement Meta() captplanet (#159) * captplanet I kind of went overboard this weekend. The major goal of this changeset is to provide an environment for local development where all of the various services can be easily run together. Developing on Storj v3 should be as easy as running a setup command and a run command! To do this, this changeset introduces a new tool called captplanet, which combines the powers of the Overlay Cache, the PointerDB, the PieceStore, Kademlia, the Minio Gateway, etc. Running 40 farmers and a heavy client inside the same process forced a rethinking of the "services" that we had. To avoid confusion by reusing prior terms, this changeset introduces two new types: Providers and Responsibilities. I wanted to avoid as many merge conflicts as possible, so I left the existing Services and code for now, but if people like this route we can clean up the duplication. A Responsibility is a collection of gRPC methods and corresponding state. The following systems are examples of Responsibilities: * Kademlia * OverlayCache * PointerDB * StatDB * PieceStore * etc. A Provider is a collection of Responsibilities that share an Identity, such as: * The heavy client * The farmer * The gateway An Identity is a public/private key pair, a node id, etc. Farmers all need different Identities, so captplanet needs to support running multiple concurrent Providers with different Identities. Each Responsibility and Provider should allow for configuration of multiple copies on its own so creating Responsibilities and Providers use a new workflow. To make a Responsibility, one should create a "config" struct, such as: ``` type Config struct { RepairThreshold int `help:"If redundancy falls below this number of pieces, repair is triggered" default:"30"` SuccessThreshold int `help:"If redundancy is above this number then no additional uploads are needed" default:"40"` } ``` To use "config" structs, this changeset introduces another new library called 'cfgstruct', which allows for the configuration of arbitrary structs through flagsets, and thus through cobra and viper. cfgstruct relies on Go's "struct tags" feature to document help information and default values. Config structs can be configured via cfgstruct.Bind for binding the struct to a flagset. Because this configuration system makes setup and configuration easier *in general*, additional commands are provided that allow for easy standup of separate Providers. Please make sure to check out: * cmd/captplanet/farmer/main.go (a new farmer binary) * cmd/captplanet/hc/main.go (a new heavy client binary) * cmd/captplanet/gw/main.go (a new minio gateway binary) Usage: ``` $ go install -v storj.io/storj/cmd/captplanet $ captplanet setup $ captplanet run ``` Configuration is placed by default in `~/.storj/capt/` Other changes: * introduces new config structs for currently existing Responsibilities that conform to the new Responsibility interface. Please see the `pkg/*/config.go` files for examples. * integrates the PointerDB API key with other global configuration via flags, instead of through environment variables through viper like it's been doing. (ultimately this should also change to use the PointerDB config struct but this is an okay shortterm solution). * changes the Overlay cache to use a URL for database configuration instead of separate redis and bolt config settings. * stubs out some peer identity skeleton code (but not the meat). * Fixes the SegmentStore to use the overlay client and pointerdb clients instead of gRPC client code directly * Leaves a very clear spot where we need to tie the object to stream to segment store together. There's sort of a "golden spike" opportunity to connect all the train tracks together at the bottom of pkg/miniogw/config.go, labeled with a bunch of TODOs. Future stuff: * I now prefer this design over the original pkg/process.Service thing I had been pushing before (sorry!) * The experience of trying to have multiple farmers configurable concurrently led me to prefer config structs over global flags (I finally came around) or using viper directly. I think global flags are okay sometimes but in general going forward we should try and get all relevant config into config structs. * If you all like this direction, I think we can go delete my old Service interfaces and a bunch of flags and clean up a bunch of stuff. * If you don't like this direction, it's no sweat at all, and despite how much code there is here I'm not very tied to any of this! Considering a lot of this was written between midnight and 6 am, it might not be any good! * bind tests Add files for testing builds in docker (#161) * Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis pkg/provider: with pkg/provider merged, make a single heavy client binary, gateway binary, and deprecate old services (#165) * pkg/provider: with pkg/provider merged, make a single heavy client binary and deprecate old services * add setup to gw binary too * captplanet: output what addresses everything is listening on * revert peertls/io_util changes * define config flag across all commands * use trimsuffix fix docker makefile (#170) * fix makefile protos: update protobufs with go generate (#169) the import for timestamp and duration should use the path provided by a standard protocol buffer library installation Refactor List in PointerDB (#163) * Refactor List in Pointer DB * Fix pointerdb-client example * Fix issue in Path type related to empty paths * Test for the PointerDB service with some fixes * Fixed debug message in example: trancated --> more * GoDoc comments for unexported methods * TODO comment to check if Put is overwriting * Log warning if protobuf timestamp cannot be converted * TODO comment to make ListPageLimit configurable * Rename 'segment' package to 'segments' to reflect folder name Minio integration with Object store (#156) * initial WIP integration with Object store * List WIP * minio listobject function changes complete * Code review changes and work in progress for the mock objectstore unit testing cases * Warning fix redeclaration of err * Warning fix redeclaration of err * code review comments & unit testing inprogress * fix compilation bug * Fixed code review comments & added GetObject Mock test case * rearraged the mock test file and gateway storj test file in to the proper directory * added the missing file * code clean up * fix lint error on the mock generated code * modified per code review comments * added the PutObject mock test case * added the GetObjectInfo mock test case * added listobject mock test case * fixed package from storj to miniogw * resolved the gateway-storj.go initialization merge conflict update readme (#174) added assertion for unused errors (#152) merging this PR to avoid future issues updating github user to personal account (#171) Test coverage ranger (#168) * Fixed go panic for corner case * Initial test coverage for ranger pkg streamstore: add passthrough implementation (#176) this doesn't implement streamstore, this just allows us to try and get the june demo working again in the meantime StatDB (#144) * add statdb proto and example client * server logic * update readme * remove boltdb from service.go * sqlite3 * add statdb server executable file * create statdb node table if it does not exist already * get UpdateBatch working * update based on jt review * remove some commented lines * fix linting issues * reformat * apiKey -> APIKey * update statdb client apiKey->APIKey Update README.md Update README.md overlay: correct dockerfile db (#179) cmd/hc, cmd/gw, cmd/captplanet: simplify setup/run commands (#178) also allows much more customization of services within captain planet, such as reconfiguring the overlay service to use redis pkg/process: don't require json formatting (#177) Cleanup metadata across layers (#180) * Cleanup metadata across layers * Fix pointer db tests Kademlia Routing Table (#164) * adds comment * runs deps * creates boltdb kademlia routing table * protobuf updates * adds reverselist to mockkeyvaluestore interface * xor wip * xor wip * fixes xor sort * runs go fmt * fixes * goimports again * trying to fix travis tests * fixes mock tests Ranger refactoring (#158) * Fixed go panic for corner case * Cosmetic changes, and small error fixes miniogw: log all errors (#182) * miniogw: log all errors * tests added * doc comment to satisfy linter * fix test failure Jennifer added to CLA list * Temporary fix for storage/redis list method test
2018-08-02 19:36:57 +01:00
}
func TestK(t *testing.T) {
rt, cleanup := createRoutingTable(t, teststorj.NodeIDFromString("AA"))
2018-09-11 14:57:12 +01:00
defer cleanup()
k := rt.K()
assert.Equal(t, rt.bucketSize, k)
Testcoverage kademlia (#154) * Unit test covarege increased for kademlia pkg go style formatting added Removed DHT param from newTestKademlia method, added comments for Bucket methods that informs that these tests will need to be updated unnecessary comment deleted from newTestKademlia Adjust Segment Store to the updated interface (#160) * Adjust Segment Store to the updated interface * Move /pkg/storage/segment to /pkg/storage/segments * Fix overlay client tests * Revert changes in NewOverlayClient return value * Rename `rem` to `seg` * Implement Meta() captplanet (#159) * captplanet I kind of went overboard this weekend. The major goal of this changeset is to provide an environment for local development where all of the various services can be easily run together. Developing on Storj v3 should be as easy as running a setup command and a run command! To do this, this changeset introduces a new tool called captplanet, which combines the powers of the Overlay Cache, the PointerDB, the PieceStore, Kademlia, the Minio Gateway, etc. Running 40 farmers and a heavy client inside the same process forced a rethinking of the "services" that we had. To avoid confusion by reusing prior terms, this changeset introduces two new types: Providers and Responsibilities. I wanted to avoid as many merge conflicts as possible, so I left the existing Services and code for now, but if people like this route we can clean up the duplication. A Responsibility is a collection of gRPC methods and corresponding state. The following systems are examples of Responsibilities: * Kademlia * OverlayCache * PointerDB * StatDB * PieceStore * etc. A Provider is a collection of Responsibilities that share an Identity, such as: * The heavy client * The farmer * The gateway An Identity is a public/private key pair, a node id, etc. Farmers all need different Identities, so captplanet needs to support running multiple concurrent Providers with different Identities. Each Responsibility and Provider should allow for configuration of multiple copies on its own so creating Responsibilities and Providers use a new workflow. To make a Responsibility, one should create a "config" struct, such as: ``` type Config struct { RepairThreshold int `help:"If redundancy falls below this number of pieces, repair is triggered" default:"30"` SuccessThreshold int `help:"If redundancy is above this number then no additional uploads are needed" default:"40"` } ``` To use "config" structs, this changeset introduces another new library called 'cfgstruct', which allows for the configuration of arbitrary structs through flagsets, and thus through cobra and viper. cfgstruct relies on Go's "struct tags" feature to document help information and default values. Config structs can be configured via cfgstruct.Bind for binding the struct to a flagset. Because this configuration system makes setup and configuration easier *in general*, additional commands are provided that allow for easy standup of separate Providers. Please make sure to check out: * cmd/captplanet/farmer/main.go (a new farmer binary) * cmd/captplanet/hc/main.go (a new heavy client binary) * cmd/captplanet/gw/main.go (a new minio gateway binary) Usage: ``` $ go install -v storj.io/storj/cmd/captplanet $ captplanet setup $ captplanet run ``` Configuration is placed by default in `~/.storj/capt/` Other changes: * introduces new config structs for currently existing Responsibilities that conform to the new Responsibility interface. Please see the `pkg/*/config.go` files for examples. * integrates the PointerDB API key with other global configuration via flags, instead of through environment variables through viper like it's been doing. (ultimately this should also change to use the PointerDB config struct but this is an okay shortterm solution). * changes the Overlay cache to use a URL for database configuration instead of separate redis and bolt config settings. * stubs out some peer identity skeleton code (but not the meat). * Fixes the SegmentStore to use the overlay client and pointerdb clients instead of gRPC client code directly * Leaves a very clear spot where we need to tie the object to stream to segment store together. There's sort of a "golden spike" opportunity to connect all the train tracks together at the bottom of pkg/miniogw/config.go, labeled with a bunch of TODOs. Future stuff: * I now prefer this design over the original pkg/process.Service thing I had been pushing before (sorry!) * The experience of trying to have multiple farmers configurable concurrently led me to prefer config structs over global flags (I finally came around) or using viper directly. I think global flags are okay sometimes but in general going forward we should try and get all relevant config into config structs. * If you all like this direction, I think we can go delete my old Service interfaces and a bunch of flags and clean up a bunch of stuff. * If you don't like this direction, it's no sweat at all, and despite how much code there is here I'm not very tied to any of this! Considering a lot of this was written between midnight and 6 am, it might not be any good! * bind tests Add files for testing builds in docker (#161) * Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis pkg/provider: with pkg/provider merged, make a single heavy client binary, gateway binary, and deprecate old services (#165) * pkg/provider: with pkg/provider merged, make a single heavy client binary and deprecate old services * add setup to gw binary too * captplanet: output what addresses everything is listening on * revert peertls/io_util changes * define config flag across all commands * use trimsuffix fix docker makefile (#170) * fix makefile protos: update protobufs with go generate (#169) the import for timestamp and duration should use the path provided by a standard protocol buffer library installation Refactor List in PointerDB (#163) * Refactor List in Pointer DB * Fix pointerdb-client example * Fix issue in Path type related to empty paths * Test for the PointerDB service with some fixes * Fixed debug message in example: trancated --> more * GoDoc comments for unexported methods * TODO comment to check if Put is overwriting * Log warning if protobuf timestamp cannot be converted * TODO comment to make ListPageLimit configurable * Rename 'segment' package to 'segments' to reflect folder name Minio integration with Object store (#156) * initial WIP integration with Object store * List WIP * minio listobject function changes complete * Code review changes and work in progress for the mock objectstore unit testing cases * Warning fix redeclaration of err * Warning fix redeclaration of err * code review comments & unit testing inprogress * fix compilation bug * Fixed code review comments & added GetObject Mock test case * rearraged the mock test file and gateway storj test file in to the proper directory * added the missing file * code clean up * fix lint error on the mock generated code * modified per code review comments * added the PutObject mock test case * added the GetObjectInfo mock test case * added listobject mock test case * fixed package from storj to miniogw * resolved the gateway-storj.go initialization merge conflict update readme (#174) added assertion for unused errors (#152) merging this PR to avoid future issues updating github user to personal account (#171) Test coverage ranger (#168) * Fixed go panic for corner case * Initial test coverage for ranger pkg streamstore: add passthrough implementation (#176) this doesn't implement streamstore, this just allows us to try and get the june demo working again in the meantime StatDB (#144) * add statdb proto and example client * server logic * update readme * remove boltdb from service.go * sqlite3 * add statdb server executable file * create statdb node table if it does not exist already * get UpdateBatch working * update based on jt review * remove some commented lines * fix linting issues * reformat * apiKey -> APIKey * update statdb client apiKey->APIKey Update README.md Update README.md overlay: correct dockerfile db (#179) cmd/hc, cmd/gw, cmd/captplanet: simplify setup/run commands (#178) also allows much more customization of services within captain planet, such as reconfiguring the overlay service to use redis pkg/process: don't require json formatting (#177) Cleanup metadata across layers (#180) * Cleanup metadata across layers * Fix pointer db tests Kademlia Routing Table (#164) * adds comment * runs deps * creates boltdb kademlia routing table * protobuf updates * adds reverselist to mockkeyvaluestore interface * xor wip * xor wip * fixes xor sort * runs go fmt * fixes * goimports again * trying to fix travis tests * fixes mock tests Ranger refactoring (#158) * Fixed go panic for corner case * Cosmetic changes, and small error fixes miniogw: log all errors (#182) * miniogw: log all errors * tests added * doc comment to satisfy linter * fix test failure Jennifer added to CLA list * Temporary fix for storage/redis list method test
2018-08-02 19:36:57 +01:00
}
func TestCacheSize(t *testing.T) {
rt, cleanup := createRoutingTable(t, teststorj.NodeIDFromString("AA"))
2018-09-11 14:57:12 +01:00
defer cleanup()
expected := rt.rcBucketSize
result := rt.CacheSize()
assert.Equal(t, expected, result)
Testcoverage kademlia (#154) * Unit test covarege increased for kademlia pkg go style formatting added Removed DHT param from newTestKademlia method, added comments for Bucket methods that informs that these tests will need to be updated unnecessary comment deleted from newTestKademlia Adjust Segment Store to the updated interface (#160) * Adjust Segment Store to the updated interface * Move /pkg/storage/segment to /pkg/storage/segments * Fix overlay client tests * Revert changes in NewOverlayClient return value * Rename `rem` to `seg` * Implement Meta() captplanet (#159) * captplanet I kind of went overboard this weekend. The major goal of this changeset is to provide an environment for local development where all of the various services can be easily run together. Developing on Storj v3 should be as easy as running a setup command and a run command! To do this, this changeset introduces a new tool called captplanet, which combines the powers of the Overlay Cache, the PointerDB, the PieceStore, Kademlia, the Minio Gateway, etc. Running 40 farmers and a heavy client inside the same process forced a rethinking of the "services" that we had. To avoid confusion by reusing prior terms, this changeset introduces two new types: Providers and Responsibilities. I wanted to avoid as many merge conflicts as possible, so I left the existing Services and code for now, but if people like this route we can clean up the duplication. A Responsibility is a collection of gRPC methods and corresponding state. The following systems are examples of Responsibilities: * Kademlia * OverlayCache * PointerDB * StatDB * PieceStore * etc. A Provider is a collection of Responsibilities that share an Identity, such as: * The heavy client * The farmer * The gateway An Identity is a public/private key pair, a node id, etc. Farmers all need different Identities, so captplanet needs to support running multiple concurrent Providers with different Identities. Each Responsibility and Provider should allow for configuration of multiple copies on its own so creating Responsibilities and Providers use a new workflow. To make a Responsibility, one should create a "config" struct, such as: ``` type Config struct { RepairThreshold int `help:"If redundancy falls below this number of pieces, repair is triggered" default:"30"` SuccessThreshold int `help:"If redundancy is above this number then no additional uploads are needed" default:"40"` } ``` To use "config" structs, this changeset introduces another new library called 'cfgstruct', which allows for the configuration of arbitrary structs through flagsets, and thus through cobra and viper. cfgstruct relies on Go's "struct tags" feature to document help information and default values. Config structs can be configured via cfgstruct.Bind for binding the struct to a flagset. Because this configuration system makes setup and configuration easier *in general*, additional commands are provided that allow for easy standup of separate Providers. Please make sure to check out: * cmd/captplanet/farmer/main.go (a new farmer binary) * cmd/captplanet/hc/main.go (a new heavy client binary) * cmd/captplanet/gw/main.go (a new minio gateway binary) Usage: ``` $ go install -v storj.io/storj/cmd/captplanet $ captplanet setup $ captplanet run ``` Configuration is placed by default in `~/.storj/capt/` Other changes: * introduces new config structs for currently existing Responsibilities that conform to the new Responsibility interface. Please see the `pkg/*/config.go` files for examples. * integrates the PointerDB API key with other global configuration via flags, instead of through environment variables through viper like it's been doing. (ultimately this should also change to use the PointerDB config struct but this is an okay shortterm solution). * changes the Overlay cache to use a URL for database configuration instead of separate redis and bolt config settings. * stubs out some peer identity skeleton code (but not the meat). * Fixes the SegmentStore to use the overlay client and pointerdb clients instead of gRPC client code directly * Leaves a very clear spot where we need to tie the object to stream to segment store together. There's sort of a "golden spike" opportunity to connect all the train tracks together at the bottom of pkg/miniogw/config.go, labeled with a bunch of TODOs. Future stuff: * I now prefer this design over the original pkg/process.Service thing I had been pushing before (sorry!) * The experience of trying to have multiple farmers configurable concurrently led me to prefer config structs over global flags (I finally came around) or using viper directly. I think global flags are okay sometimes but in general going forward we should try and get all relevant config into config structs. * If you all like this direction, I think we can go delete my old Service interfaces and a bunch of flags and clean up a bunch of stuff. * If you don't like this direction, it's no sweat at all, and despite how much code there is here I'm not very tied to any of this! Considering a lot of this was written between midnight and 6 am, it might not be any good! * bind tests Add files for testing builds in docker (#161) * Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis pkg/provider: with pkg/provider merged, make a single heavy client binary, gateway binary, and deprecate old services (#165) * pkg/provider: with pkg/provider merged, make a single heavy client binary and deprecate old services * add setup to gw binary too * captplanet: output what addresses everything is listening on * revert peertls/io_util changes * define config flag across all commands * use trimsuffix fix docker makefile (#170) * fix makefile protos: update protobufs with go generate (#169) the import for timestamp and duration should use the path provided by a standard protocol buffer library installation Refactor List in PointerDB (#163) * Refactor List in Pointer DB * Fix pointerdb-client example * Fix issue in Path type related to empty paths * Test for the PointerDB service with some fixes * Fixed debug message in example: trancated --> more * GoDoc comments for unexported methods * TODO comment to check if Put is overwriting * Log warning if protobuf timestamp cannot be converted * TODO comment to make ListPageLimit configurable * Rename 'segment' package to 'segments' to reflect folder name Minio integration with Object store (#156) * initial WIP integration with Object store * List WIP * minio listobject function changes complete * Code review changes and work in progress for the mock objectstore unit testing cases * Warning fix redeclaration of err * Warning fix redeclaration of err * code review comments & unit testing inprogress * fix compilation bug * Fixed code review comments & added GetObject Mock test case * rearraged the mock test file and gateway storj test file in to the proper directory * added the missing file * code clean up * fix lint error on the mock generated code * modified per code review comments * added the PutObject mock test case * added the GetObjectInfo mock test case * added listobject mock test case * fixed package from storj to miniogw * resolved the gateway-storj.go initialization merge conflict update readme (#174) added assertion for unused errors (#152) merging this PR to avoid future issues updating github user to personal account (#171) Test coverage ranger (#168) * Fixed go panic for corner case * Initial test coverage for ranger pkg streamstore: add passthrough implementation (#176) this doesn't implement streamstore, this just allows us to try and get the june demo working again in the meantime StatDB (#144) * add statdb proto and example client * server logic * update readme * remove boltdb from service.go * sqlite3 * add statdb server executable file * create statdb node table if it does not exist already * get UpdateBatch working * update based on jt review * remove some commented lines * fix linting issues * reformat * apiKey -> APIKey * update statdb client apiKey->APIKey Update README.md Update README.md overlay: correct dockerfile db (#179) cmd/hc, cmd/gw, cmd/captplanet: simplify setup/run commands (#178) also allows much more customization of services within captain planet, such as reconfiguring the overlay service to use redis pkg/process: don't require json formatting (#177) Cleanup metadata across layers (#180) * Cleanup metadata across layers * Fix pointer db tests Kademlia Routing Table (#164) * adds comment * runs deps * creates boltdb kademlia routing table * protobuf updates * adds reverselist to mockkeyvaluestore interface * xor wip * xor wip * fixes xor sort * runs go fmt * fixes * goimports again * trying to fix travis tests * fixes mock tests Ranger refactoring (#158) * Fixed go panic for corner case * Cosmetic changes, and small error fixes miniogw: log all errors (#182) * miniogw: log all errors * tests added * doc comment to satisfy linter * fix test failure Jennifer added to CLA list * Temporary fix for storage/redis list method test
2018-08-02 19:36:57 +01:00
}
func TestGetBucket(t *testing.T) {
rt, cleanup := createRoutingTable(t, teststorj.NodeIDFromString("AA"))
2018-09-11 14:57:12 +01:00
defer cleanup()
node := teststorj.MockNode("AA")
node2 := teststorj.MockNode("BB")
ok, err := rt.addNode(node2)
assert.True(t, ok)
assert.NoError(t, err)
Testcoverage kademlia (#154) * Unit test covarege increased for kademlia pkg go style formatting added Removed DHT param from newTestKademlia method, added comments for Bucket methods that informs that these tests will need to be updated unnecessary comment deleted from newTestKademlia Adjust Segment Store to the updated interface (#160) * Adjust Segment Store to the updated interface * Move /pkg/storage/segment to /pkg/storage/segments * Fix overlay client tests * Revert changes in NewOverlayClient return value * Rename `rem` to `seg` * Implement Meta() captplanet (#159) * captplanet I kind of went overboard this weekend. The major goal of this changeset is to provide an environment for local development where all of the various services can be easily run together. Developing on Storj v3 should be as easy as running a setup command and a run command! To do this, this changeset introduces a new tool called captplanet, which combines the powers of the Overlay Cache, the PointerDB, the PieceStore, Kademlia, the Minio Gateway, etc. Running 40 farmers and a heavy client inside the same process forced a rethinking of the "services" that we had. To avoid confusion by reusing prior terms, this changeset introduces two new types: Providers and Responsibilities. I wanted to avoid as many merge conflicts as possible, so I left the existing Services and code for now, but if people like this route we can clean up the duplication. A Responsibility is a collection of gRPC methods and corresponding state. The following systems are examples of Responsibilities: * Kademlia * OverlayCache * PointerDB * StatDB * PieceStore * etc. A Provider is a collection of Responsibilities that share an Identity, such as: * The heavy client * The farmer * The gateway An Identity is a public/private key pair, a node id, etc. Farmers all need different Identities, so captplanet needs to support running multiple concurrent Providers with different Identities. Each Responsibility and Provider should allow for configuration of multiple copies on its own so creating Responsibilities and Providers use a new workflow. To make a Responsibility, one should create a "config" struct, such as: ``` type Config struct { RepairThreshold int `help:"If redundancy falls below this number of pieces, repair is triggered" default:"30"` SuccessThreshold int `help:"If redundancy is above this number then no additional uploads are needed" default:"40"` } ``` To use "config" structs, this changeset introduces another new library called 'cfgstruct', which allows for the configuration of arbitrary structs through flagsets, and thus through cobra and viper. cfgstruct relies on Go's "struct tags" feature to document help information and default values. Config structs can be configured via cfgstruct.Bind for binding the struct to a flagset. Because this configuration system makes setup and configuration easier *in general*, additional commands are provided that allow for easy standup of separate Providers. Please make sure to check out: * cmd/captplanet/farmer/main.go (a new farmer binary) * cmd/captplanet/hc/main.go (a new heavy client binary) * cmd/captplanet/gw/main.go (a new minio gateway binary) Usage: ``` $ go install -v storj.io/storj/cmd/captplanet $ captplanet setup $ captplanet run ``` Configuration is placed by default in `~/.storj/capt/` Other changes: * introduces new config structs for currently existing Responsibilities that conform to the new Responsibility interface. Please see the `pkg/*/config.go` files for examples. * integrates the PointerDB API key with other global configuration via flags, instead of through environment variables through viper like it's been doing. (ultimately this should also change to use the PointerDB config struct but this is an okay shortterm solution). * changes the Overlay cache to use a URL for database configuration instead of separate redis and bolt config settings. * stubs out some peer identity skeleton code (but not the meat). * Fixes the SegmentStore to use the overlay client and pointerdb clients instead of gRPC client code directly * Leaves a very clear spot where we need to tie the object to stream to segment store together. There's sort of a "golden spike" opportunity to connect all the train tracks together at the bottom of pkg/miniogw/config.go, labeled with a bunch of TODOs. Future stuff: * I now prefer this design over the original pkg/process.Service thing I had been pushing before (sorry!) * The experience of trying to have multiple farmers configurable concurrently led me to prefer config structs over global flags (I finally came around) or using viper directly. I think global flags are okay sometimes but in general going forward we should try and get all relevant config into config structs. * If you all like this direction, I think we can go delete my old Service interfaces and a bunch of flags and clean up a bunch of stuff. * If you don't like this direction, it's no sweat at all, and despite how much code there is here I'm not very tied to any of this! Considering a lot of this was written between midnight and 6 am, it might not be any good! * bind tests Add files for testing builds in docker (#161) * Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis pkg/provider: with pkg/provider merged, make a single heavy client binary, gateway binary, and deprecate old services (#165) * pkg/provider: with pkg/provider merged, make a single heavy client binary and deprecate old services * add setup to gw binary too * captplanet: output what addresses everything is listening on * revert peertls/io_util changes * define config flag across all commands * use trimsuffix fix docker makefile (#170) * fix makefile protos: update protobufs with go generate (#169) the import for timestamp and duration should use the path provided by a standard protocol buffer library installation Refactor List in PointerDB (#163) * Refactor List in Pointer DB * Fix pointerdb-client example * Fix issue in Path type related to empty paths * Test for the PointerDB service with some fixes * Fixed debug message in example: trancated --> more * GoDoc comments for unexported methods * TODO comment to check if Put is overwriting * Log warning if protobuf timestamp cannot be converted * TODO comment to make ListPageLimit configurable * Rename 'segment' package to 'segments' to reflect folder name Minio integration with Object store (#156) * initial WIP integration with Object store * List WIP * minio listobject function changes complete * Code review changes and work in progress for the mock objectstore unit testing cases * Warning fix redeclaration of err * Warning fix redeclaration of err * code review comments & unit testing inprogress * fix compilation bug * Fixed code review comments & added GetObject Mock test case * rearraged the mock test file and gateway storj test file in to the proper directory * added the missing file * code clean up * fix lint error on the mock generated code * modified per code review comments * added the PutObject mock test case * added the GetObjectInfo mock test case * added listobject mock test case * fixed package from storj to miniogw * resolved the gateway-storj.go initialization merge conflict update readme (#174) added assertion for unused errors (#152) merging this PR to avoid future issues updating github user to personal account (#171) Test coverage ranger (#168) * Fixed go panic for corner case * Initial test coverage for ranger pkg streamstore: add passthrough implementation (#176) this doesn't implement streamstore, this just allows us to try and get the june demo working again in the meantime StatDB (#144) * add statdb proto and example client * server logic * update readme * remove boltdb from service.go * sqlite3 * add statdb server executable file * create statdb node table if it does not exist already * get UpdateBatch working * update based on jt review * remove some commented lines * fix linting issues * reformat * apiKey -> APIKey * update statdb client apiKey->APIKey Update README.md Update README.md overlay: correct dockerfile db (#179) cmd/hc, cmd/gw, cmd/captplanet: simplify setup/run commands (#178) also allows much more customization of services within captain planet, such as reconfiguring the overlay service to use redis pkg/process: don't require json formatting (#177) Cleanup metadata across layers (#180) * Cleanup metadata across layers * Fix pointer db tests Kademlia Routing Table (#164) * adds comment * runs deps * creates boltdb kademlia routing table * protobuf updates * adds reverselist to mockkeyvaluestore interface * xor wip * xor wip * fixes xor sort * runs go fmt * fixes * goimports again * trying to fix travis tests * fixes mock tests Ranger refactoring (#158) * Fixed go panic for corner case * Cosmetic changes, and small error fixes miniogw: log all errors (#182) * miniogw: log all errors * tests added * doc comment to satisfy linter * fix test failure Jennifer added to CLA list * Temporary fix for storage/redis list method test
2018-08-02 19:36:57 +01:00
cases := []struct {
nodeID storj.NodeID
2018-12-18 18:04:46 +00:00
expected []*pb.Node
ok bool
}{
{nodeID: node.Id,
2018-12-18 18:04:46 +00:00
expected: []*pb.Node{node, node2},
ok: true,
},
{nodeID: node2.Id,
2018-12-18 18:04:46 +00:00
expected: []*pb.Node{node, node2},
ok: true,
},
}
for i, v := range cases {
2018-12-18 18:04:46 +00:00
b, e := rt.GetNodes(node2.Id)
for j, w := range v.expected {
if !assert.True(t, bytes.Equal(w.Id.Bytes(), b[j].Id.Bytes())) {
t.Logf("case %v failed expected: ", i)
}
}
if !assert.Equal(t, v.ok, e) {
t.Logf("case %v failed ok: ", i)
Testcoverage kademlia (#154) * Unit test covarege increased for kademlia pkg go style formatting added Removed DHT param from newTestKademlia method, added comments for Bucket methods that informs that these tests will need to be updated unnecessary comment deleted from newTestKademlia Adjust Segment Store to the updated interface (#160) * Adjust Segment Store to the updated interface * Move /pkg/storage/segment to /pkg/storage/segments * Fix overlay client tests * Revert changes in NewOverlayClient return value * Rename `rem` to `seg` * Implement Meta() captplanet (#159) * captplanet I kind of went overboard this weekend. The major goal of this changeset is to provide an environment for local development where all of the various services can be easily run together. Developing on Storj v3 should be as easy as running a setup command and a run command! To do this, this changeset introduces a new tool called captplanet, which combines the powers of the Overlay Cache, the PointerDB, the PieceStore, Kademlia, the Minio Gateway, etc. Running 40 farmers and a heavy client inside the same process forced a rethinking of the "services" that we had. To avoid confusion by reusing prior terms, this changeset introduces two new types: Providers and Responsibilities. I wanted to avoid as many merge conflicts as possible, so I left the existing Services and code for now, but if people like this route we can clean up the duplication. A Responsibility is a collection of gRPC methods and corresponding state. The following systems are examples of Responsibilities: * Kademlia * OverlayCache * PointerDB * StatDB * PieceStore * etc. A Provider is a collection of Responsibilities that share an Identity, such as: * The heavy client * The farmer * The gateway An Identity is a public/private key pair, a node id, etc. Farmers all need different Identities, so captplanet needs to support running multiple concurrent Providers with different Identities. Each Responsibility and Provider should allow for configuration of multiple copies on its own so creating Responsibilities and Providers use a new workflow. To make a Responsibility, one should create a "config" struct, such as: ``` type Config struct { RepairThreshold int `help:"If redundancy falls below this number of pieces, repair is triggered" default:"30"` SuccessThreshold int `help:"If redundancy is above this number then no additional uploads are needed" default:"40"` } ``` To use "config" structs, this changeset introduces another new library called 'cfgstruct', which allows for the configuration of arbitrary structs through flagsets, and thus through cobra and viper. cfgstruct relies on Go's "struct tags" feature to document help information and default values. Config structs can be configured via cfgstruct.Bind for binding the struct to a flagset. Because this configuration system makes setup and configuration easier *in general*, additional commands are provided that allow for easy standup of separate Providers. Please make sure to check out: * cmd/captplanet/farmer/main.go (a new farmer binary) * cmd/captplanet/hc/main.go (a new heavy client binary) * cmd/captplanet/gw/main.go (a new minio gateway binary) Usage: ``` $ go install -v storj.io/storj/cmd/captplanet $ captplanet setup $ captplanet run ``` Configuration is placed by default in `~/.storj/capt/` Other changes: * introduces new config structs for currently existing Responsibilities that conform to the new Responsibility interface. Please see the `pkg/*/config.go` files for examples. * integrates the PointerDB API key with other global configuration via flags, instead of through environment variables through viper like it's been doing. (ultimately this should also change to use the PointerDB config struct but this is an okay shortterm solution). * changes the Overlay cache to use a URL for database configuration instead of separate redis and bolt config settings. * stubs out some peer identity skeleton code (but not the meat). * Fixes the SegmentStore to use the overlay client and pointerdb clients instead of gRPC client code directly * Leaves a very clear spot where we need to tie the object to stream to segment store together. There's sort of a "golden spike" opportunity to connect all the train tracks together at the bottom of pkg/miniogw/config.go, labeled with a bunch of TODOs. Future stuff: * I now prefer this design over the original pkg/process.Service thing I had been pushing before (sorry!) * The experience of trying to have multiple farmers configurable concurrently led me to prefer config structs over global flags (I finally came around) or using viper directly. I think global flags are okay sometimes but in general going forward we should try and get all relevant config into config structs. * If you all like this direction, I think we can go delete my old Service interfaces and a bunch of flags and clean up a bunch of stuff. * If you don't like this direction, it's no sweat at all, and despite how much code there is here I'm not very tied to any of this! Considering a lot of this was written between midnight and 6 am, it might not be any good! * bind tests Add files for testing builds in docker (#161) * Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis pkg/provider: with pkg/provider merged, make a single heavy client binary, gateway binary, and deprecate old services (#165) * pkg/provider: with pkg/provider merged, make a single heavy client binary and deprecate old services * add setup to gw binary too * captplanet: output what addresses everything is listening on * revert peertls/io_util changes * define config flag across all commands * use trimsuffix fix docker makefile (#170) * fix makefile protos: update protobufs with go generate (#169) the import for timestamp and duration should use the path provided by a standard protocol buffer library installation Refactor List in PointerDB (#163) * Refactor List in Pointer DB * Fix pointerdb-client example * Fix issue in Path type related to empty paths * Test for the PointerDB service with some fixes * Fixed debug message in example: trancated --> more * GoDoc comments for unexported methods * TODO comment to check if Put is overwriting * Log warning if protobuf timestamp cannot be converted * TODO comment to make ListPageLimit configurable * Rename 'segment' package to 'segments' to reflect folder name Minio integration with Object store (#156) * initial WIP integration with Object store * List WIP * minio listobject function changes complete * Code review changes and work in progress for the mock objectstore unit testing cases * Warning fix redeclaration of err * Warning fix redeclaration of err * code review comments & unit testing inprogress * fix compilation bug * Fixed code review comments & added GetObject Mock test case * rearraged the mock test file and gateway storj test file in to the proper directory * added the missing file * code clean up * fix lint error on the mock generated code * modified per code review comments * added the PutObject mock test case * added the GetObjectInfo mock test case * added listobject mock test case * fixed package from storj to miniogw * resolved the gateway-storj.go initialization merge conflict update readme (#174) added assertion for unused errors (#152) merging this PR to avoid future issues updating github user to personal account (#171) Test coverage ranger (#168) * Fixed go panic for corner case * Initial test coverage for ranger pkg streamstore: add passthrough implementation (#176) this doesn't implement streamstore, this just allows us to try and get the june demo working again in the meantime StatDB (#144) * add statdb proto and example client * server logic * update readme * remove boltdb from service.go * sqlite3 * add statdb server executable file * create statdb node table if it does not exist already * get UpdateBatch working * update based on jt review * remove some commented lines * fix linting issues * reformat * apiKey -> APIKey * update statdb client apiKey->APIKey Update README.md Update README.md overlay: correct dockerfile db (#179) cmd/hc, cmd/gw, cmd/captplanet: simplify setup/run commands (#178) also allows much more customization of services within captain planet, such as reconfiguring the overlay service to use redis pkg/process: don't require json formatting (#177) Cleanup metadata across layers (#180) * Cleanup metadata across layers * Fix pointer db tests Kademlia Routing Table (#164) * adds comment * runs deps * creates boltdb kademlia routing table * protobuf updates * adds reverselist to mockkeyvaluestore interface * xor wip * xor wip * fixes xor sort * runs go fmt * fixes * goimports again * trying to fix travis tests * fixes mock tests Ranger refactoring (#158) * Fixed go panic for corner case * Cosmetic changes, and small error fixes miniogw: log all errors (#182) * miniogw: log all errors * tests added * doc comment to satisfy linter * fix test failure Jennifer added to CLA list * Temporary fix for storage/redis list method test
2018-08-02 19:36:57 +01:00
}
}
Testcoverage kademlia (#154) * Unit test covarege increased for kademlia pkg go style formatting added Removed DHT param from newTestKademlia method, added comments for Bucket methods that informs that these tests will need to be updated unnecessary comment deleted from newTestKademlia Adjust Segment Store to the updated interface (#160) * Adjust Segment Store to the updated interface * Move /pkg/storage/segment to /pkg/storage/segments * Fix overlay client tests * Revert changes in NewOverlayClient return value * Rename `rem` to `seg` * Implement Meta() captplanet (#159) * captplanet I kind of went overboard this weekend. The major goal of this changeset is to provide an environment for local development where all of the various services can be easily run together. Developing on Storj v3 should be as easy as running a setup command and a run command! To do this, this changeset introduces a new tool called captplanet, which combines the powers of the Overlay Cache, the PointerDB, the PieceStore, Kademlia, the Minio Gateway, etc. Running 40 farmers and a heavy client inside the same process forced a rethinking of the "services" that we had. To avoid confusion by reusing prior terms, this changeset introduces two new types: Providers and Responsibilities. I wanted to avoid as many merge conflicts as possible, so I left the existing Services and code for now, but if people like this route we can clean up the duplication. A Responsibility is a collection of gRPC methods and corresponding state. The following systems are examples of Responsibilities: * Kademlia * OverlayCache * PointerDB * StatDB * PieceStore * etc. A Provider is a collection of Responsibilities that share an Identity, such as: * The heavy client * The farmer * The gateway An Identity is a public/private key pair, a node id, etc. Farmers all need different Identities, so captplanet needs to support running multiple concurrent Providers with different Identities. Each Responsibility and Provider should allow for configuration of multiple copies on its own so creating Responsibilities and Providers use a new workflow. To make a Responsibility, one should create a "config" struct, such as: ``` type Config struct { RepairThreshold int `help:"If redundancy falls below this number of pieces, repair is triggered" default:"30"` SuccessThreshold int `help:"If redundancy is above this number then no additional uploads are needed" default:"40"` } ``` To use "config" structs, this changeset introduces another new library called 'cfgstruct', which allows for the configuration of arbitrary structs through flagsets, and thus through cobra and viper. cfgstruct relies on Go's "struct tags" feature to document help information and default values. Config structs can be configured via cfgstruct.Bind for binding the struct to a flagset. Because this configuration system makes setup and configuration easier *in general*, additional commands are provided that allow for easy standup of separate Providers. Please make sure to check out: * cmd/captplanet/farmer/main.go (a new farmer binary) * cmd/captplanet/hc/main.go (a new heavy client binary) * cmd/captplanet/gw/main.go (a new minio gateway binary) Usage: ``` $ go install -v storj.io/storj/cmd/captplanet $ captplanet setup $ captplanet run ``` Configuration is placed by default in `~/.storj/capt/` Other changes: * introduces new config structs for currently existing Responsibilities that conform to the new Responsibility interface. Please see the `pkg/*/config.go` files for examples. * integrates the PointerDB API key with other global configuration via flags, instead of through environment variables through viper like it's been doing. (ultimately this should also change to use the PointerDB config struct but this is an okay shortterm solution). * changes the Overlay cache to use a URL for database configuration instead of separate redis and bolt config settings. * stubs out some peer identity skeleton code (but not the meat). * Fixes the SegmentStore to use the overlay client and pointerdb clients instead of gRPC client code directly * Leaves a very clear spot where we need to tie the object to stream to segment store together. There's sort of a "golden spike" opportunity to connect all the train tracks together at the bottom of pkg/miniogw/config.go, labeled with a bunch of TODOs. Future stuff: * I now prefer this design over the original pkg/process.Service thing I had been pushing before (sorry!) * The experience of trying to have multiple farmers configurable concurrently led me to prefer config structs over global flags (I finally came around) or using viper directly. I think global flags are okay sometimes but in general going forward we should try and get all relevant config into config structs. * If you all like this direction, I think we can go delete my old Service interfaces and a bunch of flags and clean up a bunch of stuff. * If you don't like this direction, it's no sweat at all, and despite how much code there is here I'm not very tied to any of this! Considering a lot of this was written between midnight and 6 am, it might not be any good! * bind tests Add files for testing builds in docker (#161) * Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis pkg/provider: with pkg/provider merged, make a single heavy client binary, gateway binary, and deprecate old services (#165) * pkg/provider: with pkg/provider merged, make a single heavy client binary and deprecate old services * add setup to gw binary too * captplanet: output what addresses everything is listening on * revert peertls/io_util changes * define config flag across all commands * use trimsuffix fix docker makefile (#170) * fix makefile protos: update protobufs with go generate (#169) the import for timestamp and duration should use the path provided by a standard protocol buffer library installation Refactor List in PointerDB (#163) * Refactor List in Pointer DB * Fix pointerdb-client example * Fix issue in Path type related to empty paths * Test for the PointerDB service with some fixes * Fixed debug message in example: trancated --> more * GoDoc comments for unexported methods * TODO comment to check if Put is overwriting * Log warning if protobuf timestamp cannot be converted * TODO comment to make ListPageLimit configurable * Rename 'segment' package to 'segments' to reflect folder name Minio integration with Object store (#156) * initial WIP integration with Object store * List WIP * minio listobject function changes complete * Code review changes and work in progress for the mock objectstore unit testing cases * Warning fix redeclaration of err * Warning fix redeclaration of err * code review comments & unit testing inprogress * fix compilation bug * Fixed code review comments & added GetObject Mock test case * rearraged the mock test file and gateway storj test file in to the proper directory * added the missing file * code clean up * fix lint error on the mock generated code * modified per code review comments * added the PutObject mock test case * added the GetObjectInfo mock test case * added listobject mock test case * fixed package from storj to miniogw * resolved the gateway-storj.go initialization merge conflict update readme (#174) added assertion for unused errors (#152) merging this PR to avoid future issues updating github user to personal account (#171) Test coverage ranger (#168) * Fixed go panic for corner case * Initial test coverage for ranger pkg streamstore: add passthrough implementation (#176) this doesn't implement streamstore, this just allows us to try and get the june demo working again in the meantime StatDB (#144) * add statdb proto and example client * server logic * update readme * remove boltdb from service.go * sqlite3 * add statdb server executable file * create statdb node table if it does not exist already * get UpdateBatch working * update based on jt review * remove some commented lines * fix linting issues * reformat * apiKey -> APIKey * update statdb client apiKey->APIKey Update README.md Update README.md overlay: correct dockerfile db (#179) cmd/hc, cmd/gw, cmd/captplanet: simplify setup/run commands (#178) also allows much more customization of services within captain planet, such as reconfiguring the overlay service to use redis pkg/process: don't require json formatting (#177) Cleanup metadata across layers (#180) * Cleanup metadata across layers * Fix pointer db tests Kademlia Routing Table (#164) * adds comment * runs deps * creates boltdb kademlia routing table * protobuf updates * adds reverselist to mockkeyvaluestore interface * xor wip * xor wip * fixes xor sort * runs go fmt * fixes * goimports again * trying to fix travis tests * fixes mock tests Ranger refactoring (#158) * Fixed go panic for corner case * Cosmetic changes, and small error fixes miniogw: log all errors (#182) * miniogw: log all errors * tests added * doc comment to satisfy linter * fix test failure Jennifer added to CLA list * Temporary fix for storage/redis list method test
2018-08-02 19:36:57 +01:00
}
func TestKademliaFindNear(t *testing.T) {
rt, cleanup := createRoutingTable(t, teststorj.NodeIDFromString("AA"))
2018-09-11 14:57:12 +01:00
defer cleanup()
node1 := teststorj.MockNode("AA")
node2 := teststorj.MockNode("BB")
node3 := teststorj.MockNode("CC")
ok, err := rt.addNode(node2)
assert.True(t, ok)
assert.NoError(t, err)
cases := []struct {
testID string
node pb.Node
expectedNodes []*pb.Node
limit int
}{
{testID: "limit 1 on node1: return node1",
node: *node1,
expectedNodes: []*pb.Node{node1},
limit: 1,
},
{testID: "limit 2 on node3: return nodes2, node1",
node: *node3,
expectedNodes: []*pb.Node{node2, node1},
limit: 2,
},
{testID: "limit 1 on node3: return node2",
node: *node3,
expectedNodes: []*pb.Node{node2},
limit: 1,
},
{testID: "limit 3 on node3: return node2, node1",
node: *node3,
expectedNodes: []*pb.Node{node2, node1},
limit: 3,
},
}
for _, c := range cases {
t.Run(c.testID, func(t *testing.T) {
ns, err := rt.FindNear(c.node.Id, c.limit)
assert.NoError(t, err)
for i, n := range c.expectedNodes {
assert.True(t, bytes.Equal(n.Id.Bytes(), ns[i].Id.Bytes()))
}
})
}
Testcoverage kademlia (#154) * Unit test covarege increased for kademlia pkg go style formatting added Removed DHT param from newTestKademlia method, added comments for Bucket methods that informs that these tests will need to be updated unnecessary comment deleted from newTestKademlia Adjust Segment Store to the updated interface (#160) * Adjust Segment Store to the updated interface * Move /pkg/storage/segment to /pkg/storage/segments * Fix overlay client tests * Revert changes in NewOverlayClient return value * Rename `rem` to `seg` * Implement Meta() captplanet (#159) * captplanet I kind of went overboard this weekend. The major goal of this changeset is to provide an environment for local development where all of the various services can be easily run together. Developing on Storj v3 should be as easy as running a setup command and a run command! To do this, this changeset introduces a new tool called captplanet, which combines the powers of the Overlay Cache, the PointerDB, the PieceStore, Kademlia, the Minio Gateway, etc. Running 40 farmers and a heavy client inside the same process forced a rethinking of the "services" that we had. To avoid confusion by reusing prior terms, this changeset introduces two new types: Providers and Responsibilities. I wanted to avoid as many merge conflicts as possible, so I left the existing Services and code for now, but if people like this route we can clean up the duplication. A Responsibility is a collection of gRPC methods and corresponding state. The following systems are examples of Responsibilities: * Kademlia * OverlayCache * PointerDB * StatDB * PieceStore * etc. A Provider is a collection of Responsibilities that share an Identity, such as: * The heavy client * The farmer * The gateway An Identity is a public/private key pair, a node id, etc. Farmers all need different Identities, so captplanet needs to support running multiple concurrent Providers with different Identities. Each Responsibility and Provider should allow for configuration of multiple copies on its own so creating Responsibilities and Providers use a new workflow. To make a Responsibility, one should create a "config" struct, such as: ``` type Config struct { RepairThreshold int `help:"If redundancy falls below this number of pieces, repair is triggered" default:"30"` SuccessThreshold int `help:"If redundancy is above this number then no additional uploads are needed" default:"40"` } ``` To use "config" structs, this changeset introduces another new library called 'cfgstruct', which allows for the configuration of arbitrary structs through flagsets, and thus through cobra and viper. cfgstruct relies on Go's "struct tags" feature to document help information and default values. Config structs can be configured via cfgstruct.Bind for binding the struct to a flagset. Because this configuration system makes setup and configuration easier *in general*, additional commands are provided that allow for easy standup of separate Providers. Please make sure to check out: * cmd/captplanet/farmer/main.go (a new farmer binary) * cmd/captplanet/hc/main.go (a new heavy client binary) * cmd/captplanet/gw/main.go (a new minio gateway binary) Usage: ``` $ go install -v storj.io/storj/cmd/captplanet $ captplanet setup $ captplanet run ``` Configuration is placed by default in `~/.storj/capt/` Other changes: * introduces new config structs for currently existing Responsibilities that conform to the new Responsibility interface. Please see the `pkg/*/config.go` files for examples. * integrates the PointerDB API key with other global configuration via flags, instead of through environment variables through viper like it's been doing. (ultimately this should also change to use the PointerDB config struct but this is an okay shortterm solution). * changes the Overlay cache to use a URL for database configuration instead of separate redis and bolt config settings. * stubs out some peer identity skeleton code (but not the meat). * Fixes the SegmentStore to use the overlay client and pointerdb clients instead of gRPC client code directly * Leaves a very clear spot where we need to tie the object to stream to segment store together. There's sort of a "golden spike" opportunity to connect all the train tracks together at the bottom of pkg/miniogw/config.go, labeled with a bunch of TODOs. Future stuff: * I now prefer this design over the original pkg/process.Service thing I had been pushing before (sorry!) * The experience of trying to have multiple farmers configurable concurrently led me to prefer config structs over global flags (I finally came around) or using viper directly. I think global flags are okay sometimes but in general going forward we should try and get all relevant config into config structs. * If you all like this direction, I think we can go delete my old Service interfaces and a bunch of flags and clean up a bunch of stuff. * If you don't like this direction, it's no sweat at all, and despite how much code there is here I'm not very tied to any of this! Considering a lot of this was written between midnight and 6 am, it might not be any good! * bind tests Add files for testing builds in docker (#161) * Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis pkg/provider: with pkg/provider merged, make a single heavy client binary, gateway binary, and deprecate old services (#165) * pkg/provider: with pkg/provider merged, make a single heavy client binary and deprecate old services * add setup to gw binary too * captplanet: output what addresses everything is listening on * revert peertls/io_util changes * define config flag across all commands * use trimsuffix fix docker makefile (#170) * fix makefile protos: update protobufs with go generate (#169) the import for timestamp and duration should use the path provided by a standard protocol buffer library installation Refactor List in PointerDB (#163) * Refactor List in Pointer DB * Fix pointerdb-client example * Fix issue in Path type related to empty paths * Test for the PointerDB service with some fixes * Fixed debug message in example: trancated --> more * GoDoc comments for unexported methods * TODO comment to check if Put is overwriting * Log warning if protobuf timestamp cannot be converted * TODO comment to make ListPageLimit configurable * Rename 'segment' package to 'segments' to reflect folder name Minio integration with Object store (#156) * initial WIP integration with Object store * List WIP * minio listobject function changes complete * Code review changes and work in progress for the mock objectstore unit testing cases * Warning fix redeclaration of err * Warning fix redeclaration of err * code review comments & unit testing inprogress * fix compilation bug * Fixed code review comments & added GetObject Mock test case * rearraged the mock test file and gateway storj test file in to the proper directory * added the missing file * code clean up * fix lint error on the mock generated code * modified per code review comments * added the PutObject mock test case * added the GetObjectInfo mock test case * added listobject mock test case * fixed package from storj to miniogw * resolved the gateway-storj.go initialization merge conflict update readme (#174) added assertion for unused errors (#152) merging this PR to avoid future issues updating github user to personal account (#171) Test coverage ranger (#168) * Fixed go panic for corner case * Initial test coverage for ranger pkg streamstore: add passthrough implementation (#176) this doesn't implement streamstore, this just allows us to try and get the june demo working again in the meantime StatDB (#144) * add statdb proto and example client * server logic * update readme * remove boltdb from service.go * sqlite3 * add statdb server executable file * create statdb node table if it does not exist already * get UpdateBatch working * update based on jt review * remove some commented lines * fix linting issues * reformat * apiKey -> APIKey * update statdb client apiKey->APIKey Update README.md Update README.md overlay: correct dockerfile db (#179) cmd/hc, cmd/gw, cmd/captplanet: simplify setup/run commands (#178) also allows much more customization of services within captain planet, such as reconfiguring the overlay service to use redis pkg/process: don't require json formatting (#177) Cleanup metadata across layers (#180) * Cleanup metadata across layers * Fix pointer db tests Kademlia Routing Table (#164) * adds comment * runs deps * creates boltdb kademlia routing table * protobuf updates * adds reverselist to mockkeyvaluestore interface * xor wip * xor wip * fixes xor sort * runs go fmt * fixes * goimports again * trying to fix travis tests * fixes mock tests Ranger refactoring (#158) * Fixed go panic for corner case * Cosmetic changes, and small error fixes miniogw: log all errors (#182) * miniogw: log all errors * tests added * doc comment to satisfy linter * fix test failure Jennifer added to CLA list * Temporary fix for storage/redis list method test
2018-08-02 19:36:57 +01:00
}
func TestConnectionSuccess(t *testing.T) {
id := teststorj.NodeIDFromString("AA")
rt, cleanup := createRoutingTable(t, id)
2018-09-11 14:57:12 +01:00
defer cleanup()
id2 := teststorj.NodeIDFromString("BB")
address1 := &pb.NodeAddress{Address: "a"}
address2 := &pb.NodeAddress{Address: "b"}
node1 := &pb.Node{Id: id, Address: address1, Type: pb.NodeType_STORAGE}
node2 := &pb.Node{Id: id2, Address: address2, Type: pb.NodeType_STORAGE}
cases := []struct {
testID string
node *pb.Node
id storj.NodeID
address *pb.NodeAddress
}{
{testID: "Update Node",
node: node1,
id: id,
address: address1,
},
{testID: "Create Node",
node: node2,
id: id2,
address: address2,
},
}
for _, c := range cases {
t.Run(c.testID, func(t *testing.T) {
err := rt.ConnectionSuccess(c.node)
assert.NoError(t, err)
v, err := rt.nodeBucketDB.Get(c.id.Bytes())
assert.NoError(t, err)
n, err := unmarshalNodes([]storage.Value{v})
assert.NoError(t, err)
assert.Equal(t, c.address.Address, n[0].Address.Address)
})
}
Testcoverage kademlia (#154) * Unit test covarege increased for kademlia pkg go style formatting added Removed DHT param from newTestKademlia method, added comments for Bucket methods that informs that these tests will need to be updated unnecessary comment deleted from newTestKademlia Adjust Segment Store to the updated interface (#160) * Adjust Segment Store to the updated interface * Move /pkg/storage/segment to /pkg/storage/segments * Fix overlay client tests * Revert changes in NewOverlayClient return value * Rename `rem` to `seg` * Implement Meta() captplanet (#159) * captplanet I kind of went overboard this weekend. The major goal of this changeset is to provide an environment for local development where all of the various services can be easily run together. Developing on Storj v3 should be as easy as running a setup command and a run command! To do this, this changeset introduces a new tool called captplanet, which combines the powers of the Overlay Cache, the PointerDB, the PieceStore, Kademlia, the Minio Gateway, etc. Running 40 farmers and a heavy client inside the same process forced a rethinking of the "services" that we had. To avoid confusion by reusing prior terms, this changeset introduces two new types: Providers and Responsibilities. I wanted to avoid as many merge conflicts as possible, so I left the existing Services and code for now, but if people like this route we can clean up the duplication. A Responsibility is a collection of gRPC methods and corresponding state. The following systems are examples of Responsibilities: * Kademlia * OverlayCache * PointerDB * StatDB * PieceStore * etc. A Provider is a collection of Responsibilities that share an Identity, such as: * The heavy client * The farmer * The gateway An Identity is a public/private key pair, a node id, etc. Farmers all need different Identities, so captplanet needs to support running multiple concurrent Providers with different Identities. Each Responsibility and Provider should allow for configuration of multiple copies on its own so creating Responsibilities and Providers use a new workflow. To make a Responsibility, one should create a "config" struct, such as: ``` type Config struct { RepairThreshold int `help:"If redundancy falls below this number of pieces, repair is triggered" default:"30"` SuccessThreshold int `help:"If redundancy is above this number then no additional uploads are needed" default:"40"` } ``` To use "config" structs, this changeset introduces another new library called 'cfgstruct', which allows for the configuration of arbitrary structs through flagsets, and thus through cobra and viper. cfgstruct relies on Go's "struct tags" feature to document help information and default values. Config structs can be configured via cfgstruct.Bind for binding the struct to a flagset. Because this configuration system makes setup and configuration easier *in general*, additional commands are provided that allow for easy standup of separate Providers. Please make sure to check out: * cmd/captplanet/farmer/main.go (a new farmer binary) * cmd/captplanet/hc/main.go (a new heavy client binary) * cmd/captplanet/gw/main.go (a new minio gateway binary) Usage: ``` $ go install -v storj.io/storj/cmd/captplanet $ captplanet setup $ captplanet run ``` Configuration is placed by default in `~/.storj/capt/` Other changes: * introduces new config structs for currently existing Responsibilities that conform to the new Responsibility interface. Please see the `pkg/*/config.go` files for examples. * integrates the PointerDB API key with other global configuration via flags, instead of through environment variables through viper like it's been doing. (ultimately this should also change to use the PointerDB config struct but this is an okay shortterm solution). * changes the Overlay cache to use a URL for database configuration instead of separate redis and bolt config settings. * stubs out some peer identity skeleton code (but not the meat). * Fixes the SegmentStore to use the overlay client and pointerdb clients instead of gRPC client code directly * Leaves a very clear spot where we need to tie the object to stream to segment store together. There's sort of a "golden spike" opportunity to connect all the train tracks together at the bottom of pkg/miniogw/config.go, labeled with a bunch of TODOs. Future stuff: * I now prefer this design over the original pkg/process.Service thing I had been pushing before (sorry!) * The experience of trying to have multiple farmers configurable concurrently led me to prefer config structs over global flags (I finally came around) or using viper directly. I think global flags are okay sometimes but in general going forward we should try and get all relevant config into config structs. * If you all like this direction, I think we can go delete my old Service interfaces and a bunch of flags and clean up a bunch of stuff. * If you don't like this direction, it's no sweat at all, and despite how much code there is here I'm not very tied to any of this! Considering a lot of this was written between midnight and 6 am, it might not be any good! * bind tests Add files for testing builds in docker (#161) * Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis pkg/provider: with pkg/provider merged, make a single heavy client binary, gateway binary, and deprecate old services (#165) * pkg/provider: with pkg/provider merged, make a single heavy client binary and deprecate old services * add setup to gw binary too * captplanet: output what addresses everything is listening on * revert peertls/io_util changes * define config flag across all commands * use trimsuffix fix docker makefile (#170) * fix makefile protos: update protobufs with go generate (#169) the import for timestamp and duration should use the path provided by a standard protocol buffer library installation Refactor List in PointerDB (#163) * Refactor List in Pointer DB * Fix pointerdb-client example * Fix issue in Path type related to empty paths * Test for the PointerDB service with some fixes * Fixed debug message in example: trancated --> more * GoDoc comments for unexported methods * TODO comment to check if Put is overwriting * Log warning if protobuf timestamp cannot be converted * TODO comment to make ListPageLimit configurable * Rename 'segment' package to 'segments' to reflect folder name Minio integration with Object store (#156) * initial WIP integration with Object store * List WIP * minio listobject function changes complete * Code review changes and work in progress for the mock objectstore unit testing cases * Warning fix redeclaration of err * Warning fix redeclaration of err * code review comments & unit testing inprogress * fix compilation bug * Fixed code review comments & added GetObject Mock test case * rearraged the mock test file and gateway storj test file in to the proper directory * added the missing file * code clean up * fix lint error on the mock generated code * modified per code review comments * added the PutObject mock test case * added the GetObjectInfo mock test case * added listobject mock test case * fixed package from storj to miniogw * resolved the gateway-storj.go initialization merge conflict update readme (#174) added assertion for unused errors (#152) merging this PR to avoid future issues updating github user to personal account (#171) Test coverage ranger (#168) * Fixed go panic for corner case * Initial test coverage for ranger pkg streamstore: add passthrough implementation (#176) this doesn't implement streamstore, this just allows us to try and get the june demo working again in the meantime StatDB (#144) * add statdb proto and example client * server logic * update readme * remove boltdb from service.go * sqlite3 * add statdb server executable file * create statdb node table if it does not exist already * get UpdateBatch working * update based on jt review * remove some commented lines * fix linting issues * reformat * apiKey -> APIKey * update statdb client apiKey->APIKey Update README.md Update README.md overlay: correct dockerfile db (#179) cmd/hc, cmd/gw, cmd/captplanet: simplify setup/run commands (#178) also allows much more customization of services within captain planet, such as reconfiguring the overlay service to use redis pkg/process: don't require json formatting (#177) Cleanup metadata across layers (#180) * Cleanup metadata across layers * Fix pointer db tests Kademlia Routing Table (#164) * adds comment * runs deps * creates boltdb kademlia routing table * protobuf updates * adds reverselist to mockkeyvaluestore interface * xor wip * xor wip * fixes xor sort * runs go fmt * fixes * goimports again * trying to fix travis tests * fixes mock tests Ranger refactoring (#158) * Fixed go panic for corner case * Cosmetic changes, and small error fixes miniogw: log all errors (#182) * miniogw: log all errors * tests added * doc comment to satisfy linter * fix test failure Jennifer added to CLA list * Temporary fix for storage/redis list method test
2018-08-02 19:36:57 +01:00
}
func TestUpdateSelf(t *testing.T) {
id := teststorj.NodeIDFromString("AA")
rt, cleanup := createRoutingTable(t, id)
defer cleanup()
address := &pb.NodeAddress{Address: "a"}
node := &pb.Node{Id: id, Address: address, Type: pb.NodeType_STORAGE}
cases := []struct {
testID string
node *pb.Node
id storj.NodeID
address *pb.NodeAddress
}{
{testID: "Update Node",
node: node,
id: id,
address: address,
},
}
for _, c := range cases {
t.Run(c.testID, func(t *testing.T) {
newNode := c.node
restrictions := &pb.NodeRestrictions{
FreeBandwidth: 10,
}
newNode.Restrictions = restrictions
err := rt.UpdateSelf(newNode)
assert.NoError(t, err)
v, err := rt.nodeBucketDB.Get(c.id.Bytes())
assert.NoError(t, err)
n, err := unmarshalNodes([]storage.Value{v})
assert.NoError(t, err)
assert.Equal(t, c.address.Address, n[0].Address.Address)
assert.Equal(t, newNode.Restrictions.GetFreeBandwidth(), n[0].Restrictions.GetFreeBandwidth())
})
}
}
Testcoverage kademlia (#154) * Unit test covarege increased for kademlia pkg go style formatting added Removed DHT param from newTestKademlia method, added comments for Bucket methods that informs that these tests will need to be updated unnecessary comment deleted from newTestKademlia Adjust Segment Store to the updated interface (#160) * Adjust Segment Store to the updated interface * Move /pkg/storage/segment to /pkg/storage/segments * Fix overlay client tests * Revert changes in NewOverlayClient return value * Rename `rem` to `seg` * Implement Meta() captplanet (#159) * captplanet I kind of went overboard this weekend. The major goal of this changeset is to provide an environment for local development where all of the various services can be easily run together. Developing on Storj v3 should be as easy as running a setup command and a run command! To do this, this changeset introduces a new tool called captplanet, which combines the powers of the Overlay Cache, the PointerDB, the PieceStore, Kademlia, the Minio Gateway, etc. Running 40 farmers and a heavy client inside the same process forced a rethinking of the "services" that we had. To avoid confusion by reusing prior terms, this changeset introduces two new types: Providers and Responsibilities. I wanted to avoid as many merge conflicts as possible, so I left the existing Services and code for now, but if people like this route we can clean up the duplication. A Responsibility is a collection of gRPC methods and corresponding state. The following systems are examples of Responsibilities: * Kademlia * OverlayCache * PointerDB * StatDB * PieceStore * etc. A Provider is a collection of Responsibilities that share an Identity, such as: * The heavy client * The farmer * The gateway An Identity is a public/private key pair, a node id, etc. Farmers all need different Identities, so captplanet needs to support running multiple concurrent Providers with different Identities. Each Responsibility and Provider should allow for configuration of multiple copies on its own so creating Responsibilities and Providers use a new workflow. To make a Responsibility, one should create a "config" struct, such as: ``` type Config struct { RepairThreshold int `help:"If redundancy falls below this number of pieces, repair is triggered" default:"30"` SuccessThreshold int `help:"If redundancy is above this number then no additional uploads are needed" default:"40"` } ``` To use "config" structs, this changeset introduces another new library called 'cfgstruct', which allows for the configuration of arbitrary structs through flagsets, and thus through cobra and viper. cfgstruct relies on Go's "struct tags" feature to document help information and default values. Config structs can be configured via cfgstruct.Bind for binding the struct to a flagset. Because this configuration system makes setup and configuration easier *in general*, additional commands are provided that allow for easy standup of separate Providers. Please make sure to check out: * cmd/captplanet/farmer/main.go (a new farmer binary) * cmd/captplanet/hc/main.go (a new heavy client binary) * cmd/captplanet/gw/main.go (a new minio gateway binary) Usage: ``` $ go install -v storj.io/storj/cmd/captplanet $ captplanet setup $ captplanet run ``` Configuration is placed by default in `~/.storj/capt/` Other changes: * introduces new config structs for currently existing Responsibilities that conform to the new Responsibility interface. Please see the `pkg/*/config.go` files for examples. * integrates the PointerDB API key with other global configuration via flags, instead of through environment variables through viper like it's been doing. (ultimately this should also change to use the PointerDB config struct but this is an okay shortterm solution). * changes the Overlay cache to use a URL for database configuration instead of separate redis and bolt config settings. * stubs out some peer identity skeleton code (but not the meat). * Fixes the SegmentStore to use the overlay client and pointerdb clients instead of gRPC client code directly * Leaves a very clear spot where we need to tie the object to stream to segment store together. There's sort of a "golden spike" opportunity to connect all the train tracks together at the bottom of pkg/miniogw/config.go, labeled with a bunch of TODOs. Future stuff: * I now prefer this design over the original pkg/process.Service thing I had been pushing before (sorry!) * The experience of trying to have multiple farmers configurable concurrently led me to prefer config structs over global flags (I finally came around) or using viper directly. I think global flags are okay sometimes but in general going forward we should try and get all relevant config into config structs. * If you all like this direction, I think we can go delete my old Service interfaces and a bunch of flags and clean up a bunch of stuff. * If you don't like this direction, it's no sweat at all, and despite how much code there is here I'm not very tied to any of this! Considering a lot of this was written between midnight and 6 am, it might not be any good! * bind tests Add files for testing builds in docker (#161) * Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis pkg/provider: with pkg/provider merged, make a single heavy client binary, gateway binary, and deprecate old services (#165) * pkg/provider: with pkg/provider merged, make a single heavy client binary and deprecate old services * add setup to gw binary too * captplanet: output what addresses everything is listening on * revert peertls/io_util changes * define config flag across all commands * use trimsuffix fix docker makefile (#170) * fix makefile protos: update protobufs with go generate (#169) the import for timestamp and duration should use the path provided by a standard protocol buffer library installation Refactor List in PointerDB (#163) * Refactor List in Pointer DB * Fix pointerdb-client example * Fix issue in Path type related to empty paths * Test for the PointerDB service with some fixes * Fixed debug message in example: trancated --> more * GoDoc comments for unexported methods * TODO comment to check if Put is overwriting * Log warning if protobuf timestamp cannot be converted * TODO comment to make ListPageLimit configurable * Rename 'segment' package to 'segments' to reflect folder name Minio integration with Object store (#156) * initial WIP integration with Object store * List WIP * minio listobject function changes complete * Code review changes and work in progress for the mock objectstore unit testing cases * Warning fix redeclaration of err * Warning fix redeclaration of err * code review comments & unit testing inprogress * fix compilation bug * Fixed code review comments & added GetObject Mock test case * rearraged the mock test file and gateway storj test file in to the proper directory * added the missing file * code clean up * fix lint error on the mock generated code * modified per code review comments * added the PutObject mock test case * added the GetObjectInfo mock test case * added listobject mock test case * fixed package from storj to miniogw * resolved the gateway-storj.go initialization merge conflict update readme (#174) added assertion for unused errors (#152) merging this PR to avoid future issues updating github user to personal account (#171) Test coverage ranger (#168) * Fixed go panic for corner case * Initial test coverage for ranger pkg streamstore: add passthrough implementation (#176) this doesn't implement streamstore, this just allows us to try and get the june demo working again in the meantime StatDB (#144) * add statdb proto and example client * server logic * update readme * remove boltdb from service.go * sqlite3 * add statdb server executable file * create statdb node table if it does not exist already * get UpdateBatch working * update based on jt review * remove some commented lines * fix linting issues * reformat * apiKey -> APIKey * update statdb client apiKey->APIKey Update README.md Update README.md overlay: correct dockerfile db (#179) cmd/hc, cmd/gw, cmd/captplanet: simplify setup/run commands (#178) also allows much more customization of services within captain planet, such as reconfiguring the overlay service to use redis pkg/process: don't require json formatting (#177) Cleanup metadata across layers (#180) * Cleanup metadata across layers * Fix pointer db tests Kademlia Routing Table (#164) * adds comment * runs deps * creates boltdb kademlia routing table * protobuf updates * adds reverselist to mockkeyvaluestore interface * xor wip * xor wip * fixes xor sort * runs go fmt * fixes * goimports again * trying to fix travis tests * fixes mock tests Ranger refactoring (#158) * Fixed go panic for corner case * Cosmetic changes, and small error fixes miniogw: log all errors (#182) * miniogw: log all errors * tests added * doc comment to satisfy linter * fix test failure Jennifer added to CLA list * Temporary fix for storage/redis list method test
2018-08-02 19:36:57 +01:00
func TestConnectionFailed(t *testing.T) {
id := teststorj.NodeIDFromString("AA")
node := &pb.Node{Id: id, Type: pb.NodeType_STORAGE}
rt, cleanup := createRoutingTable(t, id)
2018-09-11 14:57:12 +01:00
defer cleanup()
err := rt.ConnectionFailed(node)
assert.NoError(t, err)
v, err := rt.nodeBucketDB.Get(id.Bytes())
assert.Error(t, err)
assert.Nil(t, v)
Testcoverage kademlia (#154) * Unit test covarege increased for kademlia pkg go style formatting added Removed DHT param from newTestKademlia method, added comments for Bucket methods that informs that these tests will need to be updated unnecessary comment deleted from newTestKademlia Adjust Segment Store to the updated interface (#160) * Adjust Segment Store to the updated interface * Move /pkg/storage/segment to /pkg/storage/segments * Fix overlay client tests * Revert changes in NewOverlayClient return value * Rename `rem` to `seg` * Implement Meta() captplanet (#159) * captplanet I kind of went overboard this weekend. The major goal of this changeset is to provide an environment for local development where all of the various services can be easily run together. Developing on Storj v3 should be as easy as running a setup command and a run command! To do this, this changeset introduces a new tool called captplanet, which combines the powers of the Overlay Cache, the PointerDB, the PieceStore, Kademlia, the Minio Gateway, etc. Running 40 farmers and a heavy client inside the same process forced a rethinking of the "services" that we had. To avoid confusion by reusing prior terms, this changeset introduces two new types: Providers and Responsibilities. I wanted to avoid as many merge conflicts as possible, so I left the existing Services and code for now, but if people like this route we can clean up the duplication. A Responsibility is a collection of gRPC methods and corresponding state. The following systems are examples of Responsibilities: * Kademlia * OverlayCache * PointerDB * StatDB * PieceStore * etc. A Provider is a collection of Responsibilities that share an Identity, such as: * The heavy client * The farmer * The gateway An Identity is a public/private key pair, a node id, etc. Farmers all need different Identities, so captplanet needs to support running multiple concurrent Providers with different Identities. Each Responsibility and Provider should allow for configuration of multiple copies on its own so creating Responsibilities and Providers use a new workflow. To make a Responsibility, one should create a "config" struct, such as: ``` type Config struct { RepairThreshold int `help:"If redundancy falls below this number of pieces, repair is triggered" default:"30"` SuccessThreshold int `help:"If redundancy is above this number then no additional uploads are needed" default:"40"` } ``` To use "config" structs, this changeset introduces another new library called 'cfgstruct', which allows for the configuration of arbitrary structs through flagsets, and thus through cobra and viper. cfgstruct relies on Go's "struct tags" feature to document help information and default values. Config structs can be configured via cfgstruct.Bind for binding the struct to a flagset. Because this configuration system makes setup and configuration easier *in general*, additional commands are provided that allow for easy standup of separate Providers. Please make sure to check out: * cmd/captplanet/farmer/main.go (a new farmer binary) * cmd/captplanet/hc/main.go (a new heavy client binary) * cmd/captplanet/gw/main.go (a new minio gateway binary) Usage: ``` $ go install -v storj.io/storj/cmd/captplanet $ captplanet setup $ captplanet run ``` Configuration is placed by default in `~/.storj/capt/` Other changes: * introduces new config structs for currently existing Responsibilities that conform to the new Responsibility interface. Please see the `pkg/*/config.go` files for examples. * integrates the PointerDB API key with other global configuration via flags, instead of through environment variables through viper like it's been doing. (ultimately this should also change to use the PointerDB config struct but this is an okay shortterm solution). * changes the Overlay cache to use a URL for database configuration instead of separate redis and bolt config settings. * stubs out some peer identity skeleton code (but not the meat). * Fixes the SegmentStore to use the overlay client and pointerdb clients instead of gRPC client code directly * Leaves a very clear spot where we need to tie the object to stream to segment store together. There's sort of a "golden spike" opportunity to connect all the train tracks together at the bottom of pkg/miniogw/config.go, labeled with a bunch of TODOs. Future stuff: * I now prefer this design over the original pkg/process.Service thing I had been pushing before (sorry!) * The experience of trying to have multiple farmers configurable concurrently led me to prefer config structs over global flags (I finally came around) or using viper directly. I think global flags are okay sometimes but in general going forward we should try and get all relevant config into config structs. * If you all like this direction, I think we can go delete my old Service interfaces and a bunch of flags and clean up a bunch of stuff. * If you don't like this direction, it's no sweat at all, and despite how much code there is here I'm not very tied to any of this! Considering a lot of this was written between midnight and 6 am, it might not be any good! * bind tests Add files for testing builds in docker (#161) * Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis pkg/provider: with pkg/provider merged, make a single heavy client binary, gateway binary, and deprecate old services (#165) * pkg/provider: with pkg/provider merged, make a single heavy client binary and deprecate old services * add setup to gw binary too * captplanet: output what addresses everything is listening on * revert peertls/io_util changes * define config flag across all commands * use trimsuffix fix docker makefile (#170) * fix makefile protos: update protobufs with go generate (#169) the import for timestamp and duration should use the path provided by a standard protocol buffer library installation Refactor List in PointerDB (#163) * Refactor List in Pointer DB * Fix pointerdb-client example * Fix issue in Path type related to empty paths * Test for the PointerDB service with some fixes * Fixed debug message in example: trancated --> more * GoDoc comments for unexported methods * TODO comment to check if Put is overwriting * Log warning if protobuf timestamp cannot be converted * TODO comment to make ListPageLimit configurable * Rename 'segment' package to 'segments' to reflect folder name Minio integration with Object store (#156) * initial WIP integration with Object store * List WIP * minio listobject function changes complete * Code review changes and work in progress for the mock objectstore unit testing cases * Warning fix redeclaration of err * Warning fix redeclaration of err * code review comments & unit testing inprogress * fix compilation bug * Fixed code review comments & added GetObject Mock test case * rearraged the mock test file and gateway storj test file in to the proper directory * added the missing file * code clean up * fix lint error on the mock generated code * modified per code review comments * added the PutObject mock test case * added the GetObjectInfo mock test case * added listobject mock test case * fixed package from storj to miniogw * resolved the gateway-storj.go initialization merge conflict update readme (#174) added assertion for unused errors (#152) merging this PR to avoid future issues updating github user to personal account (#171) Test coverage ranger (#168) * Fixed go panic for corner case * Initial test coverage for ranger pkg streamstore: add passthrough implementation (#176) this doesn't implement streamstore, this just allows us to try and get the june demo working again in the meantime StatDB (#144) * add statdb proto and example client * server logic * update readme * remove boltdb from service.go * sqlite3 * add statdb server executable file * create statdb node table if it does not exist already * get UpdateBatch working * update based on jt review * remove some commented lines * fix linting issues * reformat * apiKey -> APIKey * update statdb client apiKey->APIKey Update README.md Update README.md overlay: correct dockerfile db (#179) cmd/hc, cmd/gw, cmd/captplanet: simplify setup/run commands (#178) also allows much more customization of services within captain planet, such as reconfiguring the overlay service to use redis pkg/process: don't require json formatting (#177) Cleanup metadata across layers (#180) * Cleanup metadata across layers * Fix pointer db tests Kademlia Routing Table (#164) * adds comment * runs deps * creates boltdb kademlia routing table * protobuf updates * adds reverselist to mockkeyvaluestore interface * xor wip * xor wip * fixes xor sort * runs go fmt * fixes * goimports again * trying to fix travis tests * fixes mock tests Ranger refactoring (#158) * Fixed go panic for corner case * Cosmetic changes, and small error fixes miniogw: log all errors (#182) * miniogw: log all errors * tests added * doc comment to satisfy linter * fix test failure Jennifer added to CLA list * Temporary fix for storage/redis list method test
2018-08-02 19:36:57 +01:00
}
func TestSetBucketTimestamp(t *testing.T) {
id := teststorj.NodeIDFromString("AA")
2018-09-11 14:57:12 +01:00
rt, cleanup := createRoutingTable(t, id)
defer cleanup()
now := time.Now().UTC()
Node Identity (#193) * peertls: don't log errors for double close understood that this part of the code is undergoing heavy change right now, but just want to make sure this fix gets incorporated somewhere * git cleanup: node-id stuff * cleanup * rename identity_util.go * wip `CertificateAuthority` refactor * refactoring * gitignore update * wip * Merge remote-tracking branch 'storj/doubleclose' into node-id3 * storj/doubleclose: peertls: don't log errors for double close * add peertls tests & gomports * wip: + refactor + style changes + cleanup + [wip] add version to CA and identity configs + [wip] heavy client setup * refactor * wip: + refactor + style changes + add `CAConfig.Load` + add `CAConfig.Save` * wip: + add `LoadOrCreate` and `Create` to CA and Identity configs + add overwrite to CA and identity configs + heavy client setup + refactor + style changes + cleanup * wip * fixing things * fixing things * wip hc setup * hc setup: + refactor + bugfixing * improvements based on reveiw feedback * goimports * improvements: + responding to review feedback + refactor * feedback-based improvements * feedback-based improvements * feedback-based improvements * feedback-based improvements * feedback-based improvements * feedback-based improvements * cleanup * refactoring CA and Identity structs * Merge branch 'master' into node-id3 * move version field to setup config structs for CA and identity * fix typo * responding to revieiw feedback * responding to revieiw feedback * responding to revieiw feedback * responding to revieiw feedback * responding to revieiw feedback * responding to revieiw feedback * Merge branch 'master' into node-id3 * fix gateway setup finally * go imports * fix `FullCertificateAuthority.GenerateIdentity` * cleanup overlay tests * bugfixing * update ca/identity setup * go imports * fix peertls test copy/paste fail * responding to review feedback * setup tweaking * update farmer setup
2018-08-13 09:39:45 +01:00
err := rt.createOrUpdateKBucket(keyToBucketID(id.Bytes()), now)
assert.NoError(t, err)
ti, err := rt.GetBucketTimestamp(id.Bytes())
assert.Equal(t, now, ti)
assert.NoError(t, err)
now = time.Now().UTC()
err = rt.SetBucketTimestamp(id.Bytes(), now)
assert.NoError(t, err)
ti, err = rt.GetBucketTimestamp(id.Bytes())
assert.Equal(t, now, ti)
assert.NoError(t, err)
Testcoverage kademlia (#154) * Unit test covarege increased for kademlia pkg go style formatting added Removed DHT param from newTestKademlia method, added comments for Bucket methods that informs that these tests will need to be updated unnecessary comment deleted from newTestKademlia Adjust Segment Store to the updated interface (#160) * Adjust Segment Store to the updated interface * Move /pkg/storage/segment to /pkg/storage/segments * Fix overlay client tests * Revert changes in NewOverlayClient return value * Rename `rem` to `seg` * Implement Meta() captplanet (#159) * captplanet I kind of went overboard this weekend. The major goal of this changeset is to provide an environment for local development where all of the various services can be easily run together. Developing on Storj v3 should be as easy as running a setup command and a run command! To do this, this changeset introduces a new tool called captplanet, which combines the powers of the Overlay Cache, the PointerDB, the PieceStore, Kademlia, the Minio Gateway, etc. Running 40 farmers and a heavy client inside the same process forced a rethinking of the "services" that we had. To avoid confusion by reusing prior terms, this changeset introduces two new types: Providers and Responsibilities. I wanted to avoid as many merge conflicts as possible, so I left the existing Services and code for now, but if people like this route we can clean up the duplication. A Responsibility is a collection of gRPC methods and corresponding state. The following systems are examples of Responsibilities: * Kademlia * OverlayCache * PointerDB * StatDB * PieceStore * etc. A Provider is a collection of Responsibilities that share an Identity, such as: * The heavy client * The farmer * The gateway An Identity is a public/private key pair, a node id, etc. Farmers all need different Identities, so captplanet needs to support running multiple concurrent Providers with different Identities. Each Responsibility and Provider should allow for configuration of multiple copies on its own so creating Responsibilities and Providers use a new workflow. To make a Responsibility, one should create a "config" struct, such as: ``` type Config struct { RepairThreshold int `help:"If redundancy falls below this number of pieces, repair is triggered" default:"30"` SuccessThreshold int `help:"If redundancy is above this number then no additional uploads are needed" default:"40"` } ``` To use "config" structs, this changeset introduces another new library called 'cfgstruct', which allows for the configuration of arbitrary structs through flagsets, and thus through cobra and viper. cfgstruct relies on Go's "struct tags" feature to document help information and default values. Config structs can be configured via cfgstruct.Bind for binding the struct to a flagset. Because this configuration system makes setup and configuration easier *in general*, additional commands are provided that allow for easy standup of separate Providers. Please make sure to check out: * cmd/captplanet/farmer/main.go (a new farmer binary) * cmd/captplanet/hc/main.go (a new heavy client binary) * cmd/captplanet/gw/main.go (a new minio gateway binary) Usage: ``` $ go install -v storj.io/storj/cmd/captplanet $ captplanet setup $ captplanet run ``` Configuration is placed by default in `~/.storj/capt/` Other changes: * introduces new config structs for currently existing Responsibilities that conform to the new Responsibility interface. Please see the `pkg/*/config.go` files for examples. * integrates the PointerDB API key with other global configuration via flags, instead of through environment variables through viper like it's been doing. (ultimately this should also change to use the PointerDB config struct but this is an okay shortterm solution). * changes the Overlay cache to use a URL for database configuration instead of separate redis and bolt config settings. * stubs out some peer identity skeleton code (but not the meat). * Fixes the SegmentStore to use the overlay client and pointerdb clients instead of gRPC client code directly * Leaves a very clear spot where we need to tie the object to stream to segment store together. There's sort of a "golden spike" opportunity to connect all the train tracks together at the bottom of pkg/miniogw/config.go, labeled with a bunch of TODOs. Future stuff: * I now prefer this design over the original pkg/process.Service thing I had been pushing before (sorry!) * The experience of trying to have multiple farmers configurable concurrently led me to prefer config structs over global flags (I finally came around) or using viper directly. I think global flags are okay sometimes but in general going forward we should try and get all relevant config into config structs. * If you all like this direction, I think we can go delete my old Service interfaces and a bunch of flags and clean up a bunch of stuff. * If you don't like this direction, it's no sweat at all, and despite how much code there is here I'm not very tied to any of this! Considering a lot of this was written between midnight and 6 am, it might not be any good! * bind tests Add files for testing builds in docker (#161) * Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis pkg/provider: with pkg/provider merged, make a single heavy client binary, gateway binary, and deprecate old services (#165) * pkg/provider: with pkg/provider merged, make a single heavy client binary and deprecate old services * add setup to gw binary too * captplanet: output what addresses everything is listening on * revert peertls/io_util changes * define config flag across all commands * use trimsuffix fix docker makefile (#170) * fix makefile protos: update protobufs with go generate (#169) the import for timestamp and duration should use the path provided by a standard protocol buffer library installation Refactor List in PointerDB (#163) * Refactor List in Pointer DB * Fix pointerdb-client example * Fix issue in Path type related to empty paths * Test for the PointerDB service with some fixes * Fixed debug message in example: trancated --> more * GoDoc comments for unexported methods * TODO comment to check if Put is overwriting * Log warning if protobuf timestamp cannot be converted * TODO comment to make ListPageLimit configurable * Rename 'segment' package to 'segments' to reflect folder name Minio integration with Object store (#156) * initial WIP integration with Object store * List WIP * minio listobject function changes complete * Code review changes and work in progress for the mock objectstore unit testing cases * Warning fix redeclaration of err * Warning fix redeclaration of err * code review comments & unit testing inprogress * fix compilation bug * Fixed code review comments & added GetObject Mock test case * rearraged the mock test file and gateway storj test file in to the proper directory * added the missing file * code clean up * fix lint error on the mock generated code * modified per code review comments * added the PutObject mock test case * added the GetObjectInfo mock test case * added listobject mock test case * fixed package from storj to miniogw * resolved the gateway-storj.go initialization merge conflict update readme (#174) added assertion for unused errors (#152) merging this PR to avoid future issues updating github user to personal account (#171) Test coverage ranger (#168) * Fixed go panic for corner case * Initial test coverage for ranger pkg streamstore: add passthrough implementation (#176) this doesn't implement streamstore, this just allows us to try and get the june demo working again in the meantime StatDB (#144) * add statdb proto and example client * server logic * update readme * remove boltdb from service.go * sqlite3 * add statdb server executable file * create statdb node table if it does not exist already * get UpdateBatch working * update based on jt review * remove some commented lines * fix linting issues * reformat * apiKey -> APIKey * update statdb client apiKey->APIKey Update README.md Update README.md overlay: correct dockerfile db (#179) cmd/hc, cmd/gw, cmd/captplanet: simplify setup/run commands (#178) also allows much more customization of services within captain planet, such as reconfiguring the overlay service to use redis pkg/process: don't require json formatting (#177) Cleanup metadata across layers (#180) * Cleanup metadata across layers * Fix pointer db tests Kademlia Routing Table (#164) * adds comment * runs deps * creates boltdb kademlia routing table * protobuf updates * adds reverselist to mockkeyvaluestore interface * xor wip * xor wip * fixes xor sort * runs go fmt * fixes * goimports again * trying to fix travis tests * fixes mock tests Ranger refactoring (#158) * Fixed go panic for corner case * Cosmetic changes, and small error fixes miniogw: log all errors (#182) * miniogw: log all errors * tests added * doc comment to satisfy linter * fix test failure Jennifer added to CLA list * Temporary fix for storage/redis list method test
2018-08-02 19:36:57 +01:00
}
func TestGetBucketTimestamp(t *testing.T) {
id := teststorj.NodeIDFromString("AA")
rt, cleanup := createRoutingTable(t, id)
2018-09-11 14:57:12 +01:00
defer cleanup()
now := time.Now().UTC()
err := rt.createOrUpdateKBucket(keyToBucketID(id.Bytes()), now)
assert.NoError(t, err)
ti, err := rt.GetBucketTimestamp(id.Bytes())
assert.Equal(t, now, ti)
assert.NoError(t, err)
Testcoverage kademlia (#154) * Unit test covarege increased for kademlia pkg go style formatting added Removed DHT param from newTestKademlia method, added comments for Bucket methods that informs that these tests will need to be updated unnecessary comment deleted from newTestKademlia Adjust Segment Store to the updated interface (#160) * Adjust Segment Store to the updated interface * Move /pkg/storage/segment to /pkg/storage/segments * Fix overlay client tests * Revert changes in NewOverlayClient return value * Rename `rem` to `seg` * Implement Meta() captplanet (#159) * captplanet I kind of went overboard this weekend. The major goal of this changeset is to provide an environment for local development where all of the various services can be easily run together. Developing on Storj v3 should be as easy as running a setup command and a run command! To do this, this changeset introduces a new tool called captplanet, which combines the powers of the Overlay Cache, the PointerDB, the PieceStore, Kademlia, the Minio Gateway, etc. Running 40 farmers and a heavy client inside the same process forced a rethinking of the "services" that we had. To avoid confusion by reusing prior terms, this changeset introduces two new types: Providers and Responsibilities. I wanted to avoid as many merge conflicts as possible, so I left the existing Services and code for now, but if people like this route we can clean up the duplication. A Responsibility is a collection of gRPC methods and corresponding state. The following systems are examples of Responsibilities: * Kademlia * OverlayCache * PointerDB * StatDB * PieceStore * etc. A Provider is a collection of Responsibilities that share an Identity, such as: * The heavy client * The farmer * The gateway An Identity is a public/private key pair, a node id, etc. Farmers all need different Identities, so captplanet needs to support running multiple concurrent Providers with different Identities. Each Responsibility and Provider should allow for configuration of multiple copies on its own so creating Responsibilities and Providers use a new workflow. To make a Responsibility, one should create a "config" struct, such as: ``` type Config struct { RepairThreshold int `help:"If redundancy falls below this number of pieces, repair is triggered" default:"30"` SuccessThreshold int `help:"If redundancy is above this number then no additional uploads are needed" default:"40"` } ``` To use "config" structs, this changeset introduces another new library called 'cfgstruct', which allows for the configuration of arbitrary structs through flagsets, and thus through cobra and viper. cfgstruct relies on Go's "struct tags" feature to document help information and default values. Config structs can be configured via cfgstruct.Bind for binding the struct to a flagset. Because this configuration system makes setup and configuration easier *in general*, additional commands are provided that allow for easy standup of separate Providers. Please make sure to check out: * cmd/captplanet/farmer/main.go (a new farmer binary) * cmd/captplanet/hc/main.go (a new heavy client binary) * cmd/captplanet/gw/main.go (a new minio gateway binary) Usage: ``` $ go install -v storj.io/storj/cmd/captplanet $ captplanet setup $ captplanet run ``` Configuration is placed by default in `~/.storj/capt/` Other changes: * introduces new config structs for currently existing Responsibilities that conform to the new Responsibility interface. Please see the `pkg/*/config.go` files for examples. * integrates the PointerDB API key with other global configuration via flags, instead of through environment variables through viper like it's been doing. (ultimately this should also change to use the PointerDB config struct but this is an okay shortterm solution). * changes the Overlay cache to use a URL for database configuration instead of separate redis and bolt config settings. * stubs out some peer identity skeleton code (but not the meat). * Fixes the SegmentStore to use the overlay client and pointerdb clients instead of gRPC client code directly * Leaves a very clear spot where we need to tie the object to stream to segment store together. There's sort of a "golden spike" opportunity to connect all the train tracks together at the bottom of pkg/miniogw/config.go, labeled with a bunch of TODOs. Future stuff: * I now prefer this design over the original pkg/process.Service thing I had been pushing before (sorry!) * The experience of trying to have multiple farmers configurable concurrently led me to prefer config structs over global flags (I finally came around) or using viper directly. I think global flags are okay sometimes but in general going forward we should try and get all relevant config into config structs. * If you all like this direction, I think we can go delete my old Service interfaces and a bunch of flags and clean up a bunch of stuff. * If you don't like this direction, it's no sweat at all, and despite how much code there is here I'm not very tied to any of this! Considering a lot of this was written between midnight and 6 am, it might not be any good! * bind tests Add files for testing builds in docker (#161) * Add files for testing builds in docker * Make tests check for redis running before trying to start redis-server, which may not exist. * Clean redis server before any tests use it. * Add more debugging for travis * Explicitly requiring redis for travis pkg/provider: with pkg/provider merged, make a single heavy client binary, gateway binary, and deprecate old services (#165) * pkg/provider: with pkg/provider merged, make a single heavy client binary and deprecate old services * add setup to gw binary too * captplanet: output what addresses everything is listening on * revert peertls/io_util changes * define config flag across all commands * use trimsuffix fix docker makefile (#170) * fix makefile protos: update protobufs with go generate (#169) the import for timestamp and duration should use the path provided by a standard protocol buffer library installation Refactor List in PointerDB (#163) * Refactor List in Pointer DB * Fix pointerdb-client example * Fix issue in Path type related to empty paths * Test for the PointerDB service with some fixes * Fixed debug message in example: trancated --> more * GoDoc comments for unexported methods * TODO comment to check if Put is overwriting * Log warning if protobuf timestamp cannot be converted * TODO comment to make ListPageLimit configurable * Rename 'segment' package to 'segments' to reflect folder name Minio integration with Object store (#156) * initial WIP integration with Object store * List WIP * minio listobject function changes complete * Code review changes and work in progress for the mock objectstore unit testing cases * Warning fix redeclaration of err * Warning fix redeclaration of err * code review comments & unit testing inprogress * fix compilation bug * Fixed code review comments & added GetObject Mock test case * rearraged the mock test file and gateway storj test file in to the proper directory * added the missing file * code clean up * fix lint error on the mock generated code * modified per code review comments * added the PutObject mock test case * added the GetObjectInfo mock test case * added listobject mock test case * fixed package from storj to miniogw * resolved the gateway-storj.go initialization merge conflict update readme (#174) added assertion for unused errors (#152) merging this PR to avoid future issues updating github user to personal account (#171) Test coverage ranger (#168) * Fixed go panic for corner case * Initial test coverage for ranger pkg streamstore: add passthrough implementation (#176) this doesn't implement streamstore, this just allows us to try and get the june demo working again in the meantime StatDB (#144) * add statdb proto and example client * server logic * update readme * remove boltdb from service.go * sqlite3 * add statdb server executable file * create statdb node table if it does not exist already * get UpdateBatch working * update based on jt review * remove some commented lines * fix linting issues * reformat * apiKey -> APIKey * update statdb client apiKey->APIKey Update README.md Update README.md overlay: correct dockerfile db (#179) cmd/hc, cmd/gw, cmd/captplanet: simplify setup/run commands (#178) also allows much more customization of services within captain planet, such as reconfiguring the overlay service to use redis pkg/process: don't require json formatting (#177) Cleanup metadata across layers (#180) * Cleanup metadata across layers * Fix pointer db tests Kademlia Routing Table (#164) * adds comment * runs deps * creates boltdb kademlia routing table * protobuf updates * adds reverselist to mockkeyvaluestore interface * xor wip * xor wip * fixes xor sort * runs go fmt * fixes * goimports again * trying to fix travis tests * fixes mock tests Ranger refactoring (#158) * Fixed go panic for corner case * Cosmetic changes, and small error fixes miniogw: log all errors (#182) * miniogw: log all errors * tests added * doc comment to satisfy linter * fix test failure Jennifer added to CLA list * Temporary fix for storage/redis list method test
2018-08-02 19:36:57 +01:00
}