Commit graph

71 commits

Author SHA1 Message Date
Pranav Kant
f4b22bbb3c Broadcast command result back to clients
This is required to tell the clients if the command they issued was
successfull or not. In this case 'savetostorage' is the command that we
are interested in knowing the success status of.

With this, now if the user commands to overwrite the document, dialog
boxes of all other users are automatically closed.

Can easily more commands in future for this kind of thing. Its similar
to unocommandresult, except its not a uno command, but our internal
command.

Change-Id: I2e7e1fd5edbd55c13ee4bf9bce24284483d6507f
2017-06-01 21:42:29 +05:30
Pranav Kant
41234773e3 If user permits, save to storage force-fully in case of doc conflict
There is one known problem still - after any user decides to overwrite
the file to storage, other users are not informed, so their dialog keeps
hanging on the screen until they press the cancel or reload button.

Change-Id: I6dad1585e4c53eeed79cd38316892a7f239d44ef
2017-06-01 19:53:10 +05:30
Pranav Kant
4d61cae4c8 If user commands, refresh the document for all in case of doc conflict
Change-Id: I42c61fb8099b0bcc60f942e602561cc97486a918
2017-06-01 19:46:38 +05:30
Aditya Dewan
9db39ce741 tdf#107752 admin console: indicating whether a document is modified.
Change-Id: I6055a601c1dd3b5e9700ef75d7c07d7e0b13d663
2017-05-23 19:00:53 +05:30
Ashod Nakashian
e877adc84b wsd: don't stop doc on unauthorized loading
When a client connects with expired/invalid
access_token, the document should remain
active for other/existing clients, if any.

However, if no clients exists (i.e. the
first client has invalid access_token),
then the document should be unloaded and
cleaned up.

Change-Id: Iaad95a4286325cc6ee130b37e3ad635993a71c72
Reviewed-on: https://gerrit.libreoffice.org/37916
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-05-22 21:07:03 +02:00
Ashod Nakashian
407c538f04 Correctly send termination reason to clients
Fixes the case when the client reconnects on idle
disconnection (because it never got the 'close: idle'
message).

Also, show informative message to users in this case
instead of grey screen.

Change-Id: Ia2e1f2ffefe6d35dd1552e7cc44e490aab86c600
Reviewed-on: https://gerrit.libreoffice.org/37891
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-05-22 07:05:28 +02:00
Jan Holesovsky
9db41725f4 Revert "wsd: use WOPI host instance ID to support hostname aliases"
Turns out this introduces two calls to the CheckFileInfo which is not really
what we should be doing; instead, let's do a kind of cannonicalization in the
WOPI host directly.

This reverts commit ec2fd0844f.

Change-Id: I311bf8a45b706ed9a4d8cd00db0a990ac6d461b4
2017-05-19 10:34:38 +02:00
Ashod Nakashian
ec2fd0844f wsd: use WOPI host instance ID to support hostname aliases
The docKey creation moved to Storage where we first
invoke WOPI (if/when it's a WOPI-hosted doc and WOPI enabled)
and see if the user has access to the document at all.
If they do, we expect the server to give us a
unique ID to use for identifying the host regardless
of hostname aliases.

If a unique ID is not returned (i.e. empty or missing)
we use the hostname and port in its place as fallback.
This will break hostname aliases, but it will still work.

Change-Id: I407b0087395f9df6ad9cc6e037570487999be4a4
Reviewed-on: https://gerrit.libreoffice.org/37697
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-05-17 04:18:31 +02:00
Pranav Kant
1cb75cbcb8 wsd: Save wrapper over .uno:Save
Document broker needs to know when the save request is sent and when the
save finished. It uses these parameters to avoid shutting down document,
in the document broker main polling loop, if save is already going on.
But direct .uno:Save commands issued from
loleaflet precludes document broker to keep track of it - in this case a
.uno:Save command issued from loleaflet followed by closing the
session will prevent saving the document to storage, if document is huge
enough and LO core takes a bit of time to save it. A save wrapper
command, 'save', ensures that document broker is aware of all such save
requests (_saveRequestTime member variable) and doesn't close the
document until we completely save it (to storage and other cleanups).

Change-Id: I5ec73d45adff23b2e7543e93dfd0624a5e5af46d
2017-05-15 11:41:52 +05:30
Ashod Nakashian
9798eafb8c wsd: random jail paths instead of pid
Jail paths are now generate from a PRNG
instead of using the PID of the kit process.

The PRN is converted to base-64 and used
as the directory name where a given
kit is jailed.

Change-Id: I8e4bc35d9ccdfdae0e542ab707c417cd29ad52f3
Reviewed-on: https://gerrit.libreoffice.org/37372
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-05-08 04:59:12 +02:00
Ashod Nakashian
9b3a22aafe wsd: save document upon server shutdown
The server correctly saves all documents
and waits to upload them before exiting.

Change-Id: I04dc9ce588bc0fa39a9deb298d0a5efa61a03f1a
Reviewed-on: https://gerrit.libreoffice.org/36654
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-19 07:04:26 +02:00
Miklos Vajna
8a1f321c84 DocumentBroker: avoid unnecessary copying
Change-Id: Iaa555ed8e347d0e1712c617839f007d0b4f3204b
2017-04-11 08:54:28 +02:00
Ashod Nakashian
fa2e2869cf wsd: logging cleanups
Change-Id: Ia06bc5b1e0090c8198ac4ba2b88d5e57f8e2b168
Reviewed-on: https://gerrit.libreoffice.org/36327
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-10 06:11:58 +02:00
Ashod Nakashian
1e1f23716c wsd: don't take reference to session member being destroyed
Change-Id: I0074f4557018feb47a7a2a95a3fca238407a0023
Reviewed-on: https://gerrit.libreoffice.org/36227
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-06 17:58:47 +00:00
Ashod Nakashian
7da1909d3c wsd: kill DocumentBroker::getSessionsCount
Change-Id: Icd3229fe9b7d2f17a0e8a8f955c41ead8bca98c7
Reviewed-on: https://gerrit.libreoffice.org/36226
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-06 17:55:24 +00:00
Michael Meeks
90127ac0e3 Let the DocBroker thread clean itself up and expire.
(cherry picked from commit 2e372b70b32d4e052458547daa229c537442774f)

Change-Id: I5835c83f44ef770fa6ccd2418fc6ca73e17694e4
Reviewed-on: https://gerrit.libreoffice.org/36225
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-06 17:53:48 +00:00
Michael Meeks
3d945a5c38 Revert "Don't cleanup DocumentBrokers that still have their thread running."
This reverts commit df8dc43be4.

DocumentBroker::isAlive already checks _threadFinished.
2017-04-06 16:35:55 +01:00
Michael Meeks
df8dc43be4 Don't cleanup DocumentBrokers that still have their thread running.
Plenty of time to do that next time around the cleanup.
We should still, really be doing the majority of the timeout work
inside the DocumentBroker poll itself.
2017-04-06 16:24:54 +01:00
Michael Meeks
01519eff70 Always cleanup DocBrokers in the PrisonerPoll thread.
This simplifies things, and keeps process management in one thread.
Also - wakeup the DocumentBroker when we want to stop it.

Change-Id: I597ba4b34719fc072a4b4ad3697442b5eebe5784
Reviewed-on: https://gerrit.libreoffice.org/36182
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-06 06:16:44 +00:00
Jan Holesovsky
cb2b788cc7 assert(isCorrectThread()) -> assertCorrectThread().
assert()'s are no-op in the release builds, but we still want to see threading
problems in the log at least.

Change-Id: Idb02bb018e8f2d628a57ab570249613ad00bcff2
2017-04-05 14:49:30 +02:00
Michael Meeks
94022e90d9 Join threads to force a reasonably sensible shutdown sequence.
ie. actually wait until documents are saved and sessions closed.
2017-04-03 15:21:30 +01:00
Ashod Nakashian
95d51493aa wsd: remove nextmessage
This was a workaround to Poco's limitation
of requiring socket receiveFrame be given
preallocated buffer, which couldn't be
exceeded by a larger payload. This meant
the receiver had to know the maximum
payload in advance.

Since only the Kit uses Poco sockets,
and the Kit never receives large payloads,
this preamble is now obsolete.

100% (94/94) of old-style tests PASS.

Change-Id: I76776f89497409e5755e335a3e25553e91cf0876
Reviewed-on: https://gerrit.libreoffice.org/36037
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-03 05:18:09 +00:00
Ashod Nakashian
c9365ad679 wsd: log the DocBroker ID in the Kit as well
This matches the document between WSD and kit,
making logs much easier to read.

Change-Id: If55a9eb84b4a22d2dc4dd53f5f6ab322ebc3646e
Reviewed-on: https://gerrit.libreoffice.org/36028
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-03 05:11:23 +00:00
Ashod Nakashian
63ab3bcfa4 wsd: remove queueSession and simplify session loading
Change-Id: Ia03a4ed64b743da8fa7e27de853623126698b9c0
Reviewed-on: https://gerrit.libreoffice.org/36016
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-02 04:47:51 +00:00
Ashod Nakashian
7d3f5c0d2b wsd: terminate DocBrokers asynchronously
Remove locks and replace with isCorrectThread
assertions instead.

Crash recovery still needs some work, but
otherwise tests are clean (91/94 pass).

Change-Id: I9ac3e21854447d19a8e6106487dfd8be00fcf5ef
2017-03-30 02:19:24 -04:00
Ashod Nakashian
48ad9a2472 wsd: ClientSession::isLoaded -> isAttached
Since this doesn't necessary mean the document
was loaded completely (as the similarly named
flag in DocumentBroker signifies) rather that
the session was added to DocumentBroker.

Change-Id: Ibfc702bbd111ade2715dcb28ac3aa4e9e8e025dd
2017-03-29 23:55:19 -04:00
Ashod Nakashian
d77ede8954 wsd: consistent naming sendFrame -> sendMessage
Change-Id: I06c6bb42392a8982a8bb232eee33ece4c8dfc451
2017-03-29 20:03:01 -04:00
Ashod Nakashian
d3a8106cda wsd: remove NewSessions
Sessions are now added to the DocBroker
_sessions map and loaded from the poll
thread first before processing their
messages.

Since messages are not read from the
sockets outside of the poll thread,
there is no reason to queue them
at all. The only exception is when
messages are passed directly
to ClientSession during convert-to
requests. That will be handled
separately (for now convert-to test
fails).

Change-Id: I798166b9e45b5707a33d31137e01a32ce63630b1
Reviewed-on: https://gerrit.libreoffice.org/35705
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-26 05:06:22 +00:00
Ashod Nakashian
a57b9e6917 wsd: const correctness
Change-Id: I2bba04ccba9fd97e10ecc56f7db1f62a66a8f5f0
Reviewed-on: https://gerrit.libreoffice.org/35702
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-26 05:04:24 +00:00
Michael Meeks
ce0dffdc12 Use callback API to implement alertAllUsers safely and simply. 2017-03-21 08:31:20 +00:00
Ashod Nakashian
4df1e3c8f2 wsd: timeout after last save before terminating DocBroker
Change-Id: I87430285be7350ffbd3dfd6516257ed2b4ce1869
2017-03-20 21:57:58 -04:00
Ashod Nakashian
2ba2e213bb wsd: support rude termination of documents
Termination should normally be initiated by the
DocumentBroker in question, so sending of termination
message on the sockets come from the correct thread.

When termination happens from elsewhere
(f.e. cleanupDocBrokers) we cannot send socket
messages, and have to resort to rude termination.

Change-Id: I94acb7b314f5dbdc45c57049fc1ac8527ba72fb9
2017-03-20 00:41:53 -04:00
Michael Meeks
6d6dc45850 Remove un-necesssary and inefficient wakeupWorld.
While message emplacement happens in the DocumentBroker poll, we
can be sure that the next iteration of the poll will call
hasQueuedWrites before polling.
2017-03-15 12:07:34 +00:00
Michael Meeks
97e9463f17 Revert "wsd: TerminatingPoll always starts its own thread"
This reverts commit 388d7b1dbf.

It is vital to have clean control of thread start. By starting
a thread during init. of a member (or base-clase) we loose lots of
control, some examples:

	Any members initialized after a member that auto-starts a
	thread, is effectively un-defined, and cannot be accessed
	reliably.

	This is particularly problematic for sub-classes.

	I've seen threads started before the base-class has
	finished constructing in the original creating thread -
	such that the vtable was not yet updated to the sub-class
	causing the transient parent vtable used during construction
	to be used in-error.
2017-03-13 12:13:22 +00:00
Ashod Nakashian
8901fcf074 wsd: ChildProcess doesn't need friends
Change-Id: I1911920c9b49adecac4ea4d8fc4b0830687b80c7
Reviewed-on: https://gerrit.libreoffice.org/35121
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:21:25 +00:00
Ashod Nakashian
04bbb75200 wsd: dump state to generic ostream for flexiblity and to log
Change-Id: I4670ee2e90b7809ebc66a2b324a44334b3dbba2b
Reviewed-on: https://gerrit.libreoffice.org/35119
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:19:58 +00:00
Ashod Nakashian
388d7b1dbf wsd: TerminatingPoll always starts its own thread
Since all TerminatingPoll instances need to fire
a thread, no reason to do it manually and risk
races. Now TerminatingPoll does it in the ctor.

Change-Id: I59850ad48b3789f3a23d01abb05a7f28e5717031
Reviewed-on: https://gerrit.libreoffice.org/35114
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:09:15 +00:00
Ashod Nakashian
cbd00bf7c8 wsd: simplify DocumentBroker construction
DocumentBrokerPoll is always owned by a
single DocumentBroker instance, so we
can hold a reference to it. This eliminates
the need to hold a shared_ptr to the owner
which, in turn, eliminates the need for
a create wrapper.

Change-Id: I954c9dddcc3b2cfdd5dfcc8248ab3d47a897f684
Reviewed-on: https://gerrit.libreoffice.org/35113
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:08:40 +00:00
Michael Meeks
51ae42d513 DocumentBroker: log load time and dump it on request. 2017-03-11 22:01:27 +00:00
Michael Meeks
160446fd23 Work on resurrecting dying DocumentBrokers if we can.
The hope is that they will close lingering session sockets at the
end and the client will re-connect.
2017-03-10 17:58:51 +00:00
Ashod Nakashian
5677eb30b7 nb: fix saving when last client disconnects
When the last client session is disconnected
docBroker must first issue a save and wait
until the kit processes the save and sends
back notfication. Since said notification
goes to the ChildSession (which is the last)
and said ChildSession is the one that signals
to docBroker to persist the doc to the Storage,
we need to keep all components alive and kicking
during this final saving.

As such, when the last session is to be removed
from docBroker, we instead issue an autosave and
continue everything as normal. When the save
notification even arrives and ChildSession signals
docBroker to persist the doc, we check if we were
destroying and in that even remove that last session
and stop the polling thread.

The docBroker instance itself will get cleaned up
in due time.

Change-Id: Ie84e784284e1ec12b0b201d6bf75170b31f66147
2017-03-10 10:47:44 +01:00
Michael Meeks
438630c68f Start DocBroker thread later - when we've added our 1st session. 2017-03-10 10:47:44 +01:00
Michael Meeks
842b261d9f Move auto-save of document into the DocumentBroker poll more convincingly. 2017-03-10 10:47:44 +01:00
Ashod Nakashian
826217b4d8 nb: move the child socket to DocBroker poll
Change-Id: I8cbec60e49ca508df0e96e7e594f9dad15f84276
2017-03-10 10:47:43 +01:00
Ashod Nakashian
222b5562c3 nb: DocumentBroker::pollThread now non-static member
Change-Id: Ib95611f6f696f5810ce7fcb3a4bb67c1d7ac13ac
2017-03-10 10:47:43 +01:00
Michael Meeks
ce4bd9b9be Unify DocumentBroker thread and its SocketPoll. 2017-03-10 10:47:43 +01:00
Michael Meeks
79fb1e2c1f Sub-class the SocketPoll to allow more flexibility in termination. 2017-03-10 10:47:43 +01:00
Ashod Nakashian
c6dbce9767 nb: transfer client sockets to respective DocumentBroker
Change-Id: I6af656ec6cbb09d4dd80b7b583a009a763de6eb9
2017-03-10 10:47:43 +01:00
Michael Meeks
52327d78e2 Cleanout old socket code, and several obsolete LOOLWebSocket uses. 2017-03-10 10:47:43 +01:00
Michael Meeks
20f15d4001 Switch Prisoner socket handling to use the SocketPoll.
Kills the Poco ThreadPool usage, and significantly improves debuggability.
2017-03-10 10:47:43 +01:00