e263454b6f0e38fd3f4a192a47f05133ad34d174
[jFCPlib.git] / src / net / pterodactylus / fcp / highlevel / HighLevelClient.java
1 /*
2  * fcplib - HighLevelClient.java -
3  * Copyright © 2008 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package net.pterodactylus.fcp.highlevel;
21
22 import java.io.BufferedReader;
23 import java.io.File;
24 import java.io.FileReader;
25 import java.io.FileWriter;
26 import java.io.IOException;
27 import java.net.InetAddress;
28 import java.net.URL;
29 import java.net.UnknownHostException;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.Map.Entry;
36 import java.util.logging.Level;
37 import java.util.logging.Logger;
38
39 import net.pterodactylus.fcp.AddPeer;
40 import net.pterodactylus.fcp.AllData;
41 import net.pterodactylus.fcp.ClientGet;
42 import net.pterodactylus.fcp.ClientHello;
43 import net.pterodactylus.fcp.CloseConnectionDuplicateClientName;
44 import net.pterodactylus.fcp.ConfigData;
45 import net.pterodactylus.fcp.DataFound;
46 import net.pterodactylus.fcp.EndListPeerNotes;
47 import net.pterodactylus.fcp.EndListPeers;
48 import net.pterodactylus.fcp.EndListPersistentRequests;
49 import net.pterodactylus.fcp.FCPPluginReply;
50 import net.pterodactylus.fcp.FcpConnection;
51 import net.pterodactylus.fcp.FcpListener;
52 import net.pterodactylus.fcp.FcpMessage;
53 import net.pterodactylus.fcp.FcpUtils;
54 import net.pterodactylus.fcp.FinishedCompression;
55 import net.pterodactylus.fcp.GenerateSSK;
56 import net.pterodactylus.fcp.GetFailed;
57 import net.pterodactylus.fcp.IdentifierCollision;
58 import net.pterodactylus.fcp.ListPeers;
59 import net.pterodactylus.fcp.ListPersistentRequests;
60 import net.pterodactylus.fcp.NodeData;
61 import net.pterodactylus.fcp.NodeHello;
62 import net.pterodactylus.fcp.NodeRef;
63 import net.pterodactylus.fcp.Peer;
64 import net.pterodactylus.fcp.PeerNote;
65 import net.pterodactylus.fcp.PeerRemoved;
66 import net.pterodactylus.fcp.PersistentGet;
67 import net.pterodactylus.fcp.PersistentPut;
68 import net.pterodactylus.fcp.PersistentPutDir;
69 import net.pterodactylus.fcp.PersistentRequestModified;
70 import net.pterodactylus.fcp.PersistentRequestRemoved;
71 import net.pterodactylus.fcp.PluginInfo;
72 import net.pterodactylus.fcp.ProtocolError;
73 import net.pterodactylus.fcp.PutFailed;
74 import net.pterodactylus.fcp.PutFetchable;
75 import net.pterodactylus.fcp.PutSuccessful;
76 import net.pterodactylus.fcp.ReturnType;
77 import net.pterodactylus.fcp.SSKKeypair;
78 import net.pterodactylus.fcp.SimpleProgress;
79 import net.pterodactylus.fcp.StartedCompression;
80 import net.pterodactylus.fcp.SubscribedUSKUpdate;
81 import net.pterodactylus.fcp.TestDDAComplete;
82 import net.pterodactylus.fcp.TestDDAReply;
83 import net.pterodactylus.fcp.TestDDARequest;
84 import net.pterodactylus.fcp.TestDDAResponse;
85 import net.pterodactylus.fcp.URIGenerated;
86 import net.pterodactylus.fcp.UnknownNodeIdentifier;
87 import net.pterodactylus.fcp.UnknownPeerNoteType;
88 import net.pterodactylus.fcp.WatchGlobal;
89
90 /**
91  * A high-level client that allows simple yet full-featured access to a Freenet
92  * node.
93  * 
94  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
95  * @version $Id$
96  */
97 public class HighLevelClient {
98
99         /** Logger. */
100         private static final Logger logger = Logger.getLogger(HighLevelClient.class.getName());
101
102         /** Object for internal synchronization. */
103         private final Object syncObject = new Object();
104
105         /** The name of the client. */
106         private final String clientName;
107
108         /** The FCP connection to the node. */
109         private FcpConnection fcpConnection = null;
110
111         /** Listeners for high-level client events. */
112         private List<HighLevelClientListener> highLevelClientListeners = Collections.synchronizedList(new ArrayList<HighLevelClientListener>());
113
114         /** The listener for the connection. */
115         private HighLevelClientFcpListener highLevelClientFcpListener = new HighLevelClientFcpListener();
116
117         /** The listeners for progress events. */
118         private List<HighLevelProgressListener> highLevelProgressListeners = Collections.synchronizedList(new ArrayList<HighLevelProgressListener>());
119
120         /** The callback for {@link #connect(String)}. */
121         private HighLevelCallback<ConnectResult> connectCallback;
122
123         /** Mapping from request identifiers to callbacks. */
124         private Map<String, HighLevelCallback<KeyGenerationResult>> keyGenerationCallbacks = Collections.synchronizedMap(new HashMap<String, HighLevelCallback<KeyGenerationResult>>());
125
126         /** Mapping from request identifier to peer list callbacks. */
127         private Map<String, HighLevelCallback<PeerListResult>> peerListCallbacks = Collections.synchronizedMap(new HashMap<String, HighLevelCallback<PeerListResult>>());
128
129         /** Mapping from request identifier to peer callbacks. */
130         private Map<String, HighLevelCallback<PeerResult>> peerCallbacks = Collections.synchronizedMap(new HashMap<String, HighLevelCallback<PeerResult>>());
131
132         /** Mapping from directories to DDA callbacks. */
133         private Map<String, HighLevelCallback<DirectDiskAccessResult>> directDiskAccessCallbacks = Collections.synchronizedMap(new HashMap<String, HighLevelCallback<DirectDiskAccessResult>>());
134
135         /** Mapping from request identifiers to download callbacks. */
136         private Map<String, HighLevelProgressCallback<DownloadResult>> downloadCallbacks = Collections.synchronizedMap(new HashMap<String, HighLevelProgressCallback<DownloadResult>>());
137
138         /** The callback for {@link #getRequests()}. */
139         private HighLevelCallback<RequestListResult> requestListCallback;
140
141         /**
142          * Creates a new high-level client that connects to a node on
143          * <code>localhost</code>.
144          * 
145          * @param clientName
146          *            The name of the client
147          */
148         public HighLevelClient(String clientName) {
149                 this.clientName = clientName;
150         }
151
152         //
153         // EVENT MANAGEMENT
154         //
155
156         /**
157          * Adds the given high-level client listener to list of listeners.
158          * 
159          * @param highLevelClientListener
160          *            The listener to add
161          */
162         public void addHighLevelClientListener(HighLevelClientListener highLevelClientListener) {
163                 highLevelClientListeners.add(highLevelClientListener);
164         }
165
166         /**
167          * Removes the given high-level client listener from the list of listeners.
168          * 
169          * @param highLevelClientListener
170          *            The listener to remove
171          */
172         public void removeHighLevelClientListener(HighLevelClientListener highLevelClientListener) {
173                 highLevelClientListeners.remove(highLevelClientListener);
174         }
175
176         /**
177          * Notifies all listeners that a client has connected.
178          */
179         private void fireClientConnected() {
180                 for (HighLevelClientListener highLevelClientListener : highLevelClientListeners) {
181                         highLevelClientListener.clientConnected(this);
182                 }
183         }
184
185         /**
186          * Notifies all listeners that a client has disconnected.
187          * 
188          * @param throwable
189          *            The exception that caused the disconnect, or <code>null</code>
190          *            if there was no exception
191          */
192         private void fireClientDisconnected(Throwable throwable) {
193                 for (HighLevelClientListener highLevelClientListener : highLevelClientListeners) {
194                         highLevelClientListener.clientDisconnected(this, throwable);
195                 }
196         }
197
198         /**
199          * Adds a high-level progress listener.
200          * 
201          * @param highLevelProgressListener
202          *            The high-level progress listener to add
203          */
204         public void addHighLevelProgressListener(HighLevelProgressListener highLevelProgressListener) {
205                 highLevelProgressListeners.add(highLevelProgressListener);
206         }
207
208         /**
209          * Removes a high-level progress listener.
210          * 
211          * @param highLevelProgressListener
212          *            The high-level progress listener to remove
213          */
214         public void removeHighLevelProgressListener(HighLevelProgressListener highLevelProgressListener) {
215                 highLevelProgressListeners.remove(highLevelProgressListener);
216         }
217
218         /**
219          * Notifies all listeners that the request with the given identifier made
220          * some progress.
221          * 
222          * @param identifier
223          *            The identifier of the request
224          * @param highLevelProgress
225          *            The progress of the request
226          */
227         private void fireProgressReceived(String identifier, HighLevelProgress highLevelProgress) {
228                 for (HighLevelProgressListener highLevelProgressListener : highLevelProgressListeners) {
229                         highLevelProgressListener.progressReceived(this, identifier, highLevelProgress);
230                 }
231         }
232
233         //
234         // ACCESSORS
235         //
236
237         /**
238          * Returns the FCP connection that backs this high-level client. This method
239          * should be used with care as fiddling around with the FCP connection can
240          * easily break the high-level client if you don’t know what you’re doing!
241          * 
242          * @return The FCP connection of this client
243          */
244         public FcpConnection getFcpConnection() {
245                 return fcpConnection;
246         }
247
248         /**
249          * Returns whether the node is connected.
250          * 
251          * @return <code>true</code> if the node is currently connected,
252          *         <code>false</code> otherwise
253          */
254         public boolean isConnected() {
255                 return fcpConnection != null;
256         }
257
258         //
259         // ACTIONS
260         //
261
262         /**
263          * Connects the client.
264          * 
265          * @param hostname
266          *            The hostname of the node
267          * @return A callback with a connection result
268          * @throws UnknownHostException
269          *             if the hostname can not be resolved
270          * @throws IOException
271          *             if an I/O error occurs communicating with the node
272          */
273         public HighLevelCallback<ConnectResult> connect(String hostname) throws UnknownHostException, IOException {
274                 return connect(hostname, 9481);
275         }
276
277         /**
278          * Connects the client.
279          * 
280          * @param hostname
281          *            The hostname of the node
282          * @param port
283          *            The port number of the node
284          * @return A callback with a connection result
285          * @throws UnknownHostException
286          *             if the hostname can not be resolved
287          * @throws IOException
288          *             if an I/O error occurs communicating with the node
289          */
290         public HighLevelCallback<ConnectResult> connect(String hostname, int port) throws UnknownHostException, IOException {
291                 return connect(InetAddress.getByName(hostname), port);
292         }
293
294         /**
295          * Connects the client.
296          * 
297          * @param address
298          *            The address of the node
299          * @param port
300          *            The port number of the node
301          * @return A callback with a connection result
302          * @throws IOException
303          *             if an I/O error occurs communicating with the node
304          */
305         public HighLevelCallback<ConnectResult> connect(InetAddress address, int port) throws IOException {
306                 try {
307                         synchronized (this) {
308                                 fcpConnection = new FcpConnection(address, port);
309                         }
310                         fcpConnection.addFcpListener(highLevelClientFcpListener);
311                         fcpConnection.connect();
312                         ClientHello clientHello = new ClientHello(clientName);
313                         connectCallback = new HighLevelCallback<ConnectResult>(new ConnectResult());
314                         fcpConnection.sendMessage(clientHello);
315                         return connectCallback;
316                 } catch (IOException ioe1) {
317                         fcpConnection = null;
318                         throw ioe1;
319                 }
320         }
321
322         /**
323          * Disconnects the client from the node.
324          */
325         public void disconnect() {
326                 disconnect(null);
327         }
328
329         /**
330          * Generates a new SSK keypair.
331          * 
332          * @return A callback with the keypair
333          * @throws IOException
334          *             if an I/O error occurs communicating with the node
335          * @throws HighLevelException
336          *             if the client is not connected
337          */
338         public HighLevelCallback<KeyGenerationResult> generateKey() throws IOException, HighLevelException {
339                 checkConnection();
340                 String identifier = generateIdentifier("generateSSK");
341                 GenerateSSK generateSSK = new GenerateSSK(identifier);
342                 HighLevelCallback<KeyGenerationResult> keyGenerationCallback = new HighLevelCallback<KeyGenerationResult>(new KeyGenerationResult(identifier));
343                 keyGenerationCallbacks.put(identifier, keyGenerationCallback);
344                 fcpConnection.sendMessage(generateSSK);
345                 return keyGenerationCallback;
346         }
347
348         /**
349          * Sets whether to watch the global queue.
350          * 
351          * @param enabled
352          *            <code>true</code> to watch the global queue in addition to
353          *            the client-local queue, <code>false</code> to only watch the
354          *            client-local queue
355          * @throws IOException
356          *             if an I/O error occurs communicating with the node
357          * @throws HighLevelException
358          *             if the client is not connected
359          */
360         public void setWatchGlobal(boolean enabled) throws IOException, HighLevelException {
361                 checkConnection();
362                 WatchGlobal watchGlobal = new WatchGlobal(enabled);
363                 fcpConnection.sendMessage(watchGlobal);
364         }
365
366         /**
367          * Gets a list of all peers from the node.
368          * 
369          * @return A callback with the peer list
370          * @throws IOException
371          *             if an I/O error occurs with the node
372          * @throws HighLevelException
373          *             if the client is not connected
374          */
375         public HighLevelCallback<PeerListResult> getPeers() throws IOException, HighLevelException {
376                 checkConnection();
377                 String identifier = generateIdentifier("listPeers");
378                 ListPeers listPeers = new ListPeers(identifier, true, true);
379                 HighLevelCallback<PeerListResult> peerListCallback = new HighLevelCallback<PeerListResult>(new PeerListResult(identifier));
380                 peerListCallbacks.put(identifier, peerListCallback);
381                 fcpConnection.sendMessage(listPeers);
382                 return peerListCallback;
383         }
384
385         /**
386          * Adds the peer whose noderef is stored in the given file.
387          * 
388          * @param nodeRefFile
389          *            The name of the file the peer’s noderef is stored in
390          * @return A peer callback
391          * @throws IOException
392          *             if an I/O error occurs communicating with the node
393          * @throws HighLevelException
394          *             if the client is not connected
395          */
396         public HighLevelCallback<PeerResult> addPeer(String nodeRefFile) throws IOException, HighLevelException {
397                 checkConnection();
398                 String identifier = generateIdentifier("addPeer");
399                 AddPeer addPeer = new AddPeer(nodeRefFile);
400                 HighLevelCallback<PeerResult> peerCallback = new HighLevelCallback<PeerResult>(new PeerResult(identifier));
401                 peerCallbacks.put(identifier, peerCallback);
402                 fcpConnection.sendMessage(addPeer);
403                 return peerCallback;
404         }
405
406         /**
407          * Adds the peer whose noderef is stored in the given file.
408          * 
409          * @param nodeRefURL
410          *            The URL where the peer’s noderef is stored
411          * @return A peer callback
412          * @throws IOException
413          *             if an I/O error occurs communicating with the node
414          * @throws HighLevelException
415          *             if the client is not connected
416          */
417         public HighLevelCallback<PeerResult> addPeer(URL nodeRefURL) throws IOException, HighLevelException {
418                 checkConnection();
419                 String identifier = generateIdentifier("addPeer");
420                 AddPeer addPeer = new AddPeer(nodeRefURL);
421                 HighLevelCallback<PeerResult> peerCallback = new HighLevelCallback<PeerResult>(new PeerResult(identifier));
422                 peerCallbacks.put(identifier, peerCallback);
423                 fcpConnection.sendMessage(addPeer);
424                 return peerCallback;
425         }
426
427         /**
428          * Adds the peer whose noderef is stored in the given file.
429          * 
430          * @param nodeRef
431          *            The peer’s noderef
432          * @return A peer callback
433          * @throws IOException
434          *             if an I/O error occurs communicating with the node
435          * @throws HighLevelException
436          *             if the client is not connected
437          */
438         public HighLevelCallback<PeerResult> addPeer(NodeRef nodeRef) throws IOException, HighLevelException {
439                 checkConnection();
440                 String identifier = generateIdentifier("addPeer");
441                 AddPeer addPeer = new AddPeer(nodeRef);
442                 HighLevelCallback<PeerResult> peerCallback = new HighLevelCallback<PeerResult>(new PeerResult(identifier));
443                 peerCallbacks.put(identifier, peerCallback);
444                 fcpConnection.sendMessage(addPeer);
445                 return peerCallback;
446         }
447
448         /**
449          * Checks whether direct disk access for the given directory is possible.
450          * You have to perform this check before you can upload or download anything
451          * from or the disk directly!
452          * 
453          * @param directory
454          *            The directory to check
455          * @param wantRead
456          *            Whether you want to read the given directory
457          * @param wantWrite
458          *            Whether you want to write to the given directory
459          * @return A direct disk access callback
460          * @throws IOException
461          *             if an I/O error occurs communicating with the node
462          * @throws HighLevelException
463          *             if the client is not connected
464          */
465         public HighLevelCallback<DirectDiskAccessResult> checkDirectDiskAccess(String directory, boolean wantRead, boolean wantWrite) throws IOException, HighLevelException {
466                 checkConnection();
467                 TestDDARequest testDDARequest = new TestDDARequest(directory, wantRead, wantWrite);
468                 HighLevelCallback<DirectDiskAccessResult> directDiskAccessCallback = new HighLevelCallback<DirectDiskAccessResult>(new DirectDiskAccessResult(directory));
469                 directDiskAccessCallbacks.put(directory, directDiskAccessCallback);
470                 fcpConnection.sendMessage(testDDARequest);
471                 return directDiskAccessCallback;
472         }
473
474         /**
475          * Starts a download. Files can either be download to disk or streamed from
476          * the node. When downloading to disk you have to perform a direct disk
477          * access check for the directory you want to put the downloaded file in!
478          * 
479          * @see #checkDirectDiskAccess(String, boolean, boolean)
480          * @param uri
481          *            The URI to get
482          * @param filename
483          *            The filename to save the data to, or <code>null</code> to
484          *            retrieve the data as InputStream from the
485          *            {@link DownloadResult}
486          * @param global
487          *            Whether to put the download on the global queue
488          * @return A download result
489          * @throws IOException
490          *             if an I/O error occurs communicating with the node
491          * @throws HighLevelException
492          *             if the client is not connected
493          */
494         public HighLevelProgressCallback<DownloadResult> download(String uri, String filename, boolean global) throws IOException, HighLevelException {
495                 checkConnection();
496                 String identifier = generateIdentifier("download");
497                 ClientGet clientGet = new ClientGet(uri, identifier, (filename == null) ? ReturnType.direct : ReturnType.disk);
498                 clientGet.setGlobal(global);
499                 HighLevelProgressCallback<DownloadResult> downloadCallback = new HighLevelProgressCallback<DownloadResult>(new DownloadResult(identifier));
500                 downloadCallbacks.put(identifier, downloadCallback);
501                 fcpConnection.sendMessage(clientGet);
502                 return downloadCallback;
503         }
504
505         /**
506          * Requests a list of all running requests from the node.
507          * 
508          * @return The request list result
509          * @throws IOException
510          *             if an I/O errors communicating with the node
511          * @throws HighLevelException
512          *             if the client is not connected
513          */
514         public HighLevelCallback<RequestListResult> getRequests() throws IOException, HighLevelException {
515                 checkConnection();
516                 String identifier = generateIdentifier("list-persistent-requests");
517                 ListPersistentRequests listPersistentRequests = new ListPersistentRequests();
518                 synchronized (syncObject) {
519                         if (requestListCallback != null) {
520                                 logger.log(Level.SEVERE, "getRequests() called with request still running!");
521                         }
522                         requestListCallback = new HighLevelCallback<RequestListResult>(new RequestListResult(identifier));
523                 }
524                 fcpConnection.sendMessage(listPersistentRequests);
525                 return requestListCallback;
526         }
527
528         //
529         // PRIVATE METHODS
530         //
531
532         /**
533          * Checks whether the client is already connected and throws an exception if
534          * it is not.
535          * 
536          * @throws HighLevelException
537          *             if the client is not connected
538          */
539         private void checkConnection() throws HighLevelException {
540                 synchronized (this) {
541                         if (fcpConnection == null) {
542                                 throw new HighLevelException("client is not connected");
543                         }
544                 }
545         }
546
547         /**
548          * Generates an identifier for the given function.
549          * 
550          * @param function
551          *            The name of the function
552          * @return An identifier
553          */
554         private String generateIdentifier(String function) {
555                 return "jFCPlib-" + function + "-" + System.currentTimeMillis();
556         }
557
558         /**
559          * Disconnects the client from the node, handing the given Throwable to
560          * {@link #fireClientDisconnected(Throwable)}.
561          * 
562          * @param throwable
563          *            The exception that caused the disconnect, or <code>null</code>
564          *            if there was no exception
565          */
566         private void disconnect(Throwable throwable) {
567                 if (fcpConnection != null) {
568                         fcpConnection.close();
569                 }
570                 fcpConnection = null;
571         }
572
573         /**
574          * FCP listener for {@link HighLevelClient}.
575          * 
576          * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
577          * @version $Id$
578          */
579         private class HighLevelClientFcpListener implements FcpListener {
580
581                 /** Mapping from directory to written file (for cleanup). */
582                 private final Map<DirectDiskAccessResult, String> writtenFiles = new HashMap<DirectDiskAccessResult, String>();
583
584                 /**
585                  * Creates a new FCP listener for {@link HighLevelClient}.
586                  */
587                 HighLevelClientFcpListener() {
588                         /* do nothing. */
589                 }
590
591                 //
592                 // PRIVATE METHODS
593                 //
594
595                 /**
596                  * Searches all callback collections for a callback with the given
597                  * identifier and cancels it.
598                  * 
599                  * @param identifier
600                  *            The identifier to search for, or <code>null</code> to
601                  *            cancel all pending requests
602                  */
603                 @SuppressWarnings("synthetic-access")
604                 private void cancelIdentifier(String identifier) {
605                         synchronized (syncObject) {
606                                 if (connectCallback != null) {
607                                         connectCallback.getIntermediaryResult().setFailed(true);
608                                         connectCallback.setDone();
609                                         connectCallback = null;
610                                 }
611                                 if (requestListCallback != null) {
612                                         requestListCallback.getIntermediaryResult().setFailed(true);
613                                         requestListCallback.setDone();
614                                         requestListCallback = null;
615                                 }
616                         }
617                         if (identifier == null) {
618                                 /* key generation callbacks */
619                                 for (Entry<String, HighLevelCallback<KeyGenerationResult>> keyGenerationEntry : keyGenerationCallbacks.entrySet()) {
620                                         keyGenerationEntry.getValue().getIntermediaryResult().setFailed(true);
621                                         keyGenerationEntry.getValue().setDone();
622                                 }
623                                 keyGenerationCallbacks.clear();
624                                 /* peer list callbacks. */
625                                 for (Entry<String, HighLevelCallback<PeerListResult>> peerListEntry : peerListCallbacks.entrySet()) {
626                                         peerListEntry.getValue().getIntermediaryResult().setFailed(true);
627                                         peerListEntry.getValue().setDone();
628                                 }
629                                 peerListCallbacks.clear();
630                                 /* peer callbacks. */
631                                 for (Entry<String, HighLevelCallback<PeerResult>> peerEntry : peerCallbacks.entrySet()) {
632                                         peerEntry.getValue().getIntermediaryResult().setFailed(true);
633                                         peerEntry.getValue().setDone();
634                                 }
635                                 peerCallbacks.clear();
636                                 /* direct disk access callbacks. */
637                                 for (Entry<String, HighLevelCallback<DirectDiskAccessResult>> directDiskAccessEntry : directDiskAccessCallbacks.entrySet()) {
638                                         directDiskAccessEntry.getValue().getIntermediaryResult().setFailed(true);
639                                         directDiskAccessEntry.getValue().setDone();
640                                 }
641                                 directDiskAccessCallbacks.clear();
642                                 /* download callbacks. */
643                                 for (Entry<String, HighLevelProgressCallback<DownloadResult>> downloadEntry : downloadCallbacks.entrySet()) {
644                                         downloadEntry.getValue().getIntermediaryResult().setFailed(true);
645                                         downloadEntry.getValue().setDone();
646                                 }
647                                 downloadCallbacks.clear();
648                         } else {
649                                 HighLevelCallback<KeyGenerationResult> keyGenerationCallback = keyGenerationCallbacks.remove(identifier);
650                                 if (keyGenerationCallback != null) {
651                                         keyGenerationCallback.getIntermediaryResult().setFailed(true);
652                                         keyGenerationCallback.setDone();
653                                         return;
654                                 }
655                                 HighLevelCallback<PeerListResult> peerListCallback = peerListCallbacks.remove(identifier);
656                                 if (peerListCallback != null) {
657                                         peerListCallback.getIntermediaryResult().setFailed(true);
658                                         peerListCallback.setDone();
659                                         return;
660                                 }
661                                 HighLevelCallback<PeerResult> peerCallback = peerCallbacks.remove(identifier);
662                                 if (peerCallback != null) {
663                                         peerCallback.getIntermediaryResult().setFailed(true);
664                                         peerCallback.setDone();
665                                         return;
666                                 }
667                                 HighLevelCallback<DirectDiskAccessResult> directDiskAccessCallback = directDiskAccessCallbacks.remove(identifier);
668                                 if (directDiskAccessCallback != null) {
669                                         directDiskAccessCallback.getIntermediaryResult().setFailed(true);
670                                         directDiskAccessCallback.setDone();
671                                         return;
672                                 }
673                                 HighLevelProgressCallback<DownloadResult> downloadCallback = downloadCallbacks.remove(identifier);
674                                 if (downloadCallback != null) {
675                                         downloadCallback.getIntermediaryResult().setFailed(true);
676                                         downloadCallback.setDone();
677                                         return;
678                                 }
679                         }
680                 }
681
682                 /**
683                  * Reads the given file and returns the first line of the file.
684                  * 
685                  * @param readFilename
686                  *            The name of the file to read
687                  * @return The content of the file
688                  */
689                 private String readContent(String readFilename) {
690                         FileReader fileReader = null;
691                         BufferedReader bufferedFileReader = null;
692                         try {
693                                 fileReader = new FileReader(readFilename);
694                                 bufferedFileReader = new BufferedReader(fileReader);
695                                 String content = bufferedFileReader.readLine();
696                                 return content;
697                         } catch (IOException ioe1) {
698                                 /* swallow. */
699                         } finally {
700                                 FcpUtils.close(bufferedFileReader);
701                                 FcpUtils.close(fileReader);
702                         }
703                         return null;
704                 }
705
706                 /**
707                  * Writes the given content to the given file.
708                  * 
709                  * @param directDiskAccessResult
710                  *            The DDA result
711                  * @param writeFilename
712                  *            The name of the file to write to
713                  * @param writeContent
714                  *            The content to write to the file
715                  */
716                 private void writeContent(DirectDiskAccessResult directDiskAccessResult, String writeFilename, String writeContent) {
717                         if ((writeFilename == null) || (writeContent == null)) {
718                                 return;
719                         }
720                         writtenFiles.put(directDiskAccessResult, writeFilename);
721                         FileWriter fileWriter = null;
722                         try {
723                                 fileWriter = new FileWriter(writeFilename);
724                                 fileWriter.write(writeContent);
725                         } catch (IOException ioe1) {
726                                 /* swallow. */
727                         } finally {
728                                 FcpUtils.close(fileWriter);
729                         }
730                 }
731
732                 /**
733                  * Cleans up any files that written for the given result.
734                  * 
735                  * @param directDiskAccessResult
736                  *            The direct disk access result
737                  */
738                 @SuppressWarnings("synthetic-access")
739                 private void cleanFiles(DirectDiskAccessResult directDiskAccessResult) {
740                         String writeFilename = writtenFiles.remove(directDiskAccessResult);
741                         if (writeFilename != null) {
742                                 if (!new File(writeFilename).delete()) {
743                                         logger.warning("could not delete " + writeFilename);
744                                 }
745                         }
746                 }
747
748                 //
749                 // INTERFACE FcpListener
750                 //
751
752                 /**
753                  * @see net.pterodactylus.fcp.FcpListener#connectionClosed(net.pterodactylus.fcp.FcpConnection,
754                  *      Throwable)
755                  */
756                 @SuppressWarnings("synthetic-access")
757                 public void connectionClosed(FcpConnection fcpConnection, Throwable throwable) {
758                         if (fcpConnection != HighLevelClient.this.fcpConnection) {
759                                 return;
760                         }
761                         cancelIdentifier(null);
762                         disconnect(throwable);
763                         fireClientDisconnected(throwable);
764                 }
765
766                 /**
767                  * @see net.pterodactylus.fcp.FcpListener#receivedAllData(net.pterodactylus.fcp.FcpConnection,
768                  *      net.pterodactylus.fcp.AllData)
769                  */
770                 public void receivedAllData(FcpConnection fcpConnection, AllData allData) {
771                         /* TODO */
772                 }
773
774                 /**
775                  * @see net.pterodactylus.fcp.FcpListener#receivedCloseConnectionDuplicateClientName(net.pterodactylus.fcp.FcpConnection,
776                  *      net.pterodactylus.fcp.CloseConnectionDuplicateClientName)
777                  */
778                 public void receivedCloseConnectionDuplicateClientName(FcpConnection fcpConnection, CloseConnectionDuplicateClientName closeConnectionDuplicateClientName) {
779                         /* TODO */
780                 }
781
782                 /**
783                  * @see net.pterodactylus.fcp.FcpListener#receivedConfigData(net.pterodactylus.fcp.FcpConnection,
784                  *      net.pterodactylus.fcp.ConfigData)
785                  */
786                 public void receivedConfigData(FcpConnection fcpConnection, ConfigData configData) {
787                         /* TODO */
788                 }
789
790                 /**
791                  * @see net.pterodactylus.fcp.FcpListener#receivedDataFound(net.pterodactylus.fcp.FcpConnection,
792                  *      net.pterodactylus.fcp.DataFound)
793                  */
794                 public void receivedDataFound(FcpConnection fcpConnection, DataFound dataFound) {
795                         /* TODO */
796                 }
797
798                 /**
799                  * @see net.pterodactylus.fcp.FcpListener#receivedEndListPeerNotes(net.pterodactylus.fcp.FcpConnection,
800                  *      net.pterodactylus.fcp.EndListPeerNotes)
801                  */
802                 public void receivedEndListPeerNotes(FcpConnection fcpConnection, EndListPeerNotes endListPeerNotes) {
803                         /* TODO */
804                 }
805
806                 /**
807                  * @see net.pterodactylus.fcp.FcpListener#receivedEndListPeers(net.pterodactylus.fcp.FcpConnection,
808                  *      net.pterodactylus.fcp.EndListPeers)
809                  */
810                 @SuppressWarnings("synthetic-access")
811                 public void receivedEndListPeers(FcpConnection fcpConnection, EndListPeers endListPeers) {
812                         if (fcpConnection != HighLevelClient.this.fcpConnection) {
813                                 return;
814                         }
815                         String identifier = endListPeers.getIdentifier();
816                         HighLevelCallback<PeerListResult> peerListCallback = peerListCallbacks.remove(identifier);
817                         if (peerListCallback == null) {
818                                 return;
819                         }
820                         peerListCallback.setDone();
821                 }
822
823                 /**
824                  * @see net.pterodactylus.fcp.FcpListener#receivedEndListPersistentRequests(net.pterodactylus.fcp.FcpConnection,
825                  *      net.pterodactylus.fcp.EndListPersistentRequests)
826                  */
827                 @SuppressWarnings("synthetic-access")
828                 public void receivedEndListPersistentRequests(FcpConnection fcpConnection, EndListPersistentRequests endListPersistentRequests) {
829                         if (fcpConnection != HighLevelClient.this.fcpConnection) {
830                                 return;
831                         }
832                         synchronized (syncObject) {
833                                 if (HighLevelClient.this.requestListCallback == null) {
834                                         logger.log(Level.WARNING, "got EndListPersistentRequests without running request!");
835                                         return;
836                                 }
837                                 requestListCallback.setDone();
838                                 requestListCallback = null;
839                         }
840                 }
841
842                 /**
843                  * @see net.pterodactylus.fcp.FcpListener#receivedFCPPluginReply(net.pterodactylus.fcp.FcpConnection,
844                  *      net.pterodactylus.fcp.FCPPluginReply)
845                  */
846                 public void receivedFCPPluginReply(FcpConnection fcpConnection, FCPPluginReply fcpPluginReply) {
847                         /* TODO */
848                 }
849
850                 /**
851                  * @see net.pterodactylus.fcp.FcpListener#receivedGetFailed(net.pterodactylus.fcp.FcpConnection,
852                  *      net.pterodactylus.fcp.GetFailed)
853                  */
854                 @SuppressWarnings("synthetic-access")
855                 public void receivedGetFailed(FcpConnection fcpConnection, GetFailed getFailed) {
856                         if (fcpConnection != HighLevelClient.this.fcpConnection) {
857                                 return;
858                         }
859                         String identifier = getFailed.getIdentifier();
860                         HighLevelProgressCallback<DownloadResult> downloadCallback = downloadCallbacks.remove(identifier);
861                         if (downloadCallback != null) {
862                                 downloadCallback.getIntermediaryResult().setFailed(true);
863                                 downloadCallback.setDone();
864                                 return;
865                         }
866                         /* unknown identifier? */
867                         logger.warning("unknown identifier for GetFailed: " + identifier);
868                 }
869
870                 /**
871                  * @see net.pterodactylus.fcp.FcpListener#receivedIdentifierCollision(net.pterodactylus.fcp.FcpConnection,
872                  *      net.pterodactylus.fcp.IdentifierCollision)
873                  */
874                 public void receivedIdentifierCollision(FcpConnection fcpConnection, IdentifierCollision identifierCollision) {
875                         /* TODO */
876                 }
877
878                 /**
879                  * @see net.pterodactylus.fcp.FcpListener#receivedMessage(net.pterodactylus.fcp.FcpConnection,
880                  *      net.pterodactylus.fcp.FcpMessage)
881                  */
882                 public void receivedMessage(FcpConnection fcpConnection, FcpMessage fcpMessage) {
883                         /* TODO */
884                 }
885
886                 /**
887                  * @see net.pterodactylus.fcp.FcpListener#receivedNodeData(net.pterodactylus.fcp.FcpConnection,
888                  *      net.pterodactylus.fcp.NodeData)
889                  */
890                 public void receivedNodeData(FcpConnection fcpConnection, NodeData nodeData) {
891                         /* TODO */
892                 }
893
894                 /**
895                  * @see net.pterodactylus.fcp.FcpListener#receivedNodeHello(net.pterodactylus.fcp.FcpConnection,
896                  *      net.pterodactylus.fcp.NodeHello)
897                  */
898                 @SuppressWarnings("synthetic-access")
899                 public void receivedNodeHello(FcpConnection fcpConnection, NodeHello nodeHello) {
900                         if (fcpConnection != HighLevelClient.this.fcpConnection) {
901                                 return;
902                         }
903                         synchronized (syncObject) {
904                                 connectCallback.getIntermediaryResult().setFailed(false);
905                                 connectCallback.setDone();
906                                 connectCallback = null;
907                         }
908                         fireClientConnected();
909                 }
910
911                 /**
912                  * @see net.pterodactylus.fcp.FcpListener#receivedPeer(net.pterodactylus.fcp.FcpConnection,
913                  *      net.pterodactylus.fcp.Peer)
914                  */
915                 @SuppressWarnings("synthetic-access")
916                 public void receivedPeer(FcpConnection fcpConnection, Peer peer) {
917                         if (fcpConnection != HighLevelClient.this.fcpConnection) {
918                                 return;
919                         }
920                         String identifier = peer.getIdentifier();
921                         if (identifier == null) {
922                                 return;
923                         }
924                         HighLevelCallback<PeerListResult> peerListCallback = peerListCallbacks.get(identifier);
925                         if (peerListCallback != null) {
926                                 peerListCallback.getIntermediaryResult().addPeer(peer);
927                                 return;
928                         }
929                         HighLevelCallback<PeerResult> peerResult = peerCallbacks.remove(identifier);
930                         if (peerResult != null) {
931                                 peerResult.getIntermediaryResult().setPeer(peer);
932                                 peerResult.setDone();
933                                 return;
934                         }
935                         logger.warning("got Peer message with unknown identifier: " + identifier);
936                 }
937
938                 /**
939                  * @see net.pterodactylus.fcp.FcpListener#receivedPeerNote(net.pterodactylus.fcp.FcpConnection,
940                  *      net.pterodactylus.fcp.PeerNote)
941                  */
942                 public void receivedPeerNote(FcpConnection fcpConnection, PeerNote peerNote) {
943                         /* TODO */
944                 }
945
946                 /**
947                  * @see net.pterodactylus.fcp.FcpListener#receivedPeerRemoved(net.pterodactylus.fcp.FcpConnection,
948                  *      net.pterodactylus.fcp.PeerRemoved)
949                  */
950                 public void receivedPeerRemoved(FcpConnection fcpConnection, PeerRemoved peerRemoved) {
951                         /* TODO */
952                 }
953
954                 /**
955                  * @see net.pterodactylus.fcp.FcpListener#receivedPersistentGet(net.pterodactylus.fcp.FcpConnection,
956                  *      net.pterodactylus.fcp.PersistentGet)
957                  */
958                 @SuppressWarnings("synthetic-access")
959                 public void receivedPersistentGet(FcpConnection fcpConnection, PersistentGet persistentGet) {
960                         if (fcpConnection != HighLevelClient.this.fcpConnection) {
961                                 return;
962                         }
963                         synchronized (syncObject) {
964                                 if (requestListCallback != null) {
965                                         RequestListResult requestListResult = requestListCallback.getIntermediaryResult();
966                                         requestListResult.addRequestResult(new GetRequestResult(persistentGet));
967                                         return;
968                                 }
969                         }
970                         String identifier = persistentGet.getIdentifier();
971                         if (downloadCallbacks.containsKey(identifier)) {
972                                 /* TODO */
973                                 return;
974                         }
975                 }
976
977                 /**
978                  * @see net.pterodactylus.fcp.FcpListener#receivedPersistentPut(net.pterodactylus.fcp.FcpConnection,
979                  *      net.pterodactylus.fcp.PersistentPut)
980                  */
981                 @SuppressWarnings("synthetic-access")
982                 public void receivedPersistentPut(FcpConnection fcpConnection, PersistentPut persistentPut) {
983                         if (fcpConnection != HighLevelClient.this.fcpConnection) {
984                                 return;
985                         }
986                         synchronized (syncObject) {
987                                 if (requestListCallback != null) {
988                                         RequestListResult requestListResult = requestListCallback.getIntermediaryResult();
989                                         requestListResult.addRequestResult(new PutRequestResult(persistentPut));
990                                         return;
991                                 }
992                         }
993                 }
994
995                 /**
996                  * @see net.pterodactylus.fcp.FcpListener#receivedPersistentPutDir(net.pterodactylus.fcp.FcpConnection,
997                  *      net.pterodactylus.fcp.PersistentPutDir)
998                  */
999                 @SuppressWarnings("synthetic-access")
1000                 public void receivedPersistentPutDir(FcpConnection fcpConnection, PersistentPutDir persistentPutDir) {
1001                         if (fcpConnection != HighLevelClient.this.fcpConnection) {
1002                                 return;
1003                         }
1004                         synchronized (syncObject) {
1005                                 if (requestListCallback != null) {
1006                                         RequestListResult requestListResult = requestListCallback.getIntermediaryResult();
1007                                         requestListResult.addRequestResult(new PutDirRequestResult(persistentPutDir));
1008                                         return;
1009                                 }
1010                         }
1011                 }
1012
1013                 /**
1014                  * @see net.pterodactylus.fcp.FcpListener#receivedPersistentRequestModified(net.pterodactylus.fcp.FcpConnection,
1015                  *      net.pterodactylus.fcp.PersistentRequestModified)
1016                  */
1017                 public void receivedPersistentRequestModified(FcpConnection fcpConnection, PersistentRequestModified persistentRequestModified) {
1018                         /* TODO */
1019                 }
1020
1021                 /**
1022                  * @see net.pterodactylus.fcp.FcpListener#receivedPersistentRequestRemoved(net.pterodactylus.fcp.FcpConnection,
1023                  *      net.pterodactylus.fcp.PersistentRequestRemoved)
1024                  */
1025                 public void receivedPersistentRequestRemoved(FcpConnection fcpConnection, PersistentRequestRemoved persistentRequestRemoved) {
1026                         /* TODO */
1027                 }
1028
1029                 /**
1030                  * @see net.pterodactylus.fcp.FcpListener#receivedPluginInfo(net.pterodactylus.fcp.FcpConnection,
1031                  *      net.pterodactylus.fcp.PluginInfo)
1032                  */
1033                 public void receivedPluginInfo(FcpConnection fcpConnection, PluginInfo pluginInfo) {
1034                         /* TODO */
1035                 }
1036
1037                 /**
1038                  * @see net.pterodactylus.fcp.FcpListener#receivedProtocolError(net.pterodactylus.fcp.FcpConnection,
1039                  *      net.pterodactylus.fcp.ProtocolError)
1040                  */
1041                 @SuppressWarnings("synthetic-access")
1042                 public void receivedProtocolError(FcpConnection fcpConnection, ProtocolError protocolError) {
1043                         if (fcpConnection != HighLevelClient.this.fcpConnection) {
1044                                 return;
1045                         }
1046                         String identifier = protocolError.getIdentifier();
1047                         if (identifier == null) {
1048                                 return;
1049                         }
1050                         cancelIdentifier(identifier);
1051                 }
1052
1053                 /**
1054                  * @see net.pterodactylus.fcp.FcpListener#receivedPutFailed(net.pterodactylus.fcp.FcpConnection,
1055                  *      net.pterodactylus.fcp.PutFailed)
1056                  */
1057                 public void receivedPutFailed(FcpConnection fcpConnection, PutFailed putFailed) {
1058                         /* TODO */
1059                 }
1060
1061                 /**
1062                  * @see net.pterodactylus.fcp.FcpListener#receivedPutFetchable(net.pterodactylus.fcp.FcpConnection,
1063                  *      net.pterodactylus.fcp.PutFetchable)
1064                  */
1065                 public void receivedPutFetchable(FcpConnection fcpConnection, PutFetchable putFetchable) {
1066                         /* TODO */
1067                 }
1068
1069                 /**
1070                  * @see net.pterodactylus.fcp.FcpListener#receivedPutSuccessful(net.pterodactylus.fcp.FcpConnection,
1071                  *      net.pterodactylus.fcp.PutSuccessful)
1072                  */
1073                 public void receivedPutSuccessful(FcpConnection fcpConnection, PutSuccessful putSuccessful) {
1074                         /* TODO */
1075                 }
1076
1077                 /**
1078                  * @see net.pterodactylus.fcp.FcpListener#receivedSSKKeypair(net.pterodactylus.fcp.FcpConnection,
1079                  *      net.pterodactylus.fcp.SSKKeypair)
1080                  */
1081                 @SuppressWarnings("synthetic-access")
1082                 public void receivedSSKKeypair(FcpConnection fcpConnection, SSKKeypair sskKeypair) {
1083                         if (fcpConnection != HighLevelClient.this.fcpConnection) {
1084                                 return;
1085                         }
1086                         HighLevelCallback<KeyGenerationResult> keyGenerationCallback = keyGenerationCallbacks.remove(sskKeypair.getIdentifier());
1087                         if (keyGenerationCallback == null) {
1088                                 return;
1089                         }
1090                         KeyGenerationResult keyGenerationResult = keyGenerationCallback.getIntermediaryResult();
1091                         keyGenerationResult.setInsertURI(sskKeypair.getInsertURI());
1092                         keyGenerationResult.setRequestURI(sskKeypair.getRequestURI());
1093                         keyGenerationCallback.setDone();
1094                 }
1095
1096                 /**
1097                  * @see net.pterodactylus.fcp.FcpListener#receivedSimpleProgress(net.pterodactylus.fcp.FcpConnection,
1098                  *      net.pterodactylus.fcp.SimpleProgress)
1099                  */
1100                 @SuppressWarnings("synthetic-access")
1101                 public void receivedSimpleProgress(FcpConnection fcpConnection, SimpleProgress simpleProgress) {
1102                         if (fcpConnection != HighLevelClient.this.fcpConnection) {
1103                                 return;
1104                         }
1105                         String identifier = simpleProgress.getIdentifier();
1106                         HighLevelProgressCallback<DownloadResult> downloadCallback = downloadCallbacks.get(identifier);
1107                         if (downloadCallback != null) {
1108                                 DownloadResult downloadResult = downloadCallback.getIntermediaryResult();
1109                                 downloadResult.setTotalBlocks(simpleProgress.getTotal());
1110                                 downloadResult.setRequiredBlocks(simpleProgress.getRequired());
1111                                 downloadResult.setSuccessfulBlocks(simpleProgress.getSucceeded());
1112                                 downloadResult.setFailedBlocks(simpleProgress.getFailed());
1113                                 downloadResult.setFatallyFailedBlocks(simpleProgress.getFatallyFailed());
1114                                 downloadResult.setTotalFinalized(simpleProgress.isFinalizedTotal());
1115                                 downloadCallback.progressUpdated();
1116                         }
1117                         HighLevelProgress highLevelProgress = new HighLevelProgress(identifier, simpleProgress.getTotal(), simpleProgress.getRequired(), simpleProgress.getSucceeded(), simpleProgress.getFailed(), simpleProgress.getFatallyFailed(), simpleProgress.isFinalizedTotal());
1118                         fireProgressReceived(identifier, highLevelProgress);
1119                 }
1120
1121                 /**
1122                  * @see net.pterodactylus.fcp.FcpListener#receivedStartedCompression(net.pterodactylus.fcp.FcpConnection,
1123                  *      net.pterodactylus.fcp.StartedCompression)
1124                  */
1125                 public void receivedStartedCompression(FcpConnection fcpConnection, StartedCompression startedCompression) {
1126                         /* TODO */
1127                 }
1128
1129                 /**
1130                  * @see net.pterodactylus.fcp.FcpListener#receivedSubscribedUSKUpdate(net.pterodactylus.fcp.FcpConnection,
1131                  *      net.pterodactylus.fcp.SubscribedUSKUpdate)
1132                  */
1133                 public void receivedSubscribedUSKUpdate(FcpConnection fcpConnection, SubscribedUSKUpdate subscribedUSKUpdate) {
1134                         /* TODO */
1135                 }
1136
1137                 /**
1138                  * @see net.pterodactylus.fcp.FcpListener#receivedTestDDAComplete(net.pterodactylus.fcp.FcpConnection,
1139                  *      net.pterodactylus.fcp.TestDDAComplete)
1140                  */
1141                 @SuppressWarnings("synthetic-access")
1142                 public void receivedTestDDAComplete(FcpConnection fcpConnection, TestDDAComplete testDDAComplete) {
1143                         if (fcpConnection != HighLevelClient.this.fcpConnection) {
1144                                 return;
1145                         }
1146                         String directory = testDDAComplete.getDirectory();
1147                         if (directory == null) {
1148                                 return;
1149                         }
1150                         HighLevelCallback<DirectDiskAccessResult> directDiskAccessCallback = directDiskAccessCallbacks.remove(directory);
1151                         DirectDiskAccessResult directDiskAccessResult = directDiskAccessCallback.getIntermediaryResult();
1152                         cleanFiles(directDiskAccessResult);
1153                         directDiskAccessResult.setReadAllowed(testDDAComplete.isReadDirectoryAllowed());
1154                         directDiskAccessResult.setWriteAllowed(testDDAComplete.isWriteDirectoryAllowed());
1155                         directDiskAccessCallback.setDone();
1156                 }
1157
1158                 /**
1159                  * @see net.pterodactylus.fcp.FcpListener#receivedTestDDAReply(net.pterodactylus.fcp.FcpConnection,
1160                  *      net.pterodactylus.fcp.TestDDAReply)
1161                  */
1162                 @SuppressWarnings("synthetic-access")
1163                 public void receivedTestDDAReply(FcpConnection fcpConnection, TestDDAReply testDDAReply) {
1164                         if (fcpConnection != HighLevelClient.this.fcpConnection) {
1165                                 return;
1166                         }
1167                         String directory = testDDAReply.getDirectory();
1168                         if (directory == null) {
1169                                 return;
1170                         }
1171                         DirectDiskAccessResult directDiskAccessResult = directDiskAccessCallbacks.get(directory).getIntermediaryResult();
1172                         String readFilename = testDDAReply.getReadFilename();
1173                         String readContent = readContent(readFilename);
1174                         String writeFilename = testDDAReply.getWriteFilename();
1175                         String writeContent = testDDAReply.getContentToWrite();
1176                         writeContent(directDiskAccessResult, writeFilename, writeContent);
1177                         TestDDAResponse testDDAResponse = new TestDDAResponse(directory, readContent);
1178                         try {
1179                                 fcpConnection.sendMessage(testDDAResponse);
1180                         } catch (IOException e) {
1181                                 /* swallow. I’m verry unhappy about this. */
1182                         }
1183                 }
1184
1185                 /**
1186                  * @see net.pterodactylus.fcp.FcpListener#receivedURIGenerated(net.pterodactylus.fcp.FcpConnection,
1187                  *      net.pterodactylus.fcp.URIGenerated)
1188                  */
1189                 public void receivedURIGenerated(FcpConnection fcpConnection, URIGenerated uriGenerated) {
1190                         /* TODO */
1191                 }
1192
1193                 /**
1194                  * @see net.pterodactylus.fcp.FcpListener#receivedUnknownNodeIdentifier(net.pterodactylus.fcp.FcpConnection,
1195                  *      net.pterodactylus.fcp.UnknownNodeIdentifier)
1196                  */
1197                 public void receivedUnknownNodeIdentifier(FcpConnection fcpConnection, UnknownNodeIdentifier unknownNodeIdentifier) {
1198                         /* TODO */
1199                 }
1200
1201                 /**
1202                  * @see net.pterodactylus.fcp.FcpListener#receivedUnknownPeerNoteType(net.pterodactylus.fcp.FcpConnection,
1203                  *      net.pterodactylus.fcp.UnknownPeerNoteType)
1204                  */
1205                 public void receivedUnknownPeerNoteType(FcpConnection fcpConnection, UnknownPeerNoteType unknownPeerNoteType) {
1206                         /* TODO */
1207                 }
1208
1209                 /**
1210                  * @see net.pterodactylus.fcp.FcpListener#receviedFinishedCompression(net.pterodactylus.fcp.FcpConnection,
1211                  *      net.pterodactylus.fcp.FinishedCompression)
1212                  */
1213                 public void receviedFinishedCompression(FcpConnection fcpConnection, FinishedCompression finishedCompression) {
1214                         /* TODO */
1215                 }
1216
1217         }
1218
1219 }