Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
PeerfactSim.KOM
Commits
cff5d31b
Commit
cff5d31b
authored
Sep 19, 2017
by
Björn Richerzhagen
Browse files
Prevent duplicate TransMessageListeners on the same port
parent
679a6f50
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/api/transport/TransProtocol.java
View file @
cff5d31b
...
...
@@ -19,73 +19,61 @@
*/
package
de.tud.kom.p2psim.api.transport
;
/**
* Instances of this type describe the service properties chosen for message
* transmission.
*
* @author Sebastian Kaune
* @author Konstantin Pussep
* @version 3.0, 11/29/2007
*
*/
public
enum
TransProtocol
{
/**
* User Datagram Protocol
*/
UDP
(
false
,
false
,
8
),
/**
* Transmission Control Protocol
*/
TCP
(
true
,
true
,
20
),
package
de.tud.kom.p2psim.api.transport
;
/**
* Instances of this type describe the service properties chosen for message
* transmission.
*
* @author Sebastian Kaune
* @author Konstantin Pussep
* @version 3.0, 11/29/2007
*
*/
public
enum
TransProtocol
{
/**
* Mobile Communication, one hop (this will be changed to UDP/TCP on the
* BaseStation or one of its backbone nodes). Only available, if an
* UMTS-transceiver is configured in the LinkLayer. TODO check Header Size
* User Datagram Protocol
*/
U
MTS
(
true
,
tru
e
,
20
),
U
DP
(
false
,
fals
e
,
8
),
/**
* Bluetooth (this will only allow one-hop communication to short-ranged
* neighbors). Only available, if a BT-transceiver is configured in the
* LinkLayer. TODO check Header Size
* Transmission Control Protocol
*/
BLUETOOTH
(
true
,
true
,
20
);
private
boolean
isConOriented
;
TCP
(
true
,
true
,
20
);
private
boolean
isConOriented
;
private
boolean
isReliable
;
private
int
headerSize
;
private
int
headerSize
;
private
TransProtocol
(
boolean
isConOriented
,
boolean
isReliable
,
int
headerSize
)
{
this
.
isConOriented
=
isConOriented
;
int
headerSize
)
{
this
.
isConOriented
=
isConOriented
;
this
.
isReliable
=
isReliable
;
this
.
headerSize
=
headerSize
;
}
/**
* If the used service is connection-oriented the in-order delivery of
* messages is guaranteed.
*
* @return whether the applied service should be connection-oriented
*/
public
boolean
isConnectionOriented
()
{
return
this
.
isConOriented
;
}
/**
* Whether the used connection is reliable, i.e. the network wrapper tries
* to deliver the message in case of loss or and if the message cannot be
* delivered an exception is reported to the upper layer.
*
* @return whether the applied service should be reliable
*/
public
boolean
isReliable
()
{
return
this
.
isReliable
;
}
this
.
headerSize
=
headerSize
;
}
/**
* If the used service is connection-oriented the in-order delivery of
* messages is guaranteed.
*
* @return whether the applied service should be connection-oriented
*/
public
boolean
isConnectionOriented
()
{
return
this
.
isConOriented
;
}
/**
* Whether the used connection is reliable, i.e. the network wrapper tries
* to deliver the message in case of loss or and if the message cannot be
* delivered an exception is reported to the upper layer.
*
* @return whether the applied service should be reliable
*/
public
boolean
isReliable
()
{
return
this
.
isReliable
;
}
/**
* Size of the headers of this TransMessage in byte.
...
...
@@ -95,5 +83,5 @@ public enum TransProtocol {
public
int
getHeaderSize
()
{
return
this
.
headerSize
;
}
}
}
src/de/tud/kom/p2psim/impl/transport/modular/ITransProtocol.java
View file @
cff5d31b
...
...
@@ -21,6 +21,7 @@
package
de.tud.kom.p2psim.impl.transport.modular
;
import
de.tud.kom.p2psim.api.transport.TransMessage
;
import
de.tud.kom.p2psim.api.transport.TransProtocol
;
import
de.tudarmstadt.maki.simonstrator.api.Message
;
import
de.tudarmstadt.maki.simonstrator.api.component.network.NetID
;
import
de.tudarmstadt.maki.simonstrator.api.component.transport.TransInfo
;
...
...
@@ -63,5 +64,11 @@ public interface ITransProtocol {
* @return
*/
public
int
getHeaderSize
();
/**
* Protocol type of this instance.
* @return
*/
public
TransProtocol
getProtocol
();
}
src/de/tud/kom/p2psim/impl/transport/modular/ModularTransLayer.java
View file @
cff5d31b
...
...
@@ -253,7 +253,7 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
@Override
public
void
setTransportMessageListener
(
TransMessageListener
listener
)
{
this
.
listener
=
listener
;
addTransMsgListener
(
listener
,
localPort
);
addTransMsgListener
(
transport
.
getProtocol
(),
listener
,
localPort
);
}
/*
...
...
@@ -265,7 +265,7 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
Monitor
.
log
(
ModularTransLayer
.
class
,
Level
.
DEBUG
,
"Trying tor remove a non-existing transport message listener."
);
return
;
}
removeTransMsgListener
(
listener
,
localPort
);
removeTransMsgListener
(
transport
.
getProtocol
()
,
localPort
);
listener
=
null
;
}
...
...
@@ -403,18 +403,18 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
}
protected
void
addTransMsgListener
(
TransMessageListener
receiver
,
int
port
)
{
protected
void
addTransMsgListener
(
TransProtocol
protocol
,
TransMessageListener
receiver
,
int
port
)
{
PortListener
pl
=
portListeners
.
get
(
port
);
if
(
pl
==
null
)
{
pl
=
new
PortListener
();
portListeners
.
put
(
port
,
pl
);
}
pl
.
add
Listener
(
receiver
);
pl
.
set
Listener
(
protocol
,
receiver
);
}
protected
void
removeTransMsgListener
(
Trans
MessageListener
listener
,
int
port
)
{
protected
void
removeTransMsgListener
(
Trans
Protocol
protocol
,
int
port
)
{
PortListener
pl
=
portListeners
.
get
(
port
);
pl
.
removeListener
(
listener
);
pl
.
removeListener
(
protocol
);
if
(
pl
.
isEmpty
())
{
portListeners
.
remove
(
port
);
}
...
...
@@ -445,15 +445,12 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
* Notify the Protocol of a received Message
*/
TransMessage
receivedMessage
=
null
;
Class
<?
extends
MessageBasedTransport
>
protocol
=
null
;
if
(
msg
.
getProtocol
()
==
TransProtocol
.
TCP
)
{
receivedMessage
=
tcp
.
get
(
nme
.
getReceiver
()).
receive
(
msg
,
senderInfo
);
protocol
=
UDP
.
class
;
}
else
if
(
msg
.
getProtocol
()
==
TransProtocol
.
UDP
)
{
receivedMessage
=
udp
.
get
(
nme
.
getReceiver
()).
receive
(
msg
,
senderInfo
);
protocol
=
TCPMessageBased
.
class
;
}
else
{
throw
new
AssertionError
(
"No Protocol "
+
msg
.
getProtocol
());
}
...
...
@@ -519,10 +516,10 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
}
}
// deliver real message
pl
.
dispatch
(
pMsg
.
getPayload
(),
p
rotocol
,
senderInfo
,
pl
.
dispatch
(
pMsg
.
getPayload
(),
msg
.
getP
rotocol
()
,
senderInfo
,
receivedMessage
.
getCommId
());
}
else
{
pl
.
dispatch
(
receivedMessage
.
getPayload
(),
p
rotocol
,
pl
.
dispatch
(
receivedMessage
.
getPayload
(),
msg
.
getP
rotocol
()
,
senderInfo
,
receivedMessage
.
getCommId
());
}
}
else
{
...
...
@@ -547,27 +544,34 @@ public class ModularTransLayer implements SimHostComponent, TransportComponent,
*/
public
class
PortListener
{
private
List
<
TransMessageListener
>
transListeners
;
private
Map
<
TransProtocol
,
TransMessageListener
>
transListeners
;
public
PortListener
()
{
transListeners
=
new
Linked
List
<
TransMessageListener
>();
transListeners
=
new
Linked
HashMap
<
TransProtocol
,
TransMessageListener
>();
}
public
void
add
Listener
(
TransMessageListener
listener
)
{
if
(
!
transListeners
.
contains
(
listener
))
{
transListeners
.
add
(
listener
);
public
void
set
Listener
(
TransProtocol
protocol
,
TransMessageListener
listener
)
{
if
(
transListeners
.
contains
Key
(
protocol
))
{
Monitor
.
log
(
ModularTransLayer
.
class
,
Level
.
WARN
,
"Overwriting an existing TransMessageListener for protocol %s."
,
protocol
.
toString
()
);
}
transListeners
.
put
(
protocol
,
listener
);
}
public
void
removeListener
(
TransMessageListener
listener
)
{
transListeners
.
remove
(
listener
);
public
void
removeListener
(
TransProtocol
protocol
)
{
if
(!
transListeners
.
containsKey
(
protocol
))
{
Monitor
.
log
(
ModularTransLayer
.
class
,
Level
.
WARN
,
"Trying to delete an non-existing TransMessageListener for protocol %s."
,
protocol
.
toString
());
}
transListeners
.
remove
(
protocol
);
}
public
<
T
extends
MessageBasedTransport
>
void
dispatch
(
Message
msg
,
Class
<
T
>
protocol
,
TransInfo
sender
,
int
commId
)
{
for
(
TransMessageListener
listener
:
transListeners
)
{
listener
.
messageArrived
(
msg
,
sender
,
commId
);
TransProtocol
protocol
,
TransInfo
sender
,
int
commId
)
{
if
(
transListeners
.
containsKey
(
protocol
))
{
transListeners
.
get
(
protocol
).
messageArrived
(
msg
,
sender
,
commId
);
}
else
{
Monitor
.
log
(
ModularTransLayer
.
class
,
Level
.
WARN
,
"Message arrived, but no TransMessageListener active for %s."
,
protocol
.
toString
());
}
}
public
boolean
isEmpty
()
{
...
...
src/de/tud/kom/p2psim/impl/transport/modular/protocol/TransmissionControlProtocol.java
View file @
cff5d31b
...
...
@@ -129,6 +129,11 @@ public class TransmissionControlProtocol extends AbstractTransProtocol {
public
int
getHeaderSize
()
{
return
20
;
}
@Override
public
TransProtocol
getProtocol
()
{
return
TransProtocol
.
TCP
;
}
@Override
public
void
send
(
Message
msg
,
NetID
receiverNet
,
int
receiverPort
,
...
...
src/de/tud/kom/p2psim/impl/transport/modular/protocol/TransmissionControlProtocolDummy.java
View file @
cff5d31b
...
...
@@ -65,5 +65,10 @@ public class TransmissionControlProtocolDummy extends AbstractTransProtocol {
public
int
getHeaderSize
()
{
return
TransProtocol
.
TCP
.
getHeaderSize
();
}
@Override
public
TransProtocol
getProtocol
()
{
return
TransProtocol
.
TCP
;
}
}
src/de/tud/kom/p2psim/impl/transport/modular/protocol/UserDatagramProtocol.java
View file @
cff5d31b
...
...
@@ -24,6 +24,7 @@ import de.tud.kom.p2psim.api.analyzer.MessageAnalyzer.Reason;
import
de.tud.kom.p2psim.api.common.SimHost
;
import
de.tud.kom.p2psim.api.network.NetProtocol
;
import
de.tud.kom.p2psim.api.network.SimNetInterface
;
import
de.tud.kom.p2psim.api.transport.TransProtocol
;
import
de.tud.kom.p2psim.impl.transport.UDPMessage
;
import
de.tud.kom.p2psim.impl.transport.modular.AbstractTransProtocol
;
import
de.tudarmstadt.maki.simonstrator.api.Message
;
...
...
@@ -65,4 +66,9 @@ public class UserDatagramProtocol extends AbstractTransProtocol {
return
8
;
}
@Override
public
TransProtocol
getProtocol
()
{
return
TransProtocol
.
UDP
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment