From 165b9bdef7580824855aff14e1adc425fdb646ea Mon Sep 17 00:00:00 2001 From: Antanas Masevicius Date: Wed, 21 Feb 2018 14:47:24 +0200 Subject: [PATCH 1/8] add -discovery-address and -broker-address command line options to override compiled-in options --- bin/client_run | 9 ++++++++- bin/helpers/functions.sh | 4 +++- bin/helpers/load_run_environment.sh | 8 ++++++++ bin/server_run | 9 ++++++++- cmd/commands/client/command_client.go | 2 +- cmd/commands/client/options.go | 19 +++++++++++++++++++ cmd/commands/server/factory.go | 4 ++-- cmd/commands/server/options.go | 19 +++++++++++++++++++ communication/nats/discovery/address.go | 6 ++---- communication/nats/discovery/address_test.go | 5 +++-- server/mysterium_api.go | 16 +++++++++------- server/request.go | 18 ++++++++---------- server/request_test.go | 9 +++++---- server/response_test.go | 4 ++-- 14 files changed, 97 insertions(+), 35 deletions(-) create mode 100644 bin/helpers/load_run_environment.sh diff --git a/bin/client_run b/bin/client_run index b0f80011a..47f4548f2 100755 --- a/bin/client_run +++ b/bin/client_run @@ -1,3 +1,10 @@ #!/bin/bash -sudo ./build/client/mysterium_client --config-dir=bin/client_package/config --runtime-dir=build/client $@ +source bin/helpers/load_run_environment.sh + +sudo ./build/client/mysterium_client \ + --config-dir=bin/client_package/config \ + --runtime-dir=build/client \ + $DISCOVERY \ + $BROKER \ + $@ diff --git a/bin/helpers/functions.sh b/bin/helpers/functions.sh index 729624548..819097e45 100644 --- a/bin/helpers/functions.sh +++ b/bin/helpers/functions.sh @@ -4,6 +4,8 @@ function get_linker_ldflags { echo " -X 'github.com/mysterium/node/server.mysteriumApiUrl=${MYSTERIUM_API_URL}' - -X 'github.com/mysterium/node/communication/nats/discovery.natsServerIP=${NATS_SERVER_IP}' + -X 'github.com/mysterium/node/server.natsServerIP=${NATS_SERVER_IP}' + -X 'github.com/mysterium/node/client.mysteriumApiUrl=${MYSTERIUM_API_URL}' + -X 'github.com/mysterium/node/client.natsServerIP=${NATS_SERVER_IP}' " } diff --git a/bin/helpers/load_run_environment.sh b/bin/helpers/load_run_environment.sh new file mode 100644 index 000000000..e1de63348 --- /dev/null +++ b/bin/helpers/load_run_environment.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [ -f .env ]; then + source .env + + [ -n "$MYSTERIUM_API_URL" ] && DISCOVERY="-discovery-address=$MYSTERIUM_API_URL" + [ -n "$NATS_SERVER_IP" ] && BROKER="-broker-address=$NATS_SERVER_IP" +fi diff --git a/bin/server_run b/bin/server_run index c148ac00e..ea3edf64d 100755 --- a/bin/server_run +++ b/bin/server_run @@ -1,3 +1,10 @@ #!/bin/bash -sudo ./build/server/mysterium_server --config-dir=bin/server_package/config --runtime-dir=build/server $@ \ No newline at end of file +source bin/helpers/load_run_environment.sh + +sudo ./build/server/mysterium_server \ + --config-dir=bin/server_package/config \ + --runtime-dir=build/server \ + $DISCOVERY \ + $BROKER \ + $@ diff --git a/cmd/commands/client/command_client.go b/cmd/commands/client/command_client.go index 59a8bdeaa..f49d61da3 100644 --- a/cmd/commands/client/command_client.go +++ b/cmd/commands/client/command_client.go @@ -23,7 +23,7 @@ import ( func NewCommand(options CommandOptions) *Command { return NewCommandWith( options, - server.NewClient(), + server.NewClient(options.DiscoveryAPIAddress), ) } diff --git a/cmd/commands/client/options.go b/cmd/commands/client/options.go index baad65e02..ea3314012 100644 --- a/cmd/commands/client/options.go +++ b/cmd/commands/client/options.go @@ -16,8 +16,14 @@ type CommandOptions struct { TequilapiPort int CLI bool + + DiscoveryAPIAddress string + BrokerAddress string } +var mysteriumApiUrl string +var natsServerIP string + // ParseArguments parses CLI flags and adds to CommandOptions structure func ParseArguments(args []string) (options CommandOptions, err error) { flags := flag.NewFlagSet(args[0], flag.ContinueOnError) @@ -60,6 +66,19 @@ func ParseArguments(args []string) (options CommandOptions, err error) { "Run an interactive CLI based Mysterium UI", ) + flags.StringVar( + &options.DiscoveryAPIAddress, + "discovery-address", + mysteriumApiUrl, + "Address (URL form) of discovery service", + ) + flags.StringVar( + &options.BrokerAddress, + "broker-address", + natsServerIP, + "Address (IP or domain name) of message broker", + ) + err = flags.Parse(args[1:]) if err != nil { return diff --git a/cmd/commands/server/factory.go b/cmd/commands/server/factory.go index 1ee12d6b8..8a4485226 100644 --- a/cmd/commands/server/factory.go +++ b/cmd/commands/server/factory.go @@ -24,7 +24,7 @@ import ( func NewCommand(options CommandOptions) *Command { return NewCommandWith( options, - server.NewClient(), + server.NewClient(options.DiscoveryAPIAddress), ip.NewResolver(), nat.NewService(), ) @@ -71,7 +71,7 @@ func NewCommandWith( natService: natService, dialogWaiterFactory: func(myID identity.Identity) communication.DialogWaiter { return nats_dialog.NewDialogWaiter( - nats_discovery.NewAddressGenerate(myID), + nats_discovery.NewAddressGenerate(options.BrokerAddress, myID), identity.NewSigner(keystoreInstance, myID), ) }, diff --git a/cmd/commands/server/options.go b/cmd/commands/server/options.go index 23a724f9e..64beb1c06 100644 --- a/cmd/commands/server/options.go +++ b/cmd/commands/server/options.go @@ -17,10 +17,16 @@ type CommandOptions struct { LocationCountry string LocationDatabase string + + DiscoveryAPIAddress string + BrokerAddress string } const defaultLocationDatabase = "GeoLite2-Country.mmdb" +var mysteriumApiUrl string +var natsServerIP string + // ParseArguments parses CLI flags and adds to CommandOptions structure func ParseArguments(args []string) (options CommandOptions, err error) { flags := flag.NewFlagSet(args[0], flag.ContinueOnError) @@ -69,6 +75,19 @@ func ParseArguments(args []string) (options CommandOptions, err error) { "Service location country. If not given country is autodetected", ) + flags.StringVar( + &options.DiscoveryAPIAddress, + "discovery-address", + mysteriumApiUrl, + "Address (URL form) of discovery service", + ) + flags.StringVar( + &options.BrokerAddress, + "broker-address", + natsServerIP, + "Address (IP or domain name) of message broker", + ) + err = flags.Parse(args[1:]) if err != nil { return diff --git a/communication/nats/discovery/address.go b/communication/nats/discovery/address.go index d26c37340..c6f4b2c31 100644 --- a/communication/nats/discovery/address.go +++ b/communication/nats/discovery/address.go @@ -8,8 +8,6 @@ import ( nats_lib "github.com/nats-io/go-nats" ) -var natsServerIP string - // NewAddress creates NATS address to known host or cluster of hosts func NewAddress(topic string, addresses ...string) *AddressNATS { return &AddressNATS{ @@ -19,8 +17,8 @@ func NewAddress(topic string, addresses ...string) *AddressNATS { } // NewAddressGenerate generates NATS address for current node -func NewAddressGenerate(myID identity.Identity) *AddressNATS { - address := "nats://" + natsServerIP + ":4222" +func NewAddressGenerate(brokerIP string, myID identity.Identity) *AddressNATS { + address := "nats://" + brokerIP + ":4222" return NewAddress(myID.Address, address) } diff --git a/communication/nats/discovery/address_test.go b/communication/nats/discovery/address_test.go index dda674458..20e17b174 100644 --- a/communication/nats/discovery/address_test.go +++ b/communication/nats/discovery/address_test.go @@ -23,12 +23,13 @@ func TestNewAddress(t *testing.T) { func TestNewAddressGenerate(t *testing.T) { myID := identity.FromAddress("provider1") - address := NewAddressGenerate(myID) + brokerIP := "127.0.0.1" + address := NewAddressGenerate(brokerIP, myID) assert.Equal( t, &AddressNATS{ - servers: []string{"nats://" + natsServerIP + ":4222"}, + servers: []string{"nats://" + brokerIP + ":4222"}, topic: "provider1", }, address, diff --git a/server/mysterium_api.go b/server/mysterium_api.go index 26f21633b..049abc7ae 100644 --- a/server/mysterium_api.go +++ b/server/mysterium_api.go @@ -21,20 +21,22 @@ type HttpTransport interface { } type mysteriumAPI struct { - http HttpTransport + http HttpTransport + discoveryAPIAddress string } // NewClient creates Mysterium centralized api instance with real communication -func NewClient() Client { +func NewClient(discoveryAPIAddress string) Client { return &mysteriumAPI{ &http.Client{ Transport: &http.Transport{}, }, + discoveryAPIAddress, } } func (mApi *mysteriumAPI) RegisterIdentity(id identity.Identity, signer identity.Signer) error { - req, err := newSignedPostRequest("identities", dto.CreateIdentityRequest{ + req, err := newSignedPostRequest(mApi.discoveryAPIAddress, "identities", dto.CreateIdentityRequest{ Identity: id.Address, }, signer) if err != nil { @@ -49,7 +51,7 @@ func (mApi *mysteriumAPI) RegisterIdentity(id identity.Identity, signer identity } func (mApi *mysteriumAPI) RegisterProposal(proposal dto_discovery.ServiceProposal, signer identity.Signer) error { - req, err := newSignedPostRequest("register_proposal", dto.NodeRegisterRequest{ + req, err := newSignedPostRequest(mApi.discoveryAPIAddress, "register_proposal", dto.NodeRegisterRequest{ ServiceProposal: proposal, }, signer) if err != nil { @@ -65,7 +67,7 @@ func (mApi *mysteriumAPI) RegisterProposal(proposal dto_discovery.ServiceProposa } func (mApi *mysteriumAPI) PingProposal(proposal dto_discovery.ServiceProposal, signer identity.Signer) error { - req, err := newSignedPostRequest("ping_proposal", dto.NodeStatsRequest{ + req, err := newSignedPostRequest(mApi.discoveryAPIAddress, "ping_proposal", dto.NodeStatsRequest{ NodeKey: proposal.ProviderID, }, signer) if err != nil { @@ -85,7 +87,7 @@ func (mApi *mysteriumAPI) FindProposals(providerID string) ([]dto_discovery.Serv values.Set("node_key", providerID) } - req, err := newGetRequest("proposals", values) + req, err := newGetRequest(mApi.discoveryAPIAddress, "proposals", values) if err != nil { return nil, err } @@ -103,7 +105,7 @@ func (mApi *mysteriumAPI) FindProposals(providerID string) ([]dto_discovery.Serv func (mApi *mysteriumAPI) SendSessionStats(sessionId string, sessionStats dto.SessionStats, signer identity.Signer) error { path := fmt.Sprintf("sessions/%s/stats", sessionId) - req, err := newSignedPostRequest(path, sessionStats, signer) + req, err := newSignedPostRequest(mApi.discoveryAPIAddress, path, sessionStats, signer) if err != nil { return err } diff --git a/server/request.go b/server/request.go index 8cb3d5cf9..646be58d5 100644 --- a/server/request.go +++ b/server/request.go @@ -15,22 +15,20 @@ const ( authenticationSchemaName = "Signature" ) -var mysteriumApiUrl string - -func newGetRequest(path string, params url.Values) (*http.Request, error) { +func newGetRequest(apiURI, path string, params url.Values) (*http.Request, error) { pathWithQuery := fmt.Sprintf("%v?%v", path, params.Encode()) - return newRequest(http.MethodGet, pathWithQuery, nil) + return newRequest(http.MethodGet, apiURI, pathWithQuery, nil) } -func newPostRequest(path string, requestBody interface{}) (*http.Request, error) { +func newPostRequest(apiURI, path string, requestBody interface{}) (*http.Request, error) { bodyBytes, err := encodeToJSON(requestBody) if err != nil { return nil, err } - return newRequest(http.MethodPost, path, bodyBytes) + return newRequest(http.MethodPost, apiURI, path, bodyBytes) } -func newSignedPostRequest(path string, requestBody interface{}, signer identity.Signer) (*http.Request, error) { +func newSignedPostRequest(apiURI, path string, requestBody interface{}, signer identity.Signer) (*http.Request, error) { bodyBytes, err := encodeToJSON(requestBody) if err != nil { return nil, err @@ -41,7 +39,7 @@ func newSignedPostRequest(path string, requestBody interface{}, signer identity. return nil, err } - req, err := newRequest(http.MethodPost, path, bodyBytes) + req, err := newRequest(http.MethodPost, apiURI, path, bodyBytes) if err != nil { return nil, err } @@ -55,9 +53,9 @@ func encodeToJSON(value interface{}) ([]byte, error) { return json.Marshal(value) } -func newRequest(method, path string, body []byte) (*http.Request, error) { +func newRequest(method, apiURI, path string, body []byte) (*http.Request, error) { - fullUrl := fmt.Sprintf("%v/%v", mysteriumApiUrl, path) + fullUrl := fmt.Sprintf("%v/%v", apiURI, path) req, err := http.NewRequest(method, fullUrl, bytes.NewBuffer(body)) if err != nil { return nil, err diff --git a/server/request_test.go b/server/request_test.go index d957d35ae..7a1cc4c4b 100644 --- a/server/request_test.go +++ b/server/request_test.go @@ -17,6 +17,8 @@ type mockedSigner struct { signatureToReturn identity.Signature } +var testMysteriumApiUrl = "http://testUrl" + func (signer *mockedSigner) Sign(message []byte) (identity.Signature, error) { return signer.signatureToReturn, nil } @@ -25,19 +27,18 @@ func TestSignatureIsInsertedForSignedPost(t *testing.T) { signer := mockedSigner{identity.SignatureBase64("deadbeef")} - req, err := newSignedPostRequest("/post-path", testPayload{"abc"}, &signer) + req, err := newSignedPostRequest(testMysteriumApiUrl, "/post-path", testPayload{"abc"}, &signer) assert.NoError(t, err) assert.Equal(t, req.Header.Get("Authorization"), "Signature deadbeef") } func TestDoGetContactsPassedValuesForUrl(t *testing.T) { - mysteriumApiUrl = "http://testUrl" params := url.Values{} params["param1"] = []string{"value1"} params["param2"] = []string{"value2"} - req, err := newGetRequest("get-path", params) + req, err := newGetRequest(testMysteriumApiUrl, "get-path", params) assert.NoError(t, err) assert.Equal(t, "http://testUrl/get-path?param1=value1¶m2=value2", req.URL.String()) @@ -46,7 +47,7 @@ func TestDoGetContactsPassedValuesForUrl(t *testing.T) { func TestPayloadIsSerializedSuccessfullyForPostMethod(t *testing.T) { - req, err := newPostRequest("post-path", testPayload{"abc"}) + req, err := newPostRequest(testMysteriumApiUrl, "post-path", testPayload{"abc"}) assert.NoError(t, err) diff --git a/server/response_test.go b/server/response_test.go index 329cb2024..06e5376b4 100644 --- a/server/response_test.go +++ b/server/response_test.go @@ -9,7 +9,7 @@ import ( ) func TestHttpErrorIsReportedAsErrorReturnValue(t *testing.T) { - req, err := newGetRequest("path", nil) + req, err := newGetRequest(testMysteriumApiUrl, "path", nil) assert.NoError(t, err) response := &http.Response{ @@ -26,7 +26,7 @@ type testResponse struct { func TestHttpResponseBodyIsParsedCorrectly(t *testing.T) { - req, err := newGetRequest("path", nil) + req, err := newGetRequest(testMysteriumApiUrl, "path", nil) assert.NoError(t, err) response := &http.Response{ From 3df88d755d1acfd89fd0f171e062f58690aea361 Mon Sep 17 00:00:00 2001 From: Antanas Masevicius Date: Wed, 21 Feb 2018 16:37:46 +0200 Subject: [PATCH 2/8] client does not need hardcoded broker IP - removed --- bin/client_run | 1 - bin/helpers/functions.sh | 1 - cmd/commands/client/options.go | 7 ------- 3 files changed, 9 deletions(-) diff --git a/bin/client_run b/bin/client_run index 47f4548f2..eff20437d 100755 --- a/bin/client_run +++ b/bin/client_run @@ -6,5 +6,4 @@ sudo ./build/client/mysterium_client \ --config-dir=bin/client_package/config \ --runtime-dir=build/client \ $DISCOVERY \ - $BROKER \ $@ diff --git a/bin/helpers/functions.sh b/bin/helpers/functions.sh index 819097e45..4ded50d56 100644 --- a/bin/helpers/functions.sh +++ b/bin/helpers/functions.sh @@ -6,6 +6,5 @@ function get_linker_ldflags { -X 'github.com/mysterium/node/server.mysteriumApiUrl=${MYSTERIUM_API_URL}' -X 'github.com/mysterium/node/server.natsServerIP=${NATS_SERVER_IP}' -X 'github.com/mysterium/node/client.mysteriumApiUrl=${MYSTERIUM_API_URL}' - -X 'github.com/mysterium/node/client.natsServerIP=${NATS_SERVER_IP}' " } diff --git a/cmd/commands/client/options.go b/cmd/commands/client/options.go index ea3314012..eda66a55e 100644 --- a/cmd/commands/client/options.go +++ b/cmd/commands/client/options.go @@ -22,7 +22,6 @@ type CommandOptions struct { } var mysteriumApiUrl string -var natsServerIP string // ParseArguments parses CLI flags and adds to CommandOptions structure func ParseArguments(args []string) (options CommandOptions, err error) { @@ -72,12 +71,6 @@ func ParseArguments(args []string) (options CommandOptions, err error) { mysteriumApiUrl, "Address (URL form) of discovery service", ) - flags.StringVar( - &options.BrokerAddress, - "broker-address", - natsServerIP, - "Address (IP or domain name) of message broker", - ) err = flags.Parse(args[1:]) if err != nil { From 58ae6d50d91aac029409cae38b6018e8871b34c9 Mon Sep 17 00:00:00 2001 From: Antanas Masevicius Date: Thu, 22 Feb 2018 17:26:06 +0200 Subject: [PATCH 3/8] fixed packges; client reuses the same external MysteriumApiUrl --- bin/helpers/functions.sh | 5 ++--- cmd/commands/client/options.go | 5 ++--- cmd/commands/server/options.go | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/bin/helpers/functions.sh b/bin/helpers/functions.sh index 4ded50d56..817bf141c 100644 --- a/bin/helpers/functions.sh +++ b/bin/helpers/functions.sh @@ -3,8 +3,7 @@ # Map environment variables to flags for Golang linker's -ldflags usage function get_linker_ldflags { echo " - -X 'github.com/mysterium/node/server.mysteriumApiUrl=${MYSTERIUM_API_URL}' - -X 'github.com/mysterium/node/server.natsServerIP=${NATS_SERVER_IP}' - -X 'github.com/mysterium/node/client.mysteriumApiUrl=${MYSTERIUM_API_URL}' + -X 'github.com/mysterium/node/cmd/commands/server.MysteriumApiUrl=${MYSTERIUM_API_URL}' + -X 'github.com/mysterium/node/cmd/commands/server.natsServerIP=${NATS_SERVER_IP}' " } diff --git a/cmd/commands/client/options.go b/cmd/commands/client/options.go index eda66a55e..dd5708703 100644 --- a/cmd/commands/client/options.go +++ b/cmd/commands/client/options.go @@ -3,6 +3,7 @@ package client import ( "flag" "github.com/mysterium/node/cmd" + "github.com/mysterium/node/cmd/commands/server" "path/filepath" ) @@ -21,8 +22,6 @@ type CommandOptions struct { BrokerAddress string } -var mysteriumApiUrl string - // ParseArguments parses CLI flags and adds to CommandOptions structure func ParseArguments(args []string) (options CommandOptions, err error) { flags := flag.NewFlagSet(args[0], flag.ContinueOnError) @@ -68,7 +67,7 @@ func ParseArguments(args []string) (options CommandOptions, err error) { flags.StringVar( &options.DiscoveryAPIAddress, "discovery-address", - mysteriumApiUrl, + server.MysteriumApiUrl, "Address (URL form) of discovery service", ) diff --git a/cmd/commands/server/options.go b/cmd/commands/server/options.go index 64beb1c06..705fa314c 100644 --- a/cmd/commands/server/options.go +++ b/cmd/commands/server/options.go @@ -24,7 +24,7 @@ type CommandOptions struct { const defaultLocationDatabase = "GeoLite2-Country.mmdb" -var mysteriumApiUrl string +var MysteriumApiUrl string var natsServerIP string // ParseArguments parses CLI flags and adds to CommandOptions structure @@ -78,7 +78,7 @@ func ParseArguments(args []string) (options CommandOptions, err error) { flags.StringVar( &options.DiscoveryAPIAddress, "discovery-address", - mysteriumApiUrl, + MysteriumApiUrl, "Address (URL form) of discovery service", ) flags.StringVar( From e6fbb7dc3bc784e4aa8ef2d9e46dcb375fba48cb Mon Sep 17 00:00:00 2001 From: Antanas Masevicius Date: Mon, 26 Feb 2018 11:02:23 +0200 Subject: [PATCH 4/8] aMoved request functions to seaprate package. Could be reused in the future. --- bin/helpers/functions.sh | 2 +- cmd/commands/client/options.go | 3 +-- cmd/commands/server/options.go | 3 +-- cmd/config.go | 4 ++++ openvpn/primitives/generate_test.go | 2 +- {server => requestor}/request.go | 8 ++++---- {server => requestor}/request_test.go | 10 +++++----- server/mysterium_api.go | 11 ++++++----- server/response_test.go | 7 +++++-- 9 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 cmd/config.go rename {server => requestor}/request.go (87%) rename {server => requestor}/request_test.go (78%) diff --git a/bin/helpers/functions.sh b/bin/helpers/functions.sh index 817bf141c..18fb04ae2 100644 --- a/bin/helpers/functions.sh +++ b/bin/helpers/functions.sh @@ -3,7 +3,7 @@ # Map environment variables to flags for Golang linker's -ldflags usage function get_linker_ldflags { echo " - -X 'github.com/mysterium/node/cmd/commands/server.MysteriumApiUrl=${MYSTERIUM_API_URL}' + -X 'github.com/mysterium/node/cmd.MysteriumAPIURL=${MYSTERIUM_API_URL}' -X 'github.com/mysterium/node/cmd/commands/server.natsServerIP=${NATS_SERVER_IP}' " } diff --git a/cmd/commands/client/options.go b/cmd/commands/client/options.go index dd5708703..05ecef766 100644 --- a/cmd/commands/client/options.go +++ b/cmd/commands/client/options.go @@ -3,7 +3,6 @@ package client import ( "flag" "github.com/mysterium/node/cmd" - "github.com/mysterium/node/cmd/commands/server" "path/filepath" ) @@ -67,7 +66,7 @@ func ParseArguments(args []string) (options CommandOptions, err error) { flags.StringVar( &options.DiscoveryAPIAddress, "discovery-address", - server.MysteriumApiUrl, + cmd.MysteriumAPIURL, "Address (URL form) of discovery service", ) diff --git a/cmd/commands/server/options.go b/cmd/commands/server/options.go index 705fa314c..0dd2a68c7 100644 --- a/cmd/commands/server/options.go +++ b/cmd/commands/server/options.go @@ -24,7 +24,6 @@ type CommandOptions struct { const defaultLocationDatabase = "GeoLite2-Country.mmdb" -var MysteriumApiUrl string var natsServerIP string // ParseArguments parses CLI flags and adds to CommandOptions structure @@ -78,7 +77,7 @@ func ParseArguments(args []string) (options CommandOptions, err error) { flags.StringVar( &options.DiscoveryAPIAddress, "discovery-address", - MysteriumApiUrl, + cmd.MysteriumAPIURL, "Address (URL form) of discovery service", ) flags.StringVar( diff --git a/cmd/config.go b/cmd/config.go new file mode 100644 index 000000000..eb0f4d7fe --- /dev/null +++ b/cmd/config.go @@ -0,0 +1,4 @@ +package cmd + +// MysteriumAPIURL stores MYSTERIUM_API_URL env variable that is complied in +var MysteriumAPIURL string diff --git a/openvpn/primitives/generate_test.go b/openvpn/primitives/generate_test.go index 12ade38a3..60890d29d 100644 --- a/openvpn/primitives/generate_test.go +++ b/openvpn/primitives/generate_test.go @@ -7,7 +7,7 @@ import ( "testing" ) -const fakeRunDir = "testdataoutput" +const fakeRunDir = "" func TestGenerateRequiredFiles(t *testing.T) { sp, _ := GenerateOpenVPNSecPrimitives(fakeRunDir, fakeServiceLocation, fakeProviderID) diff --git a/server/request.go b/requestor/request.go similarity index 87% rename from server/request.go rename to requestor/request.go index 646be58d5..ed079b236 100644 --- a/server/request.go +++ b/requestor/request.go @@ -1,4 +1,4 @@ -package server +package requestor import ( "bytes" @@ -15,12 +15,12 @@ const ( authenticationSchemaName = "Signature" ) -func newGetRequest(apiURI, path string, params url.Values) (*http.Request, error) { +func NewGetRequest(apiURI, path string, params url.Values) (*http.Request, error) { pathWithQuery := fmt.Sprintf("%v?%v", path, params.Encode()) return newRequest(http.MethodGet, apiURI, pathWithQuery, nil) } -func newPostRequest(apiURI, path string, requestBody interface{}) (*http.Request, error) { +func NewPostRequest(apiURI, path string, requestBody interface{}) (*http.Request, error) { bodyBytes, err := encodeToJSON(requestBody) if err != nil { return nil, err @@ -28,7 +28,7 @@ func newPostRequest(apiURI, path string, requestBody interface{}) (*http.Request return newRequest(http.MethodPost, apiURI, path, bodyBytes) } -func newSignedPostRequest(apiURI, path string, requestBody interface{}, signer identity.Signer) (*http.Request, error) { +func NewSignedPostRequest(apiURI, path string, requestBody interface{}, signer identity.Signer) (*http.Request, error) { bodyBytes, err := encodeToJSON(requestBody) if err != nil { return nil, err diff --git a/server/request_test.go b/requestor/request_test.go similarity index 78% rename from server/request_test.go rename to requestor/request_test.go index 7a1cc4c4b..9ef1bd523 100644 --- a/server/request_test.go +++ b/requestor/request_test.go @@ -1,4 +1,4 @@ -package server +package requestor import ( "bytes" @@ -17,7 +17,7 @@ type mockedSigner struct { signatureToReturn identity.Signature } -var testMysteriumApiUrl = "http://testUrl" +var testRequestApiUrl = "http://testUrl" func (signer *mockedSigner) Sign(message []byte) (identity.Signature, error) { return signer.signatureToReturn, nil @@ -27,7 +27,7 @@ func TestSignatureIsInsertedForSignedPost(t *testing.T) { signer := mockedSigner{identity.SignatureBase64("deadbeef")} - req, err := newSignedPostRequest(testMysteriumApiUrl, "/post-path", testPayload{"abc"}, &signer) + req, err := NewSignedPostRequest(testRequestApiUrl, "/post-path", testPayload{"abc"}, &signer) assert.NoError(t, err) assert.Equal(t, req.Header.Get("Authorization"), "Signature deadbeef") } @@ -38,7 +38,7 @@ func TestDoGetContactsPassedValuesForUrl(t *testing.T) { params["param1"] = []string{"value1"} params["param2"] = []string{"value2"} - req, err := newGetRequest(testMysteriumApiUrl, "get-path", params) + req, err := NewGetRequest(testRequestApiUrl, "get-path", params) assert.NoError(t, err) assert.Equal(t, "http://testUrl/get-path?param1=value1¶m2=value2", req.URL.String()) @@ -47,7 +47,7 @@ func TestDoGetContactsPassedValuesForUrl(t *testing.T) { func TestPayloadIsSerializedSuccessfullyForPostMethod(t *testing.T) { - req, err := newPostRequest(testMysteriumApiUrl, "post-path", testPayload{"abc"}) + req, err := NewPostRequest(testRequestApiUrl, "post-path", testPayload{"abc"}) assert.NoError(t, err) diff --git a/server/mysterium_api.go b/server/mysterium_api.go index 049abc7ae..31607d877 100644 --- a/server/mysterium_api.go +++ b/server/mysterium_api.go @@ -6,6 +6,7 @@ import ( log "github.com/cihub/seelog" "github.com/mysterium/node/identity" + "github.com/mysterium/node/requestor" "github.com/mysterium/node/server/dto" dto_discovery "github.com/mysterium/node/service_discovery/dto" "net/url" @@ -36,7 +37,7 @@ func NewClient(discoveryAPIAddress string) Client { } func (mApi *mysteriumAPI) RegisterIdentity(id identity.Identity, signer identity.Signer) error { - req, err := newSignedPostRequest(mApi.discoveryAPIAddress, "identities", dto.CreateIdentityRequest{ + req, err := requestor.NewSignedPostRequest(mApi.discoveryAPIAddress, "identities", dto.CreateIdentityRequest{ Identity: id.Address, }, signer) if err != nil { @@ -51,7 +52,7 @@ func (mApi *mysteriumAPI) RegisterIdentity(id identity.Identity, signer identity } func (mApi *mysteriumAPI) RegisterProposal(proposal dto_discovery.ServiceProposal, signer identity.Signer) error { - req, err := newSignedPostRequest(mApi.discoveryAPIAddress, "register_proposal", dto.NodeRegisterRequest{ + req, err := requestor.NewSignedPostRequest(mApi.discoveryAPIAddress, "register_proposal", dto.NodeRegisterRequest{ ServiceProposal: proposal, }, signer) if err != nil { @@ -67,7 +68,7 @@ func (mApi *mysteriumAPI) RegisterProposal(proposal dto_discovery.ServiceProposa } func (mApi *mysteriumAPI) PingProposal(proposal dto_discovery.ServiceProposal, signer identity.Signer) error { - req, err := newSignedPostRequest(mApi.discoveryAPIAddress, "ping_proposal", dto.NodeStatsRequest{ + req, err := requestor.NewSignedPostRequest(mApi.discoveryAPIAddress, "ping_proposal", dto.NodeStatsRequest{ NodeKey: proposal.ProviderID, }, signer) if err != nil { @@ -87,7 +88,7 @@ func (mApi *mysteriumAPI) FindProposals(providerID string) ([]dto_discovery.Serv values.Set("node_key", providerID) } - req, err := newGetRequest(mApi.discoveryAPIAddress, "proposals", values) + req, err := requestor.NewGetRequest(mApi.discoveryAPIAddress, "proposals", values) if err != nil { return nil, err } @@ -105,7 +106,7 @@ func (mApi *mysteriumAPI) FindProposals(providerID string) ([]dto_discovery.Serv func (mApi *mysteriumAPI) SendSessionStats(sessionId string, sessionStats dto.SessionStats, signer identity.Signer) error { path := fmt.Sprintf("sessions/%s/stats", sessionId) - req, err := newSignedPostRequest(mApi.discoveryAPIAddress, path, sessionStats, signer) + req, err := requestor.NewSignedPostRequest(mApi.discoveryAPIAddress, path, sessionStats, signer) if err != nil { return err } diff --git a/server/response_test.go b/server/response_test.go index 06e5376b4..75a52d7be 100644 --- a/server/response_test.go +++ b/server/response_test.go @@ -2,14 +2,17 @@ package server import ( "bytes" + "github.com/mysterium/node/requestor" "github.com/stretchr/testify/assert" "io/ioutil" "net/http" "testing" ) +var testRequestApiUrl = "http://testUrl" + func TestHttpErrorIsReportedAsErrorReturnValue(t *testing.T) { - req, err := newGetRequest(testMysteriumApiUrl, "path", nil) + req, err := requestor.NewGetRequest(testRequestApiUrl, "path", nil) assert.NoError(t, err) response := &http.Response{ @@ -26,7 +29,7 @@ type testResponse struct { func TestHttpResponseBodyIsParsedCorrectly(t *testing.T) { - req, err := newGetRequest(testMysteriumApiUrl, "path", nil) + req, err := requestor.NewGetRequest(testRequestApiUrl, "path", nil) assert.NoError(t, err) response := &http.Response{ From f75ce0a157936148605ec5708d70d7cb4d506877 Mon Sep 17 00:00:00 2001 From: Antanas Masevicius Date: Mon, 26 Feb 2018 14:06:30 +0200 Subject: [PATCH 5/8] env arguments with -- changed --- bin/helpers/load_run_environment.sh | 4 ++-- requestor/request.go | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/helpers/load_run_environment.sh b/bin/helpers/load_run_environment.sh index e1de63348..c7870e7f8 100644 --- a/bin/helpers/load_run_environment.sh +++ b/bin/helpers/load_run_environment.sh @@ -3,6 +3,6 @@ if [ -f .env ]; then source .env - [ -n "$MYSTERIUM_API_URL" ] && DISCOVERY="-discovery-address=$MYSTERIUM_API_URL" - [ -n "$NATS_SERVER_IP" ] && BROKER="-broker-address=$NATS_SERVER_IP" + [ -n "$MYSTERIUM_API_URL" ] && DISCOVERY="--discovery-address=$MYSTERIUM_API_URL" + [ -n "$NATS_SERVER_IP" ] && BROKER="--broker-address=$NATS_SERVER_IP" fi diff --git a/requestor/request.go b/requestor/request.go index ed079b236..cd58a8f41 100644 --- a/requestor/request.go +++ b/requestor/request.go @@ -15,11 +15,13 @@ const ( authenticationSchemaName = "Signature" ) +// NewGetRequest generates http Get request func NewGetRequest(apiURI, path string, params url.Values) (*http.Request, error) { pathWithQuery := fmt.Sprintf("%v?%v", path, params.Encode()) return newRequest(http.MethodGet, apiURI, pathWithQuery, nil) } +// NewPostRequest generates http Post request func NewPostRequest(apiURI, path string, requestBody interface{}) (*http.Request, error) { bodyBytes, err := encodeToJSON(requestBody) if err != nil { @@ -28,6 +30,7 @@ func NewPostRequest(apiURI, path string, requestBody interface{}) (*http.Request return newRequest(http.MethodPost, apiURI, path, bodyBytes) } +// NewSignedPostRequest signs payload and generates http Post request func NewSignedPostRequest(apiURI, path string, requestBody interface{}, signer identity.Signer) (*http.Request, error) { bodyBytes, err := encodeToJSON(requestBody) if err != nil { From bd4d4ac06a07e114641457c754843186286b395c Mon Sep 17 00:00:00 2001 From: Antanas Masevicius Date: Mon, 26 Feb 2018 15:28:30 +0200 Subject: [PATCH 6/8] introduce MYSTERIUM_DISCOVERY_ADDRESS and MYSTERIUM_BROKER_ADDRESS env variables to control respective cmd line options --- bin/client_docker/docker-entrypoint.sh | 3 ++- bin/client_package/installation/default | 3 +++ bin/server_docker/docker-entrypoint.sh | 4 +++- bin/server_package/installation/default | 6 ++++++ bin/server_package/installation/initd.sh | 1 + docker-compose.yml | 5 ++++- server/response.go | 14 ++++++++++++-- 7 files changed, 31 insertions(+), 5 deletions(-) diff --git a/bin/client_docker/docker-entrypoint.sh b/bin/client_docker/docker-entrypoint.sh index 3c6fd1c5d..1917348a6 100755 --- a/bin/client_docker/docker-entrypoint.sh +++ b/bin/client_docker/docker-entrypoint.sh @@ -10,4 +10,5 @@ exec /usr/bin/mysterium_client \ --data-dir=$OS_DIR_DATA \ --runtime-dir=$OS_DIR_RUN \ --tequilapi.address=localhost \ - --tequilapi.port=$MYSTERIUM_CLIENT_TEQUILAPI_PORT \ No newline at end of file + --tequilapi.port=$MYSTERIUM_CLIENT_TEQUILAPI_PORT \ + --discovery-address=$MYSTERIUM_DISCOVERY_ADDRESS \ diff --git a/bin/client_package/installation/default b/bin/client_package/installation/default index 3148a1adb..a68d8b3f1 100755 --- a/bin/client_package/installation/default +++ b/bin/client_package/installation/default @@ -5,3 +5,6 @@ MYSTERIUM_CLIENT_TEQUILAPI_ADDRESS="localhost" # Port for listening incoming api requests MYSTERIUM_CLIENT_TEQUILAPI_PORT="4050" + +# Mysterium discovery address (default: http://testnet.mysterium.network:5000/v1) +MYSTERIUM_DISCOVERY_ADDRESS: "" diff --git a/bin/server_docker/docker-entrypoint.sh b/bin/server_docker/docker-entrypoint.sh index 018059c64..7ce34bae8 100755 --- a/bin/server_docker/docker-entrypoint.sh +++ b/bin/server_docker/docker-entrypoint.sh @@ -23,4 +23,6 @@ exec /usr/bin/mysterium_server \ --identity=$MYSTERIUM_SERVER_IDENTITY \ --identity.passphrase=$MYSTERIUM_SERVER_IDENTITY_PASSPHRASE \ --location.database=$MYSTERIUM_SERVER_COUNTRY_DATABASE \ - --location.country=$MYSTERIUM_SERVER_COUNTRY \ No newline at end of file + --location.country=$MYSTERIUM_SERVER_COUNTRY \ + --discovery-address=$MYSTERIUM_DISCOVERY_ADDRESS \ + --broker-address=$MYSTERIUM_BROKER_ADDRESS diff --git a/bin/server_package/installation/default b/bin/server_package/installation/default index 14a7adad7..a4f9e2928 100755 --- a/bin/server_package/installation/default +++ b/bin/server_package/installation/default @@ -11,3 +11,9 @@ MYSTERIUM_SERVER_COUNTRY_DATABASE="" # Service location country. If not given country is autodetected MYSTERIUM_SERVER_COUNTRY="" + +# Mysterium discovery address (default: http://testnet.mysterium.network:5000/v1) +MYSTERIUM_DISCOVERY_ADDRESS: "" + +# Mysterium broker address (default: testnet.mysterium.network) +MYSTERIUM_BROKER_ADDRESS: "" diff --git a/bin/server_package/installation/initd.sh b/bin/server_package/installation/initd.sh index 6f868144d..99f0c74d9 100755 --- a/bin/server_package/installation/initd.sh +++ b/bin/server_package/installation/initd.sh @@ -117,6 +117,7 @@ function start() { --identity.passphrase=$MYSTERIUM_SERVER_IDENTITY_PASSPHRASE \ --location.database=$MYSTERIUM_SERVER_COUNTRY_DATABASE \ --location.country=$MYSTERIUM_SERVER_COUNTRY \ + --discovery-address=$MYSTERIUM_DISCOVERY_ADDRESS \ >>$DAEMON_STDOUT \ 2>>$DAEMON_STDERR diff --git a/docker-compose.yml b/docker-compose.yml index 0f321946c..d67a02e31 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,6 +32,8 @@ services: environment: MYSTERIUM_SERVER_IDENTITY: "" MYSTERIUM_SERVER_IDENTITY_PASSPHRASE: "" + MYSTERIUM_DISCOVERY_ADDRESS: "" + MYSTERIUM_BROKER_ADDRESS: "" client: privileged: true @@ -50,4 +52,5 @@ services: ports: - 4050:4050 environment: - MYSTERIUM_CLIENT_TEQUILAPI_PORT: 4050 \ No newline at end of file + MYSTERIUM_CLIENT_TEQUILAPI_PORT: 4050 + MYSTERIUM_DISCOVERY_ADDRESS: "" diff --git a/server/response.go b/server/response.go index 5d0f13bbc..bf8d66675 100644 --- a/server/response.go +++ b/server/response.go @@ -7,15 +7,25 @@ import ( "net/http" ) +type ErrorResponse struct { + Error string `json:"error"` +} + func parseResponseError(response *http.Response) error { if response.StatusCode < 200 || response.StatusCode >= 300 { - return fmt.Errorf("server response invalid: %s (%s)", response.Status, response.Request.URL) + var error ErrorResponse + parseResponseJson(response, &error) + return fmt.Errorf("server response invalid: %s (%s) error message: %s", + response.Status, response.Request.URL, error) } - return nil } func parseResponseJson(response *http.Response, dto interface{}) error { + if response.Body == nil { + return nil + } + responseJson, err := ioutil.ReadAll(response.Body) if err != nil { return err From 41a53ab5e9254a9beefff2fcd984f09791bd29d2 Mon Sep 17 00:00:00 2001 From: Antanas Masevicius Date: Mon, 26 Feb 2018 15:33:02 +0200 Subject: [PATCH 7/8] irequestor package renamed to requests --- {requestor => requests}/request.go | 2 +- {requestor => requests}/request_test.go | 2 +- server/mysterium_api.go | 12 ++++++------ server/response_test.go | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) rename {requestor => requests}/request.go (99%) rename {requestor => requests}/request_test.go (98%) diff --git a/requestor/request.go b/requests/request.go similarity index 99% rename from requestor/request.go rename to requests/request.go index cd58a8f41..4d67e2459 100644 --- a/requestor/request.go +++ b/requests/request.go @@ -1,4 +1,4 @@ -package requestor +package requests import ( "bytes" diff --git a/requestor/request_test.go b/requests/request_test.go similarity index 98% rename from requestor/request_test.go rename to requests/request_test.go index 9ef1bd523..169d75413 100644 --- a/requestor/request_test.go +++ b/requests/request_test.go @@ -1,4 +1,4 @@ -package requestor +package requests import ( "bytes" diff --git a/server/mysterium_api.go b/server/mysterium_api.go index 31607d877..63357b854 100644 --- a/server/mysterium_api.go +++ b/server/mysterium_api.go @@ -6,7 +6,7 @@ import ( log "github.com/cihub/seelog" "github.com/mysterium/node/identity" - "github.com/mysterium/node/requestor" + "github.com/mysterium/node/requests" "github.com/mysterium/node/server/dto" dto_discovery "github.com/mysterium/node/service_discovery/dto" "net/url" @@ -37,7 +37,7 @@ func NewClient(discoveryAPIAddress string) Client { } func (mApi *mysteriumAPI) RegisterIdentity(id identity.Identity, signer identity.Signer) error { - req, err := requestor.NewSignedPostRequest(mApi.discoveryAPIAddress, "identities", dto.CreateIdentityRequest{ + req, err := requests.NewSignedPostRequest(mApi.discoveryAPIAddress, "identities", dto.CreateIdentityRequest{ Identity: id.Address, }, signer) if err != nil { @@ -52,7 +52,7 @@ func (mApi *mysteriumAPI) RegisterIdentity(id identity.Identity, signer identity } func (mApi *mysteriumAPI) RegisterProposal(proposal dto_discovery.ServiceProposal, signer identity.Signer) error { - req, err := requestor.NewSignedPostRequest(mApi.discoveryAPIAddress, "register_proposal", dto.NodeRegisterRequest{ + req, err := requests.NewSignedPostRequest(mApi.discoveryAPIAddress, "register_proposal", dto.NodeRegisterRequest{ ServiceProposal: proposal, }, signer) if err != nil { @@ -68,7 +68,7 @@ func (mApi *mysteriumAPI) RegisterProposal(proposal dto_discovery.ServiceProposa } func (mApi *mysteriumAPI) PingProposal(proposal dto_discovery.ServiceProposal, signer identity.Signer) error { - req, err := requestor.NewSignedPostRequest(mApi.discoveryAPIAddress, "ping_proposal", dto.NodeStatsRequest{ + req, err := requests.NewSignedPostRequest(mApi.discoveryAPIAddress, "ping_proposal", dto.NodeStatsRequest{ NodeKey: proposal.ProviderID, }, signer) if err != nil { @@ -88,7 +88,7 @@ func (mApi *mysteriumAPI) FindProposals(providerID string) ([]dto_discovery.Serv values.Set("node_key", providerID) } - req, err := requestor.NewGetRequest(mApi.discoveryAPIAddress, "proposals", values) + req, err := requests.NewGetRequest(mApi.discoveryAPIAddress, "proposals", values) if err != nil { return nil, err } @@ -106,7 +106,7 @@ func (mApi *mysteriumAPI) FindProposals(providerID string) ([]dto_discovery.Serv func (mApi *mysteriumAPI) SendSessionStats(sessionId string, sessionStats dto.SessionStats, signer identity.Signer) error { path := fmt.Sprintf("sessions/%s/stats", sessionId) - req, err := requestor.NewSignedPostRequest(mApi.discoveryAPIAddress, path, sessionStats, signer) + req, err := requests.NewSignedPostRequest(mApi.discoveryAPIAddress, path, sessionStats, signer) if err != nil { return err } diff --git a/server/response_test.go b/server/response_test.go index 75a52d7be..2299ce817 100644 --- a/server/response_test.go +++ b/server/response_test.go @@ -2,17 +2,17 @@ package server import ( "bytes" - "github.com/mysterium/node/requestor" + "github.com/mysterium/node/requests" "github.com/stretchr/testify/assert" "io/ioutil" "net/http" "testing" ) -var testRequestApiUrl = "http://testUrl" +var testRequestAPIURL = "http://testUrl" func TestHttpErrorIsReportedAsErrorReturnValue(t *testing.T) { - req, err := requestor.NewGetRequest(testRequestApiUrl, "path", nil) + req, err := requests.NewGetRequest(testRequestAPIURL, "path", nil) assert.NoError(t, err) response := &http.Response{ @@ -29,7 +29,7 @@ type testResponse struct { func TestHttpResponseBodyIsParsedCorrectly(t *testing.T) { - req, err := requestor.NewGetRequest(testRequestApiUrl, "path", nil) + req, err := requests.NewGetRequest(testRequestAPIURL, "path", nil) assert.NoError(t, err) response := &http.Response{ From 6791b53418ee809d5fd5eebdc7ea00e097b0a15d Mon Sep 17 00:00:00 2001 From: Antanas Masevicius Date: Mon, 26 Feb 2018 17:18:50 +0200 Subject: [PATCH 8/8] naming fixes --- bin/client_package/installation/default | 2 +- bin/client_run | 2 +- bin/helpers/load_run_environment.sh | 4 ++-- bin/server_package/installation/default | 4 ++-- bin/server_run | 4 ++-- cmd/commands/server/options.go | 1 + server/response.go | 4 ++-- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/bin/client_package/installation/default b/bin/client_package/installation/default index a68d8b3f1..071726811 100755 --- a/bin/client_package/installation/default +++ b/bin/client_package/installation/default @@ -6,5 +6,5 @@ MYSTERIUM_CLIENT_TEQUILAPI_ADDRESS="localhost" # Port for listening incoming api requests MYSTERIUM_CLIENT_TEQUILAPI_PORT="4050" -# Mysterium discovery address (default: http://testnet.mysterium.network:5000/v1) +# Mysterium discovery address (eg.: http://testnet.mysterium.network:5000/v1) MYSTERIUM_DISCOVERY_ADDRESS: "" diff --git a/bin/client_run b/bin/client_run index eff20437d..1a3e0c57b 100755 --- a/bin/client_run +++ b/bin/client_run @@ -5,5 +5,5 @@ source bin/helpers/load_run_environment.sh sudo ./build/client/mysterium_client \ --config-dir=bin/client_package/config \ --runtime-dir=build/client \ - $DISCOVERY \ + $DISCOVERY_OPTION\ $@ diff --git a/bin/helpers/load_run_environment.sh b/bin/helpers/load_run_environment.sh index c7870e7f8..2f47e20fc 100644 --- a/bin/helpers/load_run_environment.sh +++ b/bin/helpers/load_run_environment.sh @@ -3,6 +3,6 @@ if [ -f .env ]; then source .env - [ -n "$MYSTERIUM_API_URL" ] && DISCOVERY="--discovery-address=$MYSTERIUM_API_URL" - [ -n "$NATS_SERVER_IP" ] && BROKER="--broker-address=$NATS_SERVER_IP" + [ -n "$MYSTERIUM_API_URL" ] && DISCOVERY_OPTION="--discovery-address=$MYSTERIUM_API_URL" + [ -n "$NATS_SERVER_IP" ] && BROKER_OPTION="--broker-address=$NATS_SERVER_IP" fi diff --git a/bin/server_package/installation/default b/bin/server_package/installation/default index a4f9e2928..caf6b0cac 100755 --- a/bin/server_package/installation/default +++ b/bin/server_package/installation/default @@ -12,8 +12,8 @@ MYSTERIUM_SERVER_COUNTRY_DATABASE="" # Service location country. If not given country is autodetected MYSTERIUM_SERVER_COUNTRY="" -# Mysterium discovery address (default: http://testnet.mysterium.network:5000/v1) +# Mysterium discovery address (eg.: http://testnet.mysterium.network:5000/v1) MYSTERIUM_DISCOVERY_ADDRESS: "" -# Mysterium broker address (default: testnet.mysterium.network) +# Mysterium broker address (eg.: testnet.mysterium.network) MYSTERIUM_BROKER_ADDRESS: "" diff --git a/bin/server_run b/bin/server_run index ea3edf64d..bc0a23f24 100755 --- a/bin/server_run +++ b/bin/server_run @@ -5,6 +5,6 @@ source bin/helpers/load_run_environment.sh sudo ./build/server/mysterium_server \ --config-dir=bin/server_package/config \ --runtime-dir=build/server \ - $DISCOVERY \ - $BROKER \ + $DISCOVERY_OPTION \ + $BROKER_OPTION \ $@ diff --git a/cmd/commands/server/options.go b/cmd/commands/server/options.go index 0dd2a68c7..f8cbdfe38 100644 --- a/cmd/commands/server/options.go +++ b/cmd/commands/server/options.go @@ -24,6 +24,7 @@ type CommandOptions struct { const defaultLocationDatabase = "GeoLite2-Country.mmdb" +// TODO: rename to brokerAddress var natsServerIP string // ParseArguments parses CLI flags and adds to CommandOptions structure diff --git a/server/response.go b/server/response.go index bf8d66675..ecaffbf48 100644 --- a/server/response.go +++ b/server/response.go @@ -7,13 +7,13 @@ import ( "net/http" ) -type ErrorResponse struct { +type errorResponse struct { Error string `json:"error"` } func parseResponseError(response *http.Response) error { if response.StatusCode < 200 || response.StatusCode >= 300 { - var error ErrorResponse + var error errorResponse parseResponseJson(response, &error) return fmt.Errorf("server response invalid: %s (%s) error message: %s", response.Status, response.Request.URL, error)