Skip to content

Commit

Permalink
keep connection info history
Browse files Browse the repository at this point in the history
  • Loading branch information
asabya committed Sep 13, 2021
1 parent 5c3ddd3 commit e33fd69
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions internal/matrix/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ type DiscoveredNodeMatrix struct {
Frequency int
IPFSConnectedAt int64
DiscoveryDelays []int64 // from BLE Discovery to ipfs Connection
ConnectionHistory []ConnectionInfo
}

type ConnectionInfo struct {
BLEDiscoveredAt int64
WifiConnectedAt int64
RSSI int
Speed int
Frequency int
IPFSConnectedAt int64
DisconnectedAt int64
}

type MatrixKeeper struct {
Expand Down Expand Up @@ -179,7 +190,8 @@ func (mKeeper *MatrixKeeper) BLEDiscovered(address string) {

if mKeeper.NodeMatrix.NodesDiscovered[address] == nil {
mKeeper.NodeMatrix.NodesDiscovered[address] = &DiscoveredNodeMatrix{
DiscoveryDelays: []int64{},
DiscoveryDelays: []int64{},
ConnectionHistory: []ConnectionInfo{},
}
}
nodeMatrix := mKeeper.NodeMatrix.NodesDiscovered[address]
Expand All @@ -195,7 +207,8 @@ func (mKeeper *MatrixKeeper) WifiConnected(address string, rssi, speed, freq int

if mKeeper.NodeMatrix.NodesDiscovered[address] == nil {
mKeeper.NodeMatrix.NodesDiscovered[address] = &DiscoveredNodeMatrix{
DiscoveryDelays: []int64{},
DiscoveryDelays: []int64{},
ConnectionHistory: []ConnectionInfo{},
}
}
nodeMatrix := mKeeper.NodeMatrix.NodesDiscovered[address]
Expand All @@ -214,7 +227,8 @@ func (mKeeper *MatrixKeeper) NodeConnected(address string) {

if mKeeper.NodeMatrix.NodesDiscovered[address] == nil {
mKeeper.NodeMatrix.NodesDiscovered[address] = &DiscoveredNodeMatrix{
DiscoveryDelays: []int64{},
DiscoveryDelays: []int64{},
ConnectionHistory: []ConnectionInfo{},
}
}
nodeMatrix := mKeeper.NodeMatrix.NodesDiscovered[address]
Expand All @@ -236,7 +250,8 @@ func (mKeeper *MatrixKeeper) NodeConnectionFailed(address string) {

if mKeeper.NodeMatrix.NodesDiscovered[address] == nil {
mKeeper.NodeMatrix.NodesDiscovered[address] = &DiscoveredNodeMatrix{
DiscoveryDelays: []int64{},
DiscoveryDelays: []int64{},
ConnectionHistory: []ConnectionInfo{},
}
}

Expand All @@ -252,10 +267,27 @@ func (mKeeper *MatrixKeeper) NodeDisconnected(address string) {

nodeMatrix := mKeeper.NodeMatrix.NodesDiscovered[address]
nodeMatrix.LastSuccessfulConnectionDuration = time.Now().Unix() - nodeMatrix.IPFSConnectedAt

history := ConnectionInfo{
BLEDiscoveredAt: nodeMatrix.BLEDiscoveredAt,
WifiConnectedAt: nodeMatrix.WifiConnectedAt,
RSSI: nodeMatrix.RSSI,
Speed: nodeMatrix.Speed,
Frequency: nodeMatrix.Frequency,
IPFSConnectedAt: nodeMatrix.IPFSConnectedAt,
DisconnectedAt: time.Now().Unix(),
}
if nodeMatrix.ConnectionHistory == nil {
nodeMatrix.ConnectionHistory = []ConnectionInfo{}
}
nodeMatrix.ConnectionHistory = append(nodeMatrix.ConnectionHistory, history)
nodeMatrix.ConnectionAlive = false
nodeMatrix.BLEDiscoveredAt = 0
nodeMatrix.WifiConnectedAt = 0
nodeMatrix.IPFSConnectedAt = 0
nodeMatrix.RSSI = 0
nodeMatrix.Speed = 0
nodeMatrix.Frequency = 0
}

func (mKeeper *MatrixKeeper) ContentDownloadStarted(hash string, size int64) {
Expand Down

0 comments on commit e33fd69

Please sign in to comment.