Skip to content

Commit 417972b

Browse files
committed
Fix up advertisement and blocking.
Upgrade calmclientandserver.
1 parent 6f75bed commit 417972b

File tree

9 files changed

+74
-63
lines changed

9 files changed

+74
-63
lines changed

C-ALM-VOIP/C-ALM-VOIP/AddrBook/AddressableBase.vb

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ Public MustInherit Class AddressableBase
77
Protected _targport As Integer = 0
88
Protected _myaddress As String = ""
99
Protected _myport As Integer = 0
10-
Protected _advaddress As String = ""
11-
Protected _advport As Integer = 0
1210
Protected _type As AddressableType = AddressableType.None
1311
Protected _passmode As MessagePassMode = messagePassMode.Disable
1412
Protected _targver As IPVersion = IPVersion.None
@@ -22,8 +20,6 @@ Public MustInherit Class AddressableBase
2220
_targport = other._targport
2321
_myaddress = other._myaddress
2422
_myport = other._myport
25-
_advaddress = other._advaddress
26-
_advport = other._advport
2723
_type = other._type
2824
_passmode = other._passmode
2925
_targver = other._targver
@@ -81,26 +77,6 @@ Public MustInherit Class AddressableBase
8177
End Set
8278
End Property
8379
<Xml.Serialization.XmlIgnore>
84-
Public Overridable Property advertisedAddress As String
85-
Get
86-
If _advaddress Is Nothing OrElse _advaddress = "" Then Return _myaddress
87-
Return _advaddress
88-
End Get
89-
Set(value As String)
90-
_advaddress = value
91-
End Set
92-
End Property
93-
<Xml.Serialization.XmlIgnore>
94-
Public Overridable Property advertisedPort As Integer
95-
Get
96-
If _advport = 0 Then Return _myport
97-
Return _advport
98-
End Get
99-
Set(value As Integer)
100-
_advport = value
101-
End Set
102-
End Property
103-
<Xml.Serialization.XmlIgnore>
10480
Public Overridable Property type As AddressableType
10581
Get
10682
Return _type

C-ALM-VOIP/C-ALM-VOIP/AddrBook/BlockClient.vb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@ Public Class BlockClient
4343
Set(value As MessagePassMode)
4444
End Set
4545
End Property
46+
47+
Public Overrides Sub sendAdvertisement()
48+
End Sub
4649
End Class

C-ALM-VOIP/C-ALM-VOIP/AddrBook/Client.vb

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Public Class Client
1010
Protected _str As Streamer = Nothing
1111
Protected _cl As NetMarshalBase = Nothing
1212
Protected _lts As DateTime = DateTime.UtcNow
13+
Protected _advaddress As String = ""
14+
Protected _advport As Integer = 0
1315

1416
Public Sub New(other As Contact)
1517
MyBase.New(other)
@@ -24,15 +26,41 @@ Public Class Client
2426
End Sub
2527

2628
Public Overrides Function duplicateToNew() As AddressableBase
27-
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
2835
End Function
2936

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+
3057
Public Overridable Sub forceReceive(msg As IPacket)
3158
Me.msgrec(msg)
3259
End Sub
3360

3461
Protected Overridable Sub msgrec(msg As IPacket)
3562
If _type = AddressableType.Block Or _passmode = voip.MessagePassMode.Disable Or _passmode = voip.MessagePassMode.Send Then Exit Sub
63+
3664
If isForMe(msg) Then
3765
If msg.dataType = GetType(Tuple(Of Byte(), DateTime)) AndAlso isNewerTimeStamp(msg.data) Then
3866
_lts = CType(msg.data, Tuple(Of Byte(), DateTime)).Item2

C-ALM-VOIP/C-ALM-VOIP/AddrBook/Contact.vb

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,6 @@ Public Class Contact
4949
MyBase.targetIPVersion = value
5050
End Set
5151
End Property
52-
<Xml.Serialization.XmlElement(ElementName:="advertisedAddress")>
53-
Public Overridable Property advertisedAddressValue As String
54-
Get
55-
Return _advaddress
56-
End Get
57-
Set(value As String)
58-
_advaddress = value
59-
End Set
60-
End Property
61-
<Xml.Serialization.XmlElement(ElementName:="advertisedPort")>
62-
Public Overridable Property advertisedPortValue As Integer
63-
Get
64-
Return _advport
65-
End Get
66-
Set(value As Integer)
67-
_advport = value
68-
End Set
69-
End Property
7052

7153
Public Overrides Function duplicateToNew() As AddressableBase
7254
Return New Contact(Me)

C-ALM-VOIP/C-ALM-VOIP/Views/Editor.vb

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ Public Class Editor
8080
End While
8181
SyncLock slockchker
8282
'Begin Population
83+
Label7.Text = "My Address:"
84+
Label8.Text = "My Port:"
8385
If ceditm = EditorMode.Create Or ceditm = EditorMode.EditContact Then
8486
cmbxipv.Enabled = True
8587
cmbxtype.Enabled = True
@@ -91,17 +93,16 @@ Public Class Editor
9193
txtbxmyaddr.ReadOnly = False
9294
nudmyport.ReadOnly = False
9395
nudmyport.Controls(0).Enabled = True
94-
If caddrbs.type <> AddressableType.Block Then
95-
If caddrbs.type = AddressableType.UDP Then
96-
txtbxmyaddr.Text = settings.external_Address_IPv4
97-
nudmyport.Value = settings.external_UDP_Port_IPv4
98-
ElseIf caddrbs.type = AddressableType.TCP Then
99-
txtbxmyaddr.Text = settings.external_Address_IPv4
100-
nudmyport.Value = settings.external_TCP_Port_IPv4
101-
End If
96+
If caddrbs.type = AddressableType.UDP Then
97+
txtbxmyaddr.Text = settings.external_Address_IPv4
98+
nudmyport.Value = settings.external_UDP_Port_IPv4
10299
txtbxmyaddr.Enabled = True
103100
nudmyport.Enabled = True
104101
cmbxstrmode.Enabled = True
102+
ElseIf caddrbs.type = AddressableType.TCP Then
103+
txtbxmyaddr.Enabled = False
104+
nudmyport.Enabled = False
105+
cmbxstrmode.Enabled = True
105106
Else
106107
txtbxmyaddr.Enabled = False
107108
nudmyport.Enabled = False
@@ -123,8 +124,15 @@ Public Class Editor
123124
nudport.ReadOnly = True
124125
nudport.Controls(0).Enabled = False
125126
If ceditm = EditorMode.EditClient Then
126-
txtbxmyaddr.Text = caddrbs.advertisedAddress
127-
nudmyport.Value = caddrbs.advertisedPort
127+
If caddrbs.type = AddressableType.TCP And TypeOf caddrbs Is Client Then
128+
Label7.Text = "Actual Address:"
129+
Label8.Text = "Actual Port:"
130+
txtbxmyaddr.Text = CType(caddrbs, Client).advertisedAddress
131+
nudmyport.Value = CType(caddrbs, Client).advertisedPort
132+
Else
133+
txtbxmyaddr.Text = caddrbs.myAddress
134+
nudmyport.Value = caddrbs.myPort
135+
End If
128136
txtbxmyaddr.Enabled = True
129137
nudmyport.Enabled = True
130138
cmbxstrmode.Enabled = True
@@ -255,6 +263,10 @@ Public Class Editor
255263
txtbxmyaddr.Enabled = False
256264
nudmyport.Enabled = False
257265
cmbxstrmode.Enabled = False
266+
ElseIf cmbxtype.SelectedIndex + 1 = AddressableType.TCP And ceditm <> EditorMode.EditClient Then
267+
txtbxmyaddr.Enabled = False
268+
nudmyport.Enabled = False
269+
cmbxstrmode.Enabled = True
258270
Else
259271
txtbxmyaddr.Enabled = True
260272
nudmyport.Enabled = True

C-ALM-VOIP/C-ALM-VOIP/Views/MainProgram.vb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ Public NotInheritable Class MainProgram
296296
clientreg.updateCachedIndices()
297297
If clientreg.selectedIndices.Count > 0 Then
298298
editfin = False
299-
ceditm = EditorMode.EditClient
300299
caddrbs = clientreg(clientreg.selectedIndices(0))
300+
If caddrbs.type = AddressableType.Block Then ceditm = EditorMode.EditBlocker Else ceditm = EditorMode.EditClient
301301
wp.showForm(Of Editor)(0, Me)
302302
While Not editfin
303303
Threading.Thread.Sleep(125)
@@ -491,7 +491,7 @@ Public NotInheritable Class MainProgram
491491
CType(adbIn, Contact).targetAddress = returnFirstItemOrNothing(Of IPAddress)(resolve(adbIn.targetAddress, Net.Sockets.AddressFamily.InterNetwork)).ToString()
492492
End If
493493
End If
494-
If clientreg.find(New MClient(adbIn.targetAddress, adbIn.targetPort)).Length <> 0 Then Return
494+
If clientreg.find(New MClient(adbIn.targetAddress, adbIn.targetPort)).Length <> 0 And adbIn.type <> AddressableType.Block Then Return
495495
If adbIn.type = AddressableType.TCP Then
496496
If adbIn.targetIPVersion = IPVersion.IPv4 And Not tcpmarshalIPv4 Is Nothing Then
497497
Dim tpl As New Tuple(Of String, Integer, String, voip.MessagePassMode)(adbIn.targetAddress, adbIn.targetPort, adbIn.name, adbIn.messagePassMode)
@@ -522,11 +522,16 @@ Public NotInheritable Class MainProgram
522522
End Sub
523523

524524
Private Sub addClient(clIn As Client, forceData As IPacket)
525-
If clientreg.find(New MClient(clIn.targetAddress, clIn.targetPort)).Length = 0 Then
525+
Dim arr As Client() = clientreg.find(New MClient(clIn.targetAddress, clIn.targetPort))
526+
If arr.Length = 0 Then
526527
clIn.sendAdvertisement()
527528
clientreg.add(clIn)
528529
If Not forceData Is Nothing Then clIn.forceReceive(forceData)
529530
If Not clIn.stream Is Nothing Then streamreg.add(clIn.stream)
531+
ElseIf clIn.type = AddressableType.Block Then
532+
For Each c As Client In arr
533+
c.messagePassMode = MessagePassMode.Disable
534+
Next
530535
End If
531536
End Sub
532537

C-ALM-VOIP/C-ALM-VOIP/Views/Parsers/PEditor.vb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ Public Class PEditor
2929
If _caddrbs.type = AddressableType.UDP Then
3030
caddrbs.myAddress = _caddrbs.myAddress
3131
caddrbs.myPort = _caddrbs.myPort
32-
ElseIf _caddrbs.type = AddressableType.TCP Then
33-
caddrbs.advertisedAddress = _caddrbs.advertisedAddress
34-
caddrbs.advertisedPort = _caddrbs.advertisedPort
32+
ElseIf _caddrbs.type = AddressableType.TCP And ceditm = EditorMode.EditClient And TypeOf _caddrbs Is Client Then
33+
CType(caddrbs, Client).advertisedAddress = CType(_caddrbs, Client).advertisedAddress
34+
CType(caddrbs, Client).advertisedPort = CType(_caddrbs, Client).advertisedPort
3535
End If
3636
If ceditm = EditorMode.Create Or ceditm = EditorMode.EditContact Then
3737
CType(caddrbs, Contact).type = _caddrbs.type
@@ -59,8 +59,8 @@ Public Class PEditor
5959
If ceditm <> EditorMode.EditBlocker Then
6060
If _caddrbs.type = AddressableType.UDP Then
6161
_caddrbs.myPort = args.held
62-
ElseIf _caddrbs.type = AddressableType.TCP Then
63-
_caddrbs.advertisedPort = args.held
62+
ElseIf _caddrbs.type = AddressableType.TCP And ceditm = EditorMode.EditClient And TypeOf _caddrbs Is Client Then
63+
CType(_caddrbs, Client).advertisedPort = args.held
6464
End If
6565
End If
6666
ElseIf ev.EventSource.sourceObj Is frm.txtbxaddr And ev.EventType = ETs.Leave Then
@@ -72,8 +72,8 @@ Public Class PEditor
7272
If ceditm <> EditorMode.EditBlocker Then
7373
If _caddrbs.type = AddressableType.UDP Then
7474
_caddrbs.myAddress = args.held
75-
ElseIf _caddrbs.type = AddressableType.TCP Then
76-
_caddrbs.advertisedAddress = args.held
75+
ElseIf _caddrbs.type = AddressableType.TCP And ceditm = EditorMode.EditClient And TypeOf _caddrbs Is Client Then
76+
CType(_caddrbs, Client).advertisedAddress = args.held
7777
End If
7878
End If
7979
ElseIf ev.EventSource.sourceObj Is frm.txtbxname And ev.EventType = ETs.Leave Then
512 Bytes
Binary file not shown.

C-ALM-VOIP/LIBs/calmclientandserver.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ calmclientandserver
226226
<value>Boolean</value>
227227
<returns>Whether length headers are used when passing messages</returns>
228228
<remarks></remarks>
229+
</member><member name="M:captainalm.CALMNetMarshal.NetMarshalTCPClient.releaseCache">
230+
<summary>
231+
Releases the received message cache to the event
232+
</summary>
233+
<remarks></remarks>
229234
</member><member name="T:captainalm.CALMNetMarshal.NetMarshalTCPClient">
230235
<summary>
231236
This class can be retrieved from the NetMarshalTCP and represents a separate client.

0 commit comments

Comments
 (0)