Skip to content

Commit

Permalink
Merge branch 'mainnet' into feature/embedded-profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuryshev committed Jun 14, 2019
2 parents e34fb68 + 9e48642 commit dfa7d6c
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 30 deletions.
11 changes: 11 additions & 0 deletions integration/check-route-finder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
echo -e "\n\n" ROUTE-FINDER "\n\n"

echo
echo '{"src_pk":''"'$PK_A'","dst_pk":''"'$PK_C'","min_hops":0, "max_hops":50}'
echo '{"src_pk":''"'$PK_A'","dst_pk":''"'$PK_C'","min_hops":0, "max_hops":50}' |curl -X GET $RF/routes -d@-
echo
echo '{"src_pk":''"'$PK_A'","dst_pk":''"'$PK_B'","min_hops":0, "max_hops":50}'
echo '{"src_pk":''"'$PK_A'","dst_pk":''"'$PK_B'","min_hops":0, "max_hops":50}' |curl -X GET $RF/routes -d@-
echo
echo '{"src_pk":''"'$PK_B'","dst_pk":''"'$PK_C'","min_hops":0, "max_hops":50}'
echo '{"src_pk":''"'$PK_B'","dst_pk":''"'$PK_C'","min_hops":0, "max_hops":50}' |curl -X GET $RF/routes -d@-
43 changes: 43 additions & 0 deletions integration/check-services.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

echo -e "\n\n" MESSAGING-DISCOVERY

echo -e "\n\n" $MSGD/messaging-discovery/available_servers"\n"
curl $MSGD/messaging-discovery/available_servers

echo -e "\n\n" $MSGD/messaging-discovery/entry/PK_A"\n"
curl $MSGD/messaging-discovery/entry/$PK_A

echo -e "\n\n" $MSGD/messaging-discovery/entry/PK_B"\n"
curl $MSGD/messaging-discovery/entry/$PK_B

echo -e "\n\n" $MSGD/messaging-discovery/entry/PK_C"\n"
curl $MSGD/messaging-discovery/entry/$PK_C


echo -e "\n\n" TRANSPORT-DISCOVERY

echo -e "\n\n" $TRD/security/nonces/PK_A"\n"
curl $TRD/security/nonces/$PK_A
echo -e "\n\n" $TRD/transports/edge:PK_A "\n"
curl $TRD/transports/edge:$PK_A

echo -e "\n\n" $TRD/security/nonces/PK_B"\n"
curl $TRD/security/nonces/$PK_B
echo -e "\n\n" $TRD/transports/edge:PK_B "\n"
curl $TRD/transports/edge:$PK_B
echo -e "\n\n" $TRD/security/nonces/PK_C"\n"
curl $TRD/security/nonces/$PK_C
echo -e "\n\n" $TRD/transports/edge:PK_C "\n"
curl $TRD/transports/edge:$PK_C

echo -e "\n\n" ROUTE-FINDER "\n\n"

echo
echo '{"src_pk":''"'$PK_A'","dst_pk":''"'$PK_C'","min_hops":0, "max_hops":50}'
echo '{"src_pk":''"'$PK_A'","dst_pk":''"'$PK_C'","min_hops":0, "max_hops":50}' |curl -X GET $RF/routes -d@-
echo
echo '{"src_pk":''"'$PK_A'","dst_pk":''"'$PK_B'","min_hops":0, "max_hops":50}'
echo '{"src_pk":''"'$PK_A'","dst_pk":''"'$PK_B'","min_hops":0, "max_hops":50}' |curl -X GET $RF/routes -d@-
echo
echo '{"src_pk":''"'$PK_B'","dst_pk":''"'$PK_C'","min_hops":0, "max_hops":50}'
echo '{"src_pk":''"'$PK_B'","dst_pk":''"'$PK_C'","min_hops":0, "max_hops":50}' |curl -X GET $RF/routes -d@-
10 changes: 7 additions & 3 deletions integration/generic/env-vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ export RPC_C=$(jq -r ".interfaces.rpc" ./integration/generic/nodeC.json)
export CHAT_A=http://localhost:8000/message
export CHAT_C=http://localhost$(jq -r '.apps [] |select(.app=="skychat")| .args[1] ' ./integration/generic/nodeC.json)/message

alias CLI_A='./bin/skywire-cli --rpc $RPC_A'
alias CLI_B='./bin/skywire-cli --rpc $RPC_B'
alias CLI_C='./bin/skywire-cli --rpc $RPC_C'
alias CLI_A='./skywire-cli --rpc $RPC_A'
alias CLI_B='./skywire-cli --rpc $RPC_B'
alias CLI_C='./skywire-cli --rpc $RPC_C'

export MSGD=https://messaging.discovery.skywire.skycoin.net
export TRD=https://transport.discovery.skywire.skycoin.net
export RF=https://routefinder.skywire.skycoin.net

echo PK_A: $PK_A
echo PK_B: $PK_B
Expand Down
1 change: 1 addition & 0 deletions integration/intermediary-nodeB.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557"
],
"route_finder": "https://routefinder.skywire.skycoin.net/",
"route_finder_timeout": "60s",
"table": {
"type": "boltdb",
"location": "./local/nodeB/routing.db"
Expand Down
26 changes: 17 additions & 9 deletions integration/messaging/env-vars.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
# This script needs to be `source`d from bash-compatible shell
# E.g. `source ./integration/generic/env-vars.sh` or `. ./integration/generic/env-vars.sh`
export PK_A=$(jq -r ".node.static_public_key" ./integration/generic/nodeA.json)
export RPC_A=$(jq -r ".interfaces.rpc" ./integration/generic/nodeA.json)
# E.g. `source ./integration/generic/env-vars.sh` or `. ./integration/messaging/env-vars.sh`
export PK_A=$(jq -r ".node.static_public_key" ./integration/messaging/nodeA.json)
export RPC_A=$(jq -r ".interfaces.rpc" ./integration/messaging/nodeA.json)
export PK_B=$(jq -r ".node.static_public_key" ./integration/intermediary-nodeB.json)
export RPC_B=$(jq -r ".interfaces.rpc" ./integration/intermediary-nodeB.json)
export PK_C=$(jq -r ".node.static_public_key" ./integration/generic/nodeC.json)
export RPC_C=$(jq -r ".interfaces.rpc" ./integration/generic/nodeC.json)
export PK_C=$(jq -r ".node.static_public_key" ./integration/messaging/nodeC.json)
export RPC_C=$(jq -r ".interfaces.rpc" ./integration/messaging/nodeC.json)

export CHAT_A=http://localhost:8000/message
export CHAT_C=http://localhost$(jq -r '.apps [] |select(.app=="skychat")| .args[1] ' ./integration/generic/nodeC.json)/message
export CHAT_C=http://localhost$(jq -r '.apps [] |select(.app=="skychat")| .args[1] ' ./integration/messaging/nodeC.json)/message

alias CLI_A='./bin/skywire-cli --rpc $RPC_A'
alias CLI_B='./bin/skywire-cli --rpc $RPC_B'
alias CLI_C='./bin/skywire-cli --rpc $RPC_C'
export MSGD=https://messaging.discovery.skywire.skycoin.net
export TRD=https://transport.discovery.skywire.skycoin.net
export RF=https://routefinder.skywire.skycoin.net

alias CLI_A='./skywire-cli --rpc $RPC_A'
alias CLI_B='./skywire-cli --rpc $RPC_B'
alias CLI_C='./skywire-cli --rpc $RPC_C'

alias RUN_A='./skywire-node ./integration/messaging/nodeA.json --tag NodeA'
alias RUN_B='./skywire-node ./integration/messaging/intermediary-nodeB.json --tag NodeB'
alias RUN_C='./skywire-node ./integration/messaging/nodeC.json --tag NodeC'

echo PK_A: $PK_A
echo PK_B: $PK_B
Expand Down
2 changes: 2 additions & 0 deletions integration/messaging/nodeA.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557"
],
"route_finder": "https://routefinder.skywire.skycoin.net/",
"route_finder_timeout": "60s",
"table": {
"type": "boltdb",
"location": "./local/nodeA/routing.db"
Expand All @@ -37,6 +38,7 @@
"trusted_nodes": [],
"manager_nodes": [],
"apps_path": "./apps",
"shutdown_timeout": "30s",
"local_path": "./local/nodeA",
"log_level": "info",
"interfaces": {
Expand Down
2 changes: 2 additions & 0 deletions integration/messaging/nodeC.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557"
],
"route_finder": "https://routefinder.skywire.skycoin.net/",
"route_finder_timeout": "60s",
"table": {
"type": "boltdb",
"location": "./local/nodeC/routing.db"
Expand All @@ -37,6 +38,7 @@
"trusted_nodes": [],
"manager_nodes": [],
"apps_path": "./apps",
"shutdown_timeout": "30s",
"local_path": "./local/nodeC",
"log_level": "info",
"interfaces": {
Expand Down
14 changes: 11 additions & 3 deletions integration/proxy/env-vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ export RPC_B=$(jq -r ".interfaces.rpc" ./integration/intermediary-nodeB.json)
export PK_C=$(jq -r ".node.static_public_key" ./integration/proxy/nodeC.json)
export RPC_C=$(jq -r ".interfaces.rpc" ./integration/proxy/nodeC.json)

alias CLI_A='./bin/skywire-cli --rpc $RPC_A'
alias CLI_B='./bin/skywire-cli --rpc $RPC_B'
alias CLI_C='./bin/skywire-cli --rpc $RPC_C'
alias CLI_A='./skywire-cli --rpc $RPC_A'
alias CLI_B='./skywire-cli --rpc $RPC_B'
alias CLI_C='./skywire-cli --rpc $RPC_C'

export MSGD=https://messaging.discovery.skywire.skycoin.net
export TRD=https://transport.discovery.skywire.skycoin.net
export RF=https://routefinder.skywire.skycoin.net

alias RUN_A='go run ./cmd/skywire-node ./integration/messaging/nodeA.json --tag NodeA'
alias RUN_B='go run ./cmd/skywire-node ./integration/intermediary-nodeB.json --tag NodeB'
alias RUN_C='go run ./cmd/skywire-node ./integration/messaging/nodeC.json --tag NodeC'

echo PK_A: $PK_A
echo PK_B: $PK_B
Expand Down
14 changes: 11 additions & 3 deletions integration/ssh/env-vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ export RPC_B=$(jq -r ".interfaces.rpc" ./integration/intermediary-nodeB.json)
export PK_C=$(jq -r ".node.static_public_key" ./integration/ssh/nodeC.json)
export RPC_C=$(jq -r ".interfaces.rpc" ./integration/ssh/nodeC.json)

alias CLI_A='./bin/skywire-cli --rpc $RPC_A'
alias CLI_B='./bin/skywire-cli --rpc $RPC_B'
alias CLI_C='./bin/skywire-cli --rpc $RPC_C'
alias CLI_A='./skywire-cli --rpc $RPC_A'
alias CLI_B='./skywire-cli --rpc $RPC_B'
alias CLI_C='./skywire-cli --rpc $RPC_C'

export MSGD=https://messaging.discovery.skywire.skycoin.net
export TRD=https://transport.discovery.skywire.skycoin.net
export RF=https://routefinder.skywire.skycoin.net

alias RUN_A='go run ./cmd/skywire-node ./integration/messaging/nodeA.json --tag NodeA'
alias RUN_B='go run ./cmd/skywire-node ./integration/intermediary-nodeB.json --tag NodeB'
alias RUN_C='go run ./cmd/skywire-node ./integration/messaging/nodeC.json --tag NodeC'

echo PK_A: $PK_A
echo PK_B: $PK_B
Expand Down
2 changes: 1 addition & 1 deletion integration/test-messaging.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
source ./integration/generic/env-vars.sh
curl --data {'"recipient":"'$PK_A'", "message":"Hello Joe!"}' -X POST $CHAT_C
# curl --data {'"recipient":"'$PK_A'", "message":"Hello Joe!"}' -X POST $CHAT_C
curl --data {'"recipient":"'$PK_C'", "message":"Hello Mike!"}' -X POST $CHAT_A
1 change: 1 addition & 0 deletions pkg/messaging/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func newChannel(initiator bool, secKey cipher.SecKey, remote cipher.PubKey, link
readChan: make(chan []byte),
doneChan: make(chan struct{}),
noise: noiseInstance,
deadline: time.Time{},
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/messaging/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ var (
// ErrRejected indicates that ChannelOpen frame was rejected by remote server.
ErrRejected = errors.New("rejected")
// ErrChannelClosed indicates that underlying channel is being closed and writes are prohibited.
ErrChannelClosed = errors.New("channel closed")
ErrChannelClosed = errors.New("messaging channel closed")
// ErrDeadlineExceeded indicates that read/write operation failed due to timeout.
ErrDeadlineExceeded = errors.New("deadline exceeded")
ErrDeadlineExceeded = errors.New("deadline exceeded in messaging")
// ErrClientClosed indicates that client is closed and not accepting new connections.
ErrClientClosed = errors.New("client closed")
)
Expand Down
29 changes: 20 additions & 9 deletions pkg/transport/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,55 +22,64 @@ func (handshake settlementHandshake) Do(tm *Manager, tr Transport, timeout time.
case <-done:
return entry, err
case <-time.After(timeout):
return nil, errors.New("deadline exceeded")
tm.Logger.Infof("handshake.Do timeout exceeded for value: %v", timeout)
return nil, errors.New("deadline exceeded on handshake")
}
}

func settlementInitiatorHandshake(public bool) settlementHandshake {
return func(tm *Manager, tr Transport) (*Entry, error) {
tm.Logger.Info("Entering settlementInitiatorHandshake")
entry := &Entry{
ID: MakeTransportID(tr.Edges()[0], tr.Edges()[1], tr.Type(), public),
EdgeKeys: tr.Edges(),
Type: tr.Type(),
Public: public,
}

remote, ok := tm.Remote(tr.Edges())
if !ok {
return nil, errors.New("configured PubKey not found in edges")
}

tm.Logger.Infof("settlementInitiatorHandshake: NewSignedEntry with %v", remote)
sEntry, ok := NewSignedEntry(entry, tm.config.PubKey, tm.config.SecKey)
if !ok {
return nil, errors.New("error creating signed entry")
}
tm.Logger.Info("settlementInitiatorHandshake: validateSignedEntry")
if err := validateSignedEntry(sEntry, tr, tm.config.PubKey); err != nil {
return nil, fmt.Errorf("settlementInitiatorHandshake NewSignedEntry: %s\n sEntry: %v", err, sEntry)
}

tm.Logger.Info("settlementInitiatorHandshake: json.NewEncoder.Encode")
if err := json.NewEncoder(tr).Encode(sEntry); err != nil {
return nil, fmt.Errorf("write: %s", err)
}

tm.Logger.Info("settlementInitiatorHandshake: json.NewDecoder")
respSEntry := &SignedEntry{}
if err := json.NewDecoder(tr).Decode(respSEntry); err != nil {
return nil, fmt.Errorf("read: %s", err)
}

// Verifying remote signature
remote, ok := tm.Remote(tr.Edges())
if !ok {
return nil, errors.New("configured PubKey not found in edges")
}

tm.Logger.Info("settlementInitiatorHandshake: verifySig")
if err := verifySig(respSEntry, remote); err != nil {
return nil, err
}

tm.Logger.Info("settlementInitiatorHandshake: tm.walkEntries")
newEntry := tm.walkEntries(func(e *Entry) bool { return *e == *respSEntry.Entry }) == nil
if newEntry {
tm.addEntry(entry)
}

tm.Logger.Info("Exiting settlementInitiatorHandshake")
return respSEntry.Entry, nil
}
}

func settlementResponderHandshake(tm *Manager, tr Transport) (*Entry, error) {
tm.Logger.Info("Entering settlementResponderHandshake")
sEntry := &SignedEntry{}
if err := json.NewDecoder(tr).Decode(sEntry); err != nil {
return nil, fmt.Errorf("read: %s", err)
Expand All @@ -91,6 +100,7 @@ func settlementResponderHandshake(tm *Manager, tr Transport) (*Entry, error) {

newEntry := tm.walkEntries(func(e *Entry) bool { return *e == *sEntry.Entry }) == nil

tm.Logger.Info("Entering settlementResponderHandshake: DiscoveryClient.UpdateStatuses/RegisterTransports")
var err error
if sEntry.Entry.Public {
if !newEntry {
Expand All @@ -104,14 +114,15 @@ func settlementResponderHandshake(tm *Manager, tr Transport) (*Entry, error) {
return nil, fmt.Errorf("entry set: %s", err)
}

tm.Logger.Info("Entering settlementResponderHandshake: json.NewEncoder(tr).Encode")
if err := json.NewEncoder(tr).Encode(sEntry); err != nil {
return nil, fmt.Errorf("write: %s", err)
}

if newEntry {
tm.addEntry(sEntry.Entry)
}

tm.Logger.Info("Exiting settlementResponderHandshake")
return sEntry.Entry, nil
}

Expand Down

0 comments on commit dfa7d6c

Please sign in to comment.