242 lines
9.2 KiB
JavaScript
242 lines
9.2 KiB
JavaScript
import styles from './style'
|
|
import React, { Component } from 'react';
|
|
import { Div, StyleSheet, Text, View, ScrollView, Alert, Button, TouchableHighlight, Image, Collapsile } from 'react-native';
|
|
import wifi from 'react-native-android-wifi';
|
|
import MapView from 'react-native-maps';
|
|
import { createStackNavigator } from 'react-navigation';
|
|
import { YellowBox } from 'react-native';
|
|
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader']); //Silence Bug in React-Navigation
|
|
|
|
|
|
export default class NodeInfNavigation extends React.Component {
|
|
static navigationOptions = {
|
|
title: 'Node Info',
|
|
};
|
|
render() {
|
|
/* 2. Get the param, provide a fallback value if not available */
|
|
const { navigation } = this.props;
|
|
const dataATT = navigation.getParam('dataATT', 'NO-ID');
|
|
const currentBSSID = navigation.getParam('currentBSSID', 'NO');
|
|
const hostName = navigation.getParam('hostName', 'NO');
|
|
|
|
|
|
tryNextHop = () => {
|
|
for (var k2 in dataATT) {
|
|
if (dataATT.hasOwnProperty(k2)) {
|
|
// console.log('first Step ', k2)
|
|
if (dataATT[k2].nodeinfo.node_id == hopCurrent) {
|
|
hopsOnWay.push(dataATT[k2].nodeinfo.hostname);
|
|
localCloud.push(dataATT[k2].nodeinfo.node_id);
|
|
clientsLocal += dataATT[k2].statistics.clients;
|
|
if (dataATT[k2].statistics.gateway === dataATT[k2].statistics.gateway_nexthop) {
|
|
gatewayLastFound = true;
|
|
return;
|
|
}
|
|
else {
|
|
hopCurrent = dataATT[k2].statistics.gateway_nexthop;
|
|
return;
|
|
}
|
|
}
|
|
|
|
// ++count; //amount of nodes
|
|
}
|
|
};
|
|
console.log('Fehler: GatewayLastFound wurde manuell gesetzt');
|
|
gatewayLastFound = true;
|
|
return;
|
|
}
|
|
|
|
|
|
abc = () => {
|
|
return hopsOnWay.map(function (hop) {
|
|
return (
|
|
<Text> {hop} --></Text>
|
|
);
|
|
});
|
|
}
|
|
|
|
getAllClients = () => {
|
|
while (changed) {
|
|
changed = false;
|
|
console.log('------------------------');
|
|
tryGetAllClientes();
|
|
}
|
|
|
|
}
|
|
|
|
tryGetAllClientes = () => {
|
|
for (var k3 in dataATT) {
|
|
if (dataATT.hasOwnProperty(k3)) {
|
|
localCloud.map(function (hop) {
|
|
if (dataATT[k3].statistics.gateway_nexthop == hop) {
|
|
|
|
if (!localCloud.includes(dataATT[k3].nodeinfo.node_id)) {
|
|
localCloud.push(dataATT[k3].nodeinfo.node_id);
|
|
changed = true;
|
|
return;
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
countHopsOnWay = () => {
|
|
localCloud.map(function (hop) {
|
|
for (var k4 in dataATT) {
|
|
if (dataATT.hasOwnProperty(k4)) {
|
|
if (dataATT[k4].nodeinfo.node_id == hop) {
|
|
clientsGateway += dataATT[k4].statistics.clients;
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
var tn = currentBSSID;
|
|
var hn = hostName;
|
|
var count = 0;
|
|
var cNodeNr = 0;
|
|
var online = '';
|
|
var contact = '';
|
|
var hopCurrent = '';
|
|
var hopCurrentLocal = '';
|
|
var hopNext = '';
|
|
var hopsOnWay = [];
|
|
var localCloud = [];
|
|
var changed = true;
|
|
var amountHops = 0;
|
|
var clientsLocal = 0;
|
|
var clients = 0;
|
|
var gatewayLastFound = false;
|
|
var clientsGateway = 0;
|
|
hopsOnWay.push(hn);
|
|
for (var k in dataATT) {
|
|
if (dataATT.hasOwnProperty(k)) {
|
|
if (dataATT[k].nodeinfo.hostname === hn) {
|
|
|
|
//setting the current node number:
|
|
cNodeNr = k;
|
|
|
|
//setting contact;
|
|
contact = dataATT[k].nodeinfo.owner.contact;
|
|
|
|
//setting online status:
|
|
if (dataATT[k].flags.online) {
|
|
online = 'online';
|
|
} else {
|
|
online = 'offline';
|
|
}
|
|
|
|
clients = dataATT[k].statistics.clients;
|
|
clientsLocal += clients;
|
|
|
|
hopCurrent = dataATT[k].statistics.gateway;
|
|
hopCurrentLocal = hopCurrent;
|
|
hopNext = dataATT[k].statistics.gateway_nexthop;
|
|
localCloud.push(dataATT[k].nodeinfo.node_id);
|
|
|
|
console.log('Gateway 0: ', dataATT[k].statistics.gateway)
|
|
console.log('Gateway 0: ', dataATT[k].statistics.gateway_nexthop)
|
|
if (hopCurrent === hopNext) {
|
|
console.log('Sie sind direkt mit dem Gateway verbunden');
|
|
gatewayLastFound = true;
|
|
++amountHops;
|
|
}
|
|
hopCurrent = hopNext;
|
|
while (gatewayLastFound != true && amountHops < 10) {
|
|
console.log('gatewayLastFound in while loop: ', gatewayLastFound);
|
|
tryNextHop();
|
|
++amountHops;
|
|
}
|
|
console.log(localCloud);
|
|
getAllClients();
|
|
console.log('/n');
|
|
console.log('HOPS ON WAY // LOCAL CLOUD');
|
|
console.log(hopsOnWay);
|
|
countHopsOnWay();
|
|
console.log(localCloud);
|
|
console.log(currentBSSID);
|
|
|
|
// hopsOnWay.push('gw02.tecff.de');
|
|
}
|
|
++count; //amount of nodes
|
|
|
|
}
|
|
};
|
|
|
|
|
|
return (
|
|
<ScrollView contentContainerStyle={{ alignItems: 'center', justifyContent: 'flex-start', paddingTop: 70, }}>
|
|
|
|
<View style={styles.container2}>
|
|
<View style={styles.viewStyleTwo2}>
|
|
<Text style={styles.headlineText}>{hn}</Text>
|
|
</View>
|
|
</View>
|
|
<View style={styles.container2}>
|
|
<View style={styles.viewStyleOne}>
|
|
<Text style={styles.simpleTextb2}>Status:</Text>
|
|
</View>
|
|
<View style={styles.viewStyleTwo}>
|
|
<Text style={styles.textStyle}>{online}</Text>
|
|
</View>
|
|
</View>
|
|
<View style={styles.container2}>
|
|
<View style={styles.viewStyleOne}>
|
|
<Text style={styles.simpleTextb2}>Amount of nodes:</Text>
|
|
</View>
|
|
<View style={styles.viewStyleTwo}>
|
|
<Text style={styles.textStyle}>{count}</Text>
|
|
</View>
|
|
</View>
|
|
<View style={styles.container2}>
|
|
<View style={styles.viewStyleOne}>
|
|
<Text style={styles.simpleTextb2}>Contact:</Text>
|
|
</View>
|
|
<View style={styles.viewStyleTwo}>
|
|
<Text style={styles.textStyle}>{contact}</Text>
|
|
</View>
|
|
</View>
|
|
<View style={styles.container2}>
|
|
<View style={styles.viewStyleOne}>
|
|
<Text style={styles.simpleTextb2}>Current Node Nr:</Text>
|
|
</View>
|
|
<View style={styles.viewStyleTwo}>
|
|
<Text style={styles.textStyle}>{cNodeNr}</Text>
|
|
</View>
|
|
</View>
|
|
<View style={styles.container2}>
|
|
<View style={styles.viewStyleOne}>
|
|
<Text style={styles.simpleTextb2}>Gateway Hops:</Text>
|
|
</View>
|
|
<View style={styles.viewStyleTwo}>
|
|
<Text style={styles.textStyle}>{amountHops}</Text>
|
|
</View>
|
|
</View>
|
|
<View style={styles.container2}>
|
|
<View style={styles.viewStyleOne}>
|
|
<Text style={styles.simpleTextb2}>Gateways:</Text>
|
|
</View>
|
|
<View style={styles.viewStyleTwo}>
|
|
{abc()}
|
|
<Text> gw02.tecff.de</Text>
|
|
</View>
|
|
</View>
|
|
<View style={styles.container2}>
|
|
<View style={styles.viewStyleOne}>
|
|
<Text style={styles.simpleTextb2}>Clients:</Text>
|
|
</View>
|
|
<View style={styles.viewStyleTwo}>
|
|
<Text style={styles.textStyle}>{clients} Clients are on the current node</Text>
|
|
<Text>{clientsGateway} Clients till gateway</Text>
|
|
</View>
|
|
</View>
|
|
|
|
|
|
</ScrollView>
|
|
);
|
|
}
|
|
}
|
|
|