@@ -9,33 +9,72 @@ Public Class Client
99
1010 Protected _str As Streamer = Nothing
1111 Protected _cl As NetMarshalBase = Nothing
12- Protected _m As Boolean = False
13- Protected _lts As New Tuple( Of Integer , Integer , Integer )( 0 , 0 , 0 )
12+ Protected _lts As DateTime = DateTime.UtcNow
13+ Protected _advaddress As String = ""
14+ Protected _advport As Integer = 0
15+
16+ Public Sub New (other As Contact)
17+ MyBase .New(other)
18+ End Sub
1419
1520 Public Sub New (other As Contact, client As NetMarshalBase)
1621 MyBase .New(other)
17- 'If other.messagePassMode = voip.MessagePassMode.Bidirectional Or other.messagePassMode = voip.MessagePassMode.Receive Then _
1822 _str = spkVOIP.createStreamer(other.name)
1923 _cl = client
2024 AddHandler _cl.MessageReceived, AddressOf msgrec
2125 AddHandler micVOIP.streamer.dataExgest, AddressOf msgsnd
2226 End Sub
2327
2428 Public Overrides Function duplicateToNew() As AddressableBase
25- Return New Contact( Me )
29+ Dim toret As New Contact( Me .advertisedAddress, Me .advertisedPort, Me .targetIPVersion, Me .type) With {.name = Me .name, .messagePassMode = Me .messagePassMode}
30+ If Me .type = AddressableType.UDP Then
31+ toret.myAddress = Me .myAddress
32+ toret.myPort = Me .myPort
33+ End If
34+ Return toret
2635 End Function
2736
37+ Public Overridable Property advertisedAddress As String
38+ Get
39+ If _advaddress Is Nothing OrElse _advaddress = "" Then Return _targaddress
40+ Return _advaddress
41+ End Get
42+ Set (value As String )
43+ _advaddress = value
44+ End Set
45+ End Property
46+
47+ Public Overridable Property advertisedPort As Integer
48+ Get
49+ If _advport = 0 Then Return _targport
50+ Return _advport
51+ End Get
52+ Set (value As Integer )
53+ _advport = value
54+ End Set
55+ End Property
56+
2857 Public Overridable Sub forceReceive(msg As IPacket)
2958 Me .msgrec(msg)
3059 End Sub
3160
3261 Protected Overridable Sub msgrec(msg As IPacket)
33- If _passmode = voip.MessagePassMode.Disable Or _passmode = voip.MessagePassMode.Send Then Exit Sub
34- If isForMe(msg) And Not _m Then
35- If msg.dataType = GetType (Tuple( Of Byte (), Integer , Integer , Integer )) And isNewerTimeStamp(msg.data) Then
36- _lts = New Tuple( Of Integer , Integer , Integer )( CType (msg.data, Tuple( Of Byte (), Integer , Integer , Integer )).Item2, CType (msg.data, Tuple( Of Byte (), Integer , Integer , Integer )).Item3, CType (msg.data, Tuple( Of Byte (), Integer , Integer , Integer )).Item4)
62+ If _type = AddressableType.Block Or _passmode = voip.MessagePassMode.Disable Or _passmode = voip.MessagePassMode.Send Then Exit Sub
63+
64+ If isForMe(msg) Then
65+ If msg.dataType = GetType (Tuple( Of Byte (), DateTime)) AndAlso isNewerTimeStamp(msg.data) Then
66+ _lts = CType (msg.data, Tuple( Of Byte (), DateTime)).Item2
3767 If Not _str Is Nothing Then _
38- _str.ingestData( CType (msg.data, Tuple( Of Byte (), Integer , Integer , Integer )).Item1, False )
68+ _str.ingestData( CType (msg.data, Tuple( Of Byte (), DateTime)).Item1, False )
69+ ElseIf msg.dataType = GetType (Tuple( Of String , String , Integer )) Then
70+ If settings.setAdvertisedNames Then
71+ Me .name = CType (msg.data, Tuple( Of String , String , Integer )).Item1
72+ Me .updateLVI( True )
73+ If Not _str Is Nothing Then _
74+ _str.updateLVI( True )
75+ End If
76+ Me .advertisedAddress = CType (msg.data, Tuple( Of String , String , Integer )).Item2
77+ Me .advertisedPort = CType (msg.data, Tuple( Of String , String , Integer )).Item3
3978 End If
4079 End If
4180 End Sub
@@ -50,22 +89,39 @@ Public Class Client
5089 End Function
5190
5291 Protected Overridable Sub msgsnd(bts As Byte ())
53- If _passmode = voip.MessagePassMode.Disable Or _passmode = voip.MessagePassMode.Receive Then Exit Sub
92+ If _type = AddressableType.Block Or _passmode = voip.MessagePassMode.Disable Or _passmode = voip.MessagePassMode.Receive Then Exit Sub
5493 Dim ap As AudioPacket = Nothing
5594 If _type = AddressableType.TCP Then
5695 ap = New AudioPacket() With {.bytes = bts, .receiverIP = _cl.duplicatedInternalSocketConfig.remoteIPAddress, .receiverPort = _cl.duplicatedInternalSocketConfig.remotePort, .senderIP = _cl.duplicatedInternalSocketConfig.localIPAddress, .senderPort = _cl.duplicatedInternalSocketConfig.localPort}
5796 ElseIf _type = AddressableType.UDP Then
5897 ap = New AudioPacket() With {.bytes = bts, .receiverIP = _targaddress, .receiverPort = _targport, .senderIP = _myaddress, .senderPort = _myport}
5998 End If
60- Dim ts As Tuple( Of Integer , Integer , Integer ) = generateTimestamp()
61- ap.year = ts.Item1
62- ap.day = ts.Item2
63- ap.millisecond = ts.Item3
99+ ap.timestamp = DateTime.UtcNow
100+ _cl.sendMessage(ap)
101+ End Sub
102+
103+ Public Overridable Sub sendAdvertisement()
104+ If _type = AddressableType.Block Or _passmode = voip.MessagePassMode.Disable Or _passmode = voip.MessagePassMode.Receive Then Exit Sub
105+ Dim ap As AdvPacket = Nothing
106+ If _type = AddressableType.TCP Then
107+ If _targver = IPVersion.IPv6 Then
108+ ap = New AdvPacket() With {.advName = settings.myName, .advIP = settings.external_Address_IPv6, .advPort = settings.external_TCP_Port_IPv6, .receiverIP = _cl.duplicatedInternalSocketConfig.remoteIPAddress, .receiverPort = _cl.duplicatedInternalSocketConfig.remotePort, .senderIP = _cl.duplicatedInternalSocketConfig.localIPAddress, .senderPort = _cl.duplicatedInternalSocketConfig.localPort}
109+ Else
110+ ap = New AdvPacket() With {.advName = settings.myName, .advIP = settings.external_Address_IPv4, .advPort = settings.external_TCP_Port_IPv4, .receiverIP = _cl.duplicatedInternalSocketConfig.remoteIPAddress, .receiverPort = _cl.duplicatedInternalSocketConfig.remotePort, .senderIP = _cl.duplicatedInternalSocketConfig.localIPAddress, .senderPort = _cl.duplicatedInternalSocketConfig.localPort}
111+ End If
112+ ElseIf _type = AddressableType.UDP Then
113+ If _targver = IPVersion.IPv6 Then
114+ ap = New AdvPacket() With {.advName = settings.myName, .advIP = settings.external_Address_IPv6, .advPort = settings.external_UDP_Port_IPv6, .receiverIP = _targaddress, .receiverPort = _targport, .senderIP = _myaddress, .senderPort = _myport}
115+ Else
116+ ap = New AdvPacket() With {.advName = settings.myName, .advIP = settings.external_Address_IPv4, .advPort = settings.external_UDP_Port_IPv4, .receiverIP = _targaddress, .receiverPort = _targport, .senderIP = _myaddress, .senderPort = _myport}
117+ End If
118+ End If
64119 _cl.sendMessage(ap)
65120 End Sub
66121
67122 Public Overridable ReadOnly Property connected As Boolean
68123 Get
124+ If _cl Is Nothing Then Return False
69125 Return _cl.ready
70126 End Get
71127 End Property
@@ -160,30 +216,12 @@ Public Class Client
160216 End Get
161217 End Property
162218
163- Protected Overridable Function generateTimestamp() As Tuple( Of Integer , Integer , Integer )
164- Dim toret As New Tuple( Of Integer , Integer , Integer )(DateTime.Now.Year, DateTime.Now.DayOfYear, (DateTime.Now.Hour * 3600000 ) + (DateTime.Now.Minute * 60000 ) + (DateTime.Now.Second * 1000 ) + DateTime.Now.Millisecond)
165- Return toret
219+ Protected Overridable Function isNewerTimeStamp(tstchk As Tuple( Of Byte (), DateTime)) As Boolean
220+ Return tstchk.Item2 > _lts
166221 End Function
167222
168- Protected Overridable Function isNewerTimeStamp(tstchk As Tuple( Of Byte (), Integer , Integer , Integer )) As Boolean
169- If tstchk.Item2 > _lts.Item1 Then
170- Return True
171- ElseIf tstchk.Item2 < _lts.Item1 Then
172- Return False
173- Else
174- If tstchk.Item3 > _lts.Item2 Then
175- Return True
176- ElseIf tstchk.Item3 < _lts.Item2 Then
177- Return False
178- Else
179- If tstchk.Item4 > _lts.Item3 Then
180- Return True
181- ElseIf tstchk.Item4 < _lts.Item3 Then
182- Return False
183- Else
184- Return False
185- End If
186- End If
187- End If
188- End Function
223+ Protected Overrides Sub updateLVIActual(u As Boolean )
224+ MyBase .updateLVIActual( False )
225+ If _lvi.SubItems.Count < 5 Then _lvi.SubItems.Add( Me .connected) Else _lvi.SubItems( 4 ).Text = Me .connected
226+ End Sub
189227End Class
0 commit comments