Skip to content

Commit 7b44a34

Browse files
authored
Merge pull request #6 from Captain-ALM/0.0.1.x
0.0.1.0
2 parents bb3e0c8 + 417972b commit 7b44a34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+28028
-1959
lines changed

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

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<Serializable>
22
Public MustInherit Class AddressableBase
3+
Implements IListViewable
4+
35
Protected _name As String = ""
46
Protected _targaddress As String = ""
57
Protected _targport As Integer = 0
@@ -8,6 +10,9 @@ Public MustInherit Class AddressableBase
810
Protected _type As AddressableType = AddressableType.None
911
Protected _passmode As MessagePassMode = messagePassMode.Disable
1012
Protected _targver As IPVersion = IPVersion.None
13+
Protected _lvi As ListViewItem = Nothing
14+
<NonSerialized>
15+
Protected slocklvi As New Object()
1116

1217
Public Sub New(other As AddressableBase)
1318
_name = other._name
@@ -20,11 +25,10 @@ Public MustInherit Class AddressableBase
2025
_targver = other._targver
2126
End Sub
2227

23-
Public Sub New(targAddress As String, targPort As Integer, aType As AddressableType, mpMode As MessagePassMode, targVer As IPVersion)
28+
Public Sub New(targAddress As String, targPort As Integer, targVer As IPVersion, aType As AddressableType)
2429
_targaddress = targAddress
2530
_targport = targPort
2631
_type = aType
27-
_passmode = mpMode
2832
_targver = targVer
2933
End Sub
3034

@@ -36,7 +40,7 @@ Public MustInherit Class AddressableBase
3640
_name = value
3741
End Set
3842
End Property
39-
43+
<Xml.Serialization.XmlIgnore>
4044
Public Overridable Property targetAddress As String
4145
Get
4246
Return _targaddress
@@ -45,7 +49,7 @@ Public MustInherit Class AddressableBase
4549
_targaddress = value
4650
End Set
4751
End Property
48-
52+
<Xml.Serialization.XmlIgnore>
4953
Public Overridable Property targetPort As Integer
5054
Get
5155
Return _targport
@@ -72,7 +76,7 @@ Public MustInherit Class AddressableBase
7276
_myport = value
7377
End Set
7478
End Property
75-
79+
<Xml.Serialization.XmlIgnore>
7680
Public Overridable Property type As AddressableType
7781
Get
7882
Return _type
@@ -81,7 +85,7 @@ Public MustInherit Class AddressableBase
8185
_type = value
8286
End Set
8387
End Property
84-
88+
<Xml.Serialization.XmlIgnore>
8589
Public Overridable Property targetIPVersion As IPVersion
8690
Get
8791
Return _targver
@@ -95,18 +99,50 @@ Public MustInherit Class AddressableBase
9599
Get
96100
Return _passmode
97101
End Get
98-
Protected Set(value As MessagePassMode)
102+
Set(value As MessagePassMode)
99103
_passmode = value
100104
End Set
101105
End Property
102106

103107
Public MustOverride Function duplicateToNew() As AddressableBase
108+
109+
Public Overridable Sub updateLVI(u As Boolean) Implements IListViewable.updateItem
110+
SyncLock slocklvi
111+
If (Not _lvi Is Nothing) AndAlso (Not _lvi.ListView Is Nothing) AndAlso _lvi.ListView.InvokeRequired Then
112+
_lvi.ListView.Invoke(Sub() updateLVIActual(u))
113+
Else
114+
updateLVIActual(u)
115+
End If
116+
End SyncLock
117+
End Sub
118+
119+
Protected Overridable Sub updateLVIActual(u As Boolean)
120+
If _lvi Is Nothing Then _lvi = New ListViewItem(_name) Else _lvi.Text = name
121+
If _lvi.SubItems.Count < 2 Then _lvi.SubItems.Add(_targaddress) Else _lvi.SubItems(1).Text = _targaddress
122+
If _lvi.SubItems.Count < 3 Then _lvi.SubItems.Add(_targport) Else _lvi.SubItems(2).Text = _targport
123+
If _lvi.SubItems.Count < 4 Then _lvi.SubItems.Add(_type.ToString()) Else _lvi.SubItems(3).Text = _type.ToString()
124+
End Sub
125+
126+
Public ReadOnly Property item As ListViewItem Implements IListViewable.item
127+
Get
128+
SyncLock slocklvi
129+
Return _lvi
130+
End SyncLock
131+
End Get
132+
End Property
133+
134+
Public Sub cleanItem() Implements IListViewable.cleanItem
135+
SyncLock slocklvi
136+
_lvi = Nothing
137+
End SyncLock
138+
End Sub
104139
End Class
105140

106141
Public Enum AddressableType As Integer
107142
None = 0
108143
TCP = 1
109144
UDP = 2
145+
Block = 3
110146
End Enum
111147

112148
Public Enum MessagePassMode As Integer
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Imports captainalm.CALMNetMarshal
2+
3+
Public Class BlockClient
4+
Inherits Client
5+
6+
Public Sub New(other As Contact)
7+
MyBase.New(other)
8+
End Sub
9+
10+
Public Sub New(other As Contact, targIp As String)
11+
MyBase.New(other)
12+
_targaddress = targIp
13+
End Sub
14+
15+
Public Overrides Sub forceReceive(msg As IPacket)
16+
End Sub
17+
18+
Public Overrides ReadOnly Property connected As Boolean
19+
Get
20+
Return True
21+
End Get
22+
End Property
23+
24+
Public Overrides Sub [stop]()
25+
End Sub
26+
27+
Public Overrides ReadOnly Property marshal As NetMarshalBase
28+
Get
29+
Return Nothing
30+
End Get
31+
End Property
32+
33+
Public Overrides ReadOnly Property stream As Streamer
34+
Get
35+
Return Nothing
36+
End Get
37+
End Property
38+
39+
Public Overrides Property messagePassMode As MessagePassMode
40+
Get
41+
Return voip.MessagePassMode.Disable
42+
End Get
43+
Set(value As MessagePassMode)
44+
End Set
45+
End Property
46+
47+
Public Overrides Sub sendAdvertisement()
48+
End Sub
49+
End Class

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

Lines changed: 76 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -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
189227
End Class

0 commit comments

Comments
 (0)