1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-04 23:55:58 +01:00
Commit graph

102 commits

Author SHA1 Message Date
Florian Schmaus
dabbb40de6 Fix isSmResumptionPossible() returning wrong values
The cases where reversed. Change the condition for better readability.

Also fix int and long handling in the computation of
maxResumptionMillies.

Fixes SMACK-654.
2015-04-07 08:51:03 +02:00
Florian Schmaus
3b6891b0d0 Fix integer overflow if no max resumption time
is specified by client and server.

Fixes SMACK-653.
2015-04-07 08:51:03 +02:00
Florian Schmaus
5e86db4f80 Substitute 'packet' with 'stanza(/packet)' in javadoc 2015-03-21 09:36:28 +01:00
Florian Schmaus
92c76d1023 Only reset smSessionId if the stream is no longer resumeable 2015-03-10 13:17:18 +01:00
Florian Schmaus
ed4fa3390f Add XMPPConnection.sendStanza(Stanza)
and deprecate sendPacket().
2015-03-04 21:46:44 +01:00
Florian Schmaus
96bb37f924 Fix counting bug Stream Management implementation
Previously Smack would put messages in the unacknowledgedStanzas queue
after it received the 'enabled' element, when it should do so right
after sending the 'enable' stream element.

Imagine a session where '-->' denotes "received from server" and '<--'
"sent to server"

<-- enable
--> iq roster push set
--> presence some presence
<-- iq roster push result
--> enabled

then Smack would not add the iq roster push result stanza to the
unacknowledgedStanzas queue.

This fixes the issue by initializing the unacknowledgedStanzas queue
when the writer thread encounters a 'Enable' stream element.

The additional 'instanceof' invocation in the writer thread should not
be a big performance issue, since the existing "instanceof Stanza" check
should be the common case and the "instanceof Enable" is an exclusive
alternative to this case.
2015-03-02 16:17:47 +01:00
Florian Schmaus
75ec271c6c Rename PacketListener to StanzaListener
and add the PacketListener as deprecated interface.
2015-03-02 15:49:56 +01:00
Florian Schmaus
d4a6d8e653 Rename PacketFilter (and implementing classes) and PacketExtension
to StanzaFilter and ExtensionElement.
2015-02-28 13:49:38 +01:00
Florian Schmaus
4b7a396b9b Improve logging wrt XMPPTCPConnection.shutdownDone 2015-02-26 08:27:19 +01:00
Florian Schmaus
90969e252a Improve the bundle and defer mechanism
Instead of always bundling when the queue is empty, only bundle once the
queue has become empty and then only if it has been become empty again.

The previous algorithm would also bundle and defer the last element
found in the queue. This is not the case now.
2015-02-22 10:51:44 +01:00
Florian Schmaus
8b0ccd7420 Minor javadoc fixes and improvements 2015-02-22 10:41:53 +01:00
Florian Schmaus
bfcb403673 Fix Stream Management ack listner invocation
aborting to early, because of a 'return' statement, when 'continue'
should be used.

Thanks to Daniele Ricci for reporting this bug.
2015-02-19 23:01:38 +01:00
Florian Schmaus
5f4374ec26 Use host(name) to construct the SSLSocket
in XMPPTCPConnection.

So that the hostname and not the IP is available to the SSLSocket and
the SSLSession, which handed over to HostnameVerifier. This leaves the
HostnameVerifier with the

- name of the XMPP service (first argument of verify(String, SSLSession)
- name of the used host (found in the SSLSession)

allowing more complex verification mechanisms performed by the
HostnameVerifier.
2015-02-19 12:14:16 +01:00
Florian Schmaus
d415661e35 Add BundleAndDeferCallback to smack-tcp 2015-02-19 12:14:10 +01:00
Florian Schmaus
aa8daba1cf Add StreamManagemtCounterError
to allow graceful connectionClosedOnError() disconnects, since we
received a bunch of reports where the counter seems wrong, which is
causing a NPE in a thread pool executor, causing the VM or Android App
to terminate.

Now we throw the StreamManagementCounterError instead.
2015-02-18 12:07:44 +01:00
Florian Schmaus
7897fca876 Add comment about Stream Management's unacked stanzas queue 2015-02-18 11:59:45 +01:00
Florian Schmaus
57c1b57b7c s/ a XMPP/ an XMPP/ 2015-02-12 12:13:19 +01:00
Florian Schmaus
96e3d5c533 Add XMPPTCPConnection(CharSequence, String) constructor 2015-02-09 07:35:16 +01:00
Florian Schmaus
1630b44b8d Reset smSessionId on XMPPTCPConnection.disconnect() 2015-02-09 07:35:15 +01:00
Florian Schmaus
3b8f4c144e Add missing space in log statement within XMPPTCPConnection 2015-02-09 07:35:15 +01:00
Florian Schmaus
4698805a34 Rename 'Packet' class to 'Stanza'
Smack still uses the term 'Packet' in some places. This is just the
first step towards using correct XMPP terms in Smack.
2015-02-06 09:34:51 +01:00
Florian Schmaus
5a56ff011b Add XMPPConnection.getStreamId()
and remove getConnectionID().

Also make streamId a field of AbstractXMPPConnection. Most XMPP
connection types have a streamId, it appears to be optional when BOSH
is used though.
2015-01-28 17:14:33 +01:00
Florian Schmaus
612ca1ad9d Use CharSequence instead of String for username
in XMPPTCPConnection's constructor.
2015-01-28 09:34:01 +01:00
Florian Schmaus
37081b2810 Send more information with the stream open tag 2015-01-28 09:31:28 +01:00
Florian Schmaus
780872f2ef Remove superflous throwAlreadyConnected…Exception
in XMPPTCPConnection. connectInternal() is only called by
AbstractXMPPConnection.connect() which does already invoke this method.
2015-01-26 07:54:12 +01:00
Florian Schmaus
4b10f36e9e Report failed DNS SRV lookup in ConnectionException
instead of just logging a warning if the XMPP domain has no DNS SRV
lookups, create the failedAddresses list now within DNSUtil and add the
information that the SRV lookup failed.
2015-01-26 07:54:12 +01:00
Florian Schmaus
30ec2bd072 Cleanup XMPPTCPConnection, mostly exception handling
In initConnection, only initReaderAndWriter() throws IOException.

connectUsingConfiguration doesn't need to take an argument.

PacketReader.init does not throw a SmackException.

Use Async.go() in PacketWriter, just like it's already done in PacketReader.
2015-01-26 07:54:12 +01:00
Florian Schmaus
d9c97fabfb Make connectUsingConfiguration more robust
If 'return' is not reached, then always throw a
ConnectionException.

Also make it clear that populateHostAddresses adds at least one address.
2015-01-26 07:54:11 +01:00
Florian Schmaus
4c218c96f6 Move Stream Management code into o.j.smack.sm
from o.jsmack.tcp.sm, as XEP-198 Stream Management is not an "XMPP over
TCP" exclusive feature. It could also be use together with the Websocket
binding of XMPP, so we may have a smack-streammangement in the
future. This change prepares for that by moving the SM code out of the
XMPP TCP package namespace.
2015-01-18 11:07:47 +01:00
Florian Schmaus
6d7f3904d9 Throw NotConnectedException on login()
if connect() was not previously called. Previously calling login() with
arguments would not check for the preconditions.

The check to throw needs to be performed in AbstractXMPPConnection
before every 'abstract login(Non)Anonymously()' call. That's the two
lines that check the preconditions are duplicated.

Also fix NPE in
XMPPTCPConnection.throwNotConnectedExceptionIfAppropriate() when
packetWrite is null (i.e. if the connection was never connected before).
2015-01-17 17:53:36 +01:00
Florian Schmaus
75fd1683d1 Fix stanzaIdAcknowledgedListeners not being called
Replace isNotEmpty(id) with isNullOrEmpty(id)
2015-01-17 14:11:21 +01:00
Florian Schmaus
2ea469be10 Add javadoc to XMPPTCPConnectionConfiguration 2015-01-17 10:34:37 +01:00
Florian Schmaus
d099e7b16d Improve handling of InterruptedException
InterruptedExceptions should be treated as the users intention to
'cancel' the current thread's task. There is no such thing as a
spurious interrupt (not to be confused with "spurious wakeups").
2015-01-16 17:31:10 +01:00
Florian Schmaus
106512d8d4 Assure stanzaIdAcknowledgedListeners are removed
after at most 12 hours.

Also set a keep alive time for the removeCallbacksService to 30 seconds
and add AbstractXMPPConnection.schedule(Runnable, long, TimeUnit).
2015-01-15 21:36:23 +01:00
Florian Schmaus
6209d75536 Add XMPPTCPConnection.getMaxSmResumptionTime()
Note that the logic determining the max resumption time has changed,
Math.min() is now used instead of Math.max(). This should match the real
life situation, e.g. if the server announced a max resumption time of 10
minutes and the client one of 5, then it should be assumed that the
connection/stream state is dropped by the parties after 5 minutes.
2015-01-15 21:33:44 +01:00
Florian Schmaus
04d47b2dda Use Asyn.go() to create and start reader thread
in XMPPTCPConnection.
2015-01-15 18:36:35 +01:00
Florian Schmaus
ed84b4a8b3 Add javadoc to and fix typo in XMPPTCPConnection 2015-01-15 18:36:35 +01:00
Florian Schmaus
3582de0654 Fix initializing clientHandledStanzasCount
From XEP-198: Stream Management § 4. Acks:

"""
Note: There are two values of 'h' for any given stream: one maintained
by the client to keep track of stanzas it has handled from the server,
and one maintained by the server to keep track of stanzas it has handled
from the client. The client initializes its value to zero when it sends
<enable/> to the server, and the server initializes its value to zero
when it sends <enabled/> to the client (it is expected that the server
will respond immediately to <enable/> and set its counter to zero at
that time).
"""

Previously smack initialized both to 0 just before sending enabled. But
according to the note from XEP-198 the server's counter is initialized
by the server "when it sends <enabled/> to the client, so we need to set
clientHandledStanzasCount to 0 when we receive <enabled/>. Because the
server started counted right after he send <enabled/>.

Thanks to Kim "zash" Alvefur for pointing this out.
2015-01-15 18:36:08 +01:00
Florian Schmaus
3187436ba7 Throw exception if END_DOCUMENT is seen
instead of calling just instantShutdown(). Now we will catch this
exception, call notifyConnectionError which also calls
instantShutdown() but also notifies the connection listeners of the
event.

Smack should never all instantShutdown() without notifying the
connection listeners.
2015-01-14 17:07:35 +01:00
Florian Schmaus
2aaedcb2fd Improve stanza ack listener handling
- Don't abort if there is a NotConnectedExceptions, other listeners may
  want to be informed of the ack nevertheless.
- Simply return if the id is null or empty.
2015-01-13 13:31:45 +01:00
Florian Schmaus
24b940138f Improve XMPPTCPConnection.processHandledCount(long)
Add shortcut: If stanzaAcknowledgedListeners is not empty, then we don't
need to check the stanzaIdAcknowledgedListeners.

Also fixes a bug, instead of

if (id != null && stanzaAcknowledgedListeners.contains(id)) {

it must be

if (id != null && stanzaIdAcknowledgedListeners.containsKey(id)) {
2015-01-13 13:31:45 +01:00
Florian Schmaus
07539820c3 Make addStanzaAck…Listener() not throw
users may want to add listeners before the connection is connected. The
comment was also wrong, those listeners never got auto removed.
2015-01-13 13:31:45 +01:00
Florian Schmaus
b0cecee710 Rename IQ.ELEMENT to IQ.IQ_ELEMENT
to avoid confusion between the IQ element 'iq' and the IQs child
element. ELEMENT defined in an IQ sublcass should contain the *child*
element.

Add element to StreamInitation and fix FileTransferManager which still
used a packet listener instead of an IQ request handler to handle
incoming stream initiation requests.
2015-01-11 21:54:46 +01:00
Florian Schmaus
67c0a7089b Move notifyReconnection in AbstractXMPPConnection 2015-01-07 20:11:01 +01:00
Florian Schmaus
f6144c553c Try all Inet Addresses of the host when connecting
instead of the first resolved one.

Also some small refactorizations (e.g. getSocketFactory())
2015-01-07 14:35:23 +01:00
Florian Schmaus
717090d272 Rework incoming packet listeners and Roster
Differentiate between asynchronous and synchronous ones. Asynchronous
are the ones where the invocation order may not be the same as the order
in which the stanzas arrived.

Since it's no longer guaranteed that when a unit test calls

processPacket(stanza)

the stanza will be completely processed when the call returns, it was
necessary to extend the unit tests (mostly Roster and ChatManager) with
a packet listener that waits for his invocation. Since we now also use
LinkedHashMaps as Map for the packet listeners (SMACK-531, SMACK-424),
adding a packet listeners as last also means that it will be called as
last. We exploit this behavior change now in the unit tests.

Rename 'recvListeners' to 'syncRecvListeners' in AbstractXMPPConnection.

Rename 'rosterInitialized' to 'loaded' in Roster.

Add Roster.isLoaded().

Reset 'loaded' to false in
Roster.setOfflinePresencesAndResetLoaded() (was setOfflinePresences()).

Fixes SMACK-583, SMACK-532, SMACK-424
2015-01-07 14:35:23 +01:00
Florian Schmaus
c770b12348 Add log statements around socket.connect() of XMPPTCPConnection 2015-01-07 14:35:22 +01:00
Florian Schmaus
a24c813ed1 Add XMPPTCPConnectionConfiguration.getConnectTimeout() 2015-01-07 14:35:22 +01:00
Christoph Fiehe
665e7914f2 Enable OSGi compliance via 'DynamicImport-Package: *'
on package layer instead of Declarative Service (DS) approach.
Restructuring and cleanup of initialization process to ensure that all
internal config files are found by the corresponding bundle
classloaders.

SMACK-343
2015-01-03 13:14:02 +01:00
Florian Schmaus
08c1f2c850 Add AbstractXMPPConnection.parseAndProcessStanza()
and remove BOSHPacketReader.

Reduces the duplicate code in smack-tcp and smack-bosh. Also moves
ParsingExceptionCallback into AbstractXMPPConnection.
2014-12-28 17:43:39 +01:00