Skip to content

Commit

Permalink
Merge pull request #685 from mysteriumnetwork/hotfix/backport-fixes
Browse files Browse the repository at this point in the history
Hotfix/backport fixes
  • Loading branch information
tadovas authored Jan 29, 2019
2 parents a563484 + 3f454bb commit 9bbe207
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion core/connection/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ func (manager *connectionManager) startConnection(consumerID identity.Identity,
}
cancel = append(cancel, connection.Stop)

//consume statistics right after start - openvpn3 will publish them even before connected state
go manager.consumeStats(statisticsChannel)
err = manager.waitForConnectedState(stateChannel, sessionID)
if err != nil {
return err
Expand All @@ -214,7 +216,6 @@ func (manager *connectionManager) startConnection(consumerID identity.Identity,
firewall.NewKillSwitch().Enable()
}

go manager.consumeStats(statisticsChannel)
go manager.consumeConnectionStates(stateChannel)
go connectionWaiter(connection, dialog, promiseIssuer)
return nil
Expand Down
16 changes: 12 additions & 4 deletions mobile/mysterium/openvpn_connection_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"errors"
"sync"

"github.com/cihub/seelog"
log "github.com/cihub/seelog"
"github.com/mysteriumnetwork/go-openvpn/openvpn3"
"github.com/mysteriumnetwork/node/consumer"
"github.com/mysteriumnetwork/node/core/connection"
Expand Down Expand Up @@ -73,6 +73,8 @@ func channelToCallbacks(stateChannel connection.StateChannel, statisticsChannel
}
}

const openvpn3Log = "[Openvpn3]"

type channelToCallbacksAdapter struct {
stateChannel connection.StateChannel
statisticsChannel connection.StatisticsChannel
Expand All @@ -88,20 +90,26 @@ func (adapter channelToCallbacksAdapter) OnEvent(event openvpn3.Event) {
adapter.stateChannel <- connection.Disconnecting
adapter.stateChannel <- connection.NotConnected
close(adapter.stateChannel)
close(adapter.statisticsChannel)
default:
seelog.Infof("Unhandled event: %+v", event)
log.Infof("%v Unhandled event: %+v", openvpn3Log, event)
}
}

func (channelToCallbacksAdapter) Log(text string) {
seelog.Infof("Log: %+v", text)
log.Infof("%v Log: %+v", openvpn3Log, text)
}

func (adapter channelToCallbacksAdapter) OnStats(openvpnStats openvpn3.Statistics) {
adapter.statisticsChannel <- consumer.SessionStatistics{
sessionStats := consumer.SessionStatistics{
BytesSent: uint64(openvpnStats.BytesOut),
BytesReceived: uint64(openvpnStats.BytesIn),
}
select {
case adapter.statisticsChannel <- sessionStats:
default:
log.Warn(openvpn3Log, " Statistics dropped. Channel full")
}
}

// Openvpn3TunnelSetup is alias for openvpn3 tunnel setup interface exposed to Android/iOS interop
Expand Down

0 comments on commit 9bbe207

Please sign in to comment.