Developing lightweight computation at the DSG edge

Commit e88c2ca0 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[fetch] Use DeviceIPv4Addresses in AntidoteDB's functions



This avoids writing to AntidoteDB devices which have no IPv4 address(es)
to monitor.
Signed-off-by: default avatarRoger Pueyo Centelles <roger.pueyo@guifi.net>
parent 535534a2
......@@ -290,7 +290,7 @@ func main() {
// Remove from AntidoteDB those devices that are not in the CNML file anymore
for _, v := range antidoteDevices {
if !isDeviceInArray(v, alldevices) {
if !isDeviceIPv4AddressesInArray(v, devsadds) {
if removeDeviceFromAntidote(v) {
antidoteDelSucc++
} else {
......@@ -302,8 +302,8 @@ func main() {
fmt.Printf("\r%d devices removed from AntidoteDB (%d success, %d fail)\n", antidoteDelSucc+antidoteDelFail, antidoteDelSucc, antidoteDelFail)
// Add to AntidoteDB those devices that are new in the CNML file
for _, v := range alldevices {
if !isDeviceInArray(v, antidoteDevices) {
for _, v := range devsadds {
if !isDeviceIPv4AddressesInArray(v, antidoteDevices) && len(v.Addresses) > 0 {
if saveDeviceToAntidote(v.ID) {
antidoteDevSucc++
} else {
......@@ -536,7 +536,7 @@ func getZonesInZoneExc(zone Zone) []Zone {
}
// Remove a device by its ID from Antidote using João's REST server
func removeDeviceFromAntidote(device Device) bool {
func removeDeviceFromAntidote(device DeviceIpv4Adddresses) bool {
request := fmt.Sprintf("http://localhost:3000/set/remove/guifi/devices/%d", device.ID)
//fmt.Println("Saving device", ID, "to AntidoteDB")
response, err := http.Get(request)
......@@ -560,8 +560,8 @@ func removeDeviceFromAntidote(device Device) bool {
}
// Read all the devices from Antidote using João's REST server
func readDevicesFromAntidote() []Device {
var devices []Device
func readDevicesFromAntidote() []DeviceIpv4Adddresses {
var devices []DeviceIpv4Adddresses
request := fmt.Sprintf("http://localhost:3000/set/read/guifi/devices")
response, err := http.Get(request)
......@@ -581,7 +581,7 @@ func readDevicesFromAntidote() []Device {
for _, v := range stringRestReply {
thisDevID, err := strconv.Atoi(v)
errCheck(err)
var thisDev Device
var thisDev DeviceIpv4Adddresses
thisDev.ID = thisDevID
devices = append(devices, thisDev)
//println(v, thisDevID)
......@@ -641,7 +641,7 @@ func saveDeviceIpv4ToAntidote(ID int, Ipv4 string) bool {
}
// Check if an int item is in an ints array
func isDeviceInArray(device Device, devices []Device) bool {
func isDeviceIPv4AddressesInArray(device DeviceIpv4Adddresses, devices []DeviceIpv4Adddresses) bool {
for _, v := range devices {
if v.ID == device.ID {
return true
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment