Let the GUI handle the new dump format.
authorGuus Sliepen <guus@tinc-vpn.org>
Thu, 27 Sep 2012 20:12:15 +0000 (22:12 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Thu, 27 Sep 2012 20:12:15 +0000 (22:12 +0200)
gui/tinc-gui

index 1d8d1f1..89a8afa 100755 (executable)
@@ -23,6 +23,7 @@ import wx
 import sys
 import os
 import platform
 import sys
 import os
 import platform
+import time
 from wx.lib.mixins.listctrl import ColumnSorterMixin
 from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin
 
 from wx.lib.mixins.listctrl import ColumnSorterMixin
 from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin
 
@@ -52,34 +53,32 @@ CONTROL = 18
 class Node:
        def parse(self, args):
                self.name = args[0]
 class Node:
        def parse(self, args):
                self.name = args[0]
-               self.address = args[2]
-               if args[3] != 'port':
-                       args.insert(3, 'port')
-                       args.insert(4, '')
-               self.port = args[4]
-               self.cipher = int(args[6])
-               self.digest = int(args[8])
-               self.maclength = int(args[10])
-               self.compression = int(args[12])
-               self.options = int(args[14], 0x10)
-               self.status = int(args[16], 0x10)
-               self.nexthop = args[18]
-               self.via = args[20]
-               self.distance = int(args[22])
-               self.pmtu = int(args[24])
-               self.minmtu = int(args[26])
-               self.maxmtu = int(args[28][:-1])
+               self.address = args[1]
+               self.port = args[3]
+               self.cipher = int(args[4])
+               self.digest = int(args[5])
+               self.maclength = int(args[6])
+               self.compression = int(args[7])
+               self.options = int(args[8], 0x10)
+               self.status = int(args[9], 0x10)
+               self.nexthop = args[10]
+               self.via = args[11]
+               self.distance = int(args[12])
+               self.pmtu = int(args[13])
+               self.minmtu = int(args[14])
+               self.maxmtu = int(args[15])
+               self.last_state_change = float(args[16])
 
                self.subnets = {}
 
 class Edge:
        def parse(self, args):
                self.fr = args[0]
 
                self.subnets = {}
 
 class Edge:
        def parse(self, args):
                self.fr = args[0]
-               self.to = args[2]
-               self.address = args[4]
-               self.port = args[6]
-               self.options = int(args[8], 16)
-               self.weight = int(args[10])
+               self.to = args[1]
+               self.address = args[2]
+               self.port = args[4]
+               self.options = int(args[5], 16)
+               self.weight = int(args[6])
 
 class Subnet:
        def parse(self, args):
 
 class Subnet:
        def parse(self, args):
@@ -95,19 +94,16 @@ class Subnet:
                        self.address = address
                        self.prefixlen = '48'
 
                        self.address = address
                        self.prefixlen = '48'
 
-               self.owner = args[2]    
+               self.owner = args[1]    
 
 class Connection:
        def parse(self, args):
                self.name = args[0]
 
 class Connection:
        def parse(self, args):
                self.name = args[0]
-               self.address = args[2]
-               if args[3] != 'port':
-                       args.insert(3, 'port')
-                       args.insert(4, '')
-               self.port = args[4]
-               self.options = int(args[6], 0x10)
-               self.socket = int(args[8])
-               self.status = int(args[10], 0x10)
+               self.address = args[1]
+               self.port = args[3]
+               self.options = int(args[4], 0x10)
+               self.socket = int(args[5])
+               self.status = int(args[6], 0x10)
                self.weight = 123
 
 class VPN:
                self.weight = 123
 
 class VPN:
@@ -154,34 +150,34 @@ class VPN:
                        if resp[0] != '18':
                                break
                        if resp[1] == '3':
                        if resp[0] != '18':
                                break
                        if resp[1] == '3':
-                               if len(resp) < 3:
+                               if len(resp) < 19:
                                        continue
                                node = self.nodes.get(resp[2]) or Node()
                                node.parse(resp[2:])
                                node.visited = True
                                self.nodes[resp[2]] = node
                        elif resp[1] == '4':
                                        continue
                                node = self.nodes.get(resp[2]) or Node()
                                node.parse(resp[2:])
                                node.visited = True
                                self.nodes[resp[2]] = node
                        elif resp[1] == '4':
-                               if len(resp) < 5:
+                               if len(resp) < 9:
                                        continue
                                        continue
-                               edge = self.nodes.get((resp[2], resp[4])) or Edge()
+                               edge = self.nodes.get((resp[2], resp[3])) or Edge()
                                edge.parse(resp[2:])
                                edge.visited = True
                                edge.parse(resp[2:])
                                edge.visited = True
-                               self.edges[(resp[2], resp[4])] = edge
+                               self.edges[(resp[2], resp[3])] = edge
                        elif resp[1] == '5':
                        elif resp[1] == '5':
-                               if len(resp) < 5:
+                               if len(resp) < 4:
                                        continue
                                        continue
-                               subnet = self.subnets.get((resp[2], resp[4])) or Subnet()
+                               subnet = self.subnets.get((resp[2], resp[3])) or Subnet()
                                subnet.parse(resp[2:])
                                subnet.visited = True
                                subnet.parse(resp[2:])
                                subnet.visited = True
-                               self.subnets[(resp[2], resp[4])] = subnet
+                               self.subnets[(resp[2], resp[3])] = subnet
                                self.nodes[subnet.owner].subnets[resp[2]] = subnet
                        elif resp[1] == '6':
                                self.nodes[subnet.owner].subnets[resp[2]] = subnet
                        elif resp[1] == '6':
-                               if len(resp) < 5:
+                               if len(resp) < 9:
                                        break
                                        break
-                               connection = self.connections.get((resp[2], resp[4])) or Connection()
+                               connection = self.connections.get((resp[2], resp[3], resp[5])) or Connection()
                                connection.parse(resp[2:])
                                connection.visited = True
                                connection.parse(resp[2:])
                                connection.visited = True
-                               self.connections[(resp[2], resp[4])] = connection
+                               self.connections[(resp[2], resp[3], resp[5])] = connection
                        else:
                                break
 
                        else:
                                break
 
@@ -401,6 +397,7 @@ class NodesPage(wx.Panel):
                self.list.InsertColumn(12, 'PMTU')
                self.list.InsertColumn(13, 'Min MTU')
                self.list.InsertColumn(14, 'Max MTU')
                self.list.InsertColumn(12, 'PMTU')
                self.list.InsertColumn(13, 'Min MTU')
                self.list.InsertColumn(14, 'Max MTU')
+               self.list.InsertColumn(15, 'Since')
 
                hbox = wx.BoxSizer(wx.HORIZONTAL)
                hbox.Add(self.list, 1, wx.EXPAND)
 
                hbox = wx.BoxSizer(wx.HORIZONTAL)
                hbox.Add(self.list, 1, wx.EXPAND)
@@ -422,14 +419,19 @@ class NodesPage(wx.Panel):
                        self.list.SetStringItem(i,  4, str(node.digest))
                        self.list.SetStringItem(i,  5, str(node.maclength))
                        self.list.SetStringItem(i,  6, str(node.compression))
                        self.list.SetStringItem(i,  4, str(node.digest))
                        self.list.SetStringItem(i,  5, str(node.maclength))
                        self.list.SetStringItem(i,  6, str(node.compression))
-                       self.list.SetStringItem(i,  7, str(node.options))
-                       self.list.SetStringItem(i,  8, str(node.status))
+                       self.list.SetStringItem(i,  7, format(node.options, "x"))
+                       self.list.SetStringItem(i,  8, format(node.status, "04x"))
                        self.list.SetStringItem(i,  9, node.nexthop)
                        self.list.SetStringItem(i, 10, node.via)
                        self.list.SetStringItem(i, 11, str(node.distance))
                        self.list.SetStringItem(i, 12, str(node.pmtu))
                        self.list.SetStringItem(i, 13, str(node.minmtu))
                        self.list.SetStringItem(i, 14, str(node.maxmtu))
                        self.list.SetStringItem(i,  9, node.nexthop)
                        self.list.SetStringItem(i, 10, node.via)
                        self.list.SetStringItem(i, 11, str(node.distance))
                        self.list.SetStringItem(i, 12, str(node.pmtu))
                        self.list.SetStringItem(i, 13, str(node.minmtu))
                        self.list.SetStringItem(i, 14, str(node.maxmtu))
+                       if node.last_state_change:
+                               since = time.strftime("%Y-%m-%d %H:%M", time.localtime(node.last_state_change))
+                       else:
+                               since = "never"
+                       self.list.SetStringItem(i, 15, since)
                        self.list.itemDataMap[i] = (node.name, node.address, node.port, node.cipher, node.digest, node.maclength, node.compression, node.options, node.status, node.nexthop, node.via, node.distance, node.pmtu, node.minmtu, node.maxmtu)
                        self.list.SetItemData(i, i)
                        i += 1
                        self.list.itemDataMap[i] = (node.name, node.address, node.port, node.cipher, node.digest, node.maclength, node.compression, node.options, node.status, node.nexthop, node.via, node.distance, node.pmtu, node.minmtu, node.maxmtu)
                        self.list.SetItemData(i, i)
                        i += 1
@@ -465,7 +467,7 @@ class EdgesPage(wx.Panel):
                        self.list.SetStringItem(i, 1, edge.to)
                        self.list.SetStringItem(i, 2, edge.address)
                        self.list.SetStringItem(i, 3, edge.port)
                        self.list.SetStringItem(i, 1, edge.to)
                        self.list.SetStringItem(i, 2, edge.address)
                        self.list.SetStringItem(i, 3, edge.port)
-                       self.list.SetStringItem(i, 4, str(edge.options))
+                       self.list.SetStringItem(i, 4, format(edge.options, "x"))
                        self.list.SetStringItem(i, 5, str(edge.weight))
                        self.list.itemDataMap[i] = (edge.fr, edge.to, edge.address, edge.port, edge.options, edge.weight)
                        i += 1
                        self.list.SetStringItem(i, 5, str(edge.weight))
                        self.list.itemDataMap[i] = (edge.fr, edge.to, edge.address, edge.port, edge.options, edge.weight)
                        i += 1