X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2Fserver%2FConnectAction.java;fp=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2Fserver%2FConnectAction.java;h=b9bf2240ef3cd62c6a2c6f0abc7506c6ac0cca0b;hb=3087aeb5f7b9fffcb57d51030c4674f9768e7f02;hp=0f2f1b4319fa799950119815c31dd9bf81043ee8;hpb=29fd216d455363af8bd4adb1e3325645b0ba7fb5;p=fanfix.git diff --git a/src/be/nikiroo/utils/serial/server/ConnectAction.java b/src/be/nikiroo/utils/serial/server/ConnectAction.java index 0f2f1b4..b9bf224 100644 --- a/src/be/nikiroo/utils/serial/server/ConnectAction.java +++ b/src/be/nikiroo/utils/serial/server/ConnectAction.java @@ -10,6 +10,7 @@ import javax.net.ssl.SSLException; import be.nikiroo.utils.CryptUtils; import be.nikiroo.utils.IOUtils; import be.nikiroo.utils.StringUtils; +import be.nikiroo.utils.Version; import be.nikiroo.utils.serial.Exporter; import be.nikiroo.utils.serial.Importer; import be.nikiroo.utils.streams.BufferedOutputStream; @@ -37,6 +38,9 @@ abstract class ConnectAction { private Socket s; private boolean server; + private Version clientVersion; + private Version serverVersion; + private CryptUtils crypt; private Object lock = new Object(); @@ -48,10 +52,28 @@ abstract class ConnectAction { * Method that will be called when an action is performed on either the * client or server this {@link ConnectAction} represent. * + * @param version + * the version on the other side of the communication (client or + * server) + * * @throws Exception * in case of I/O error */ - abstract protected void action() throws Exception; + abstract protected void action(Version version) throws Exception; + + /** + * Method called when we negotiate the version with the client. + *

+ * Thus, it is only called on the server. + *

+ * Will return the actual server version by default. + * + * @param clientVersion + * the client version + * + * @return the version to send to the client + */ + abstract protected Version negotiateVersion(Version clientVersion); /** * Handler called when an unexpected error occurs in the code. @@ -73,13 +95,40 @@ abstract class ConnectAction { * @param key * an optional key to encrypt all the communications (if NULL, * everything will be sent in clear text) + * @param version + * the client-or-server version (depending upon the boolean + * parameter server) */ - protected ConnectAction(Socket s, boolean server, String key) { + protected ConnectAction(Socket s, boolean server, String key, + Version version) { this.s = s; this.server = server; if (key != null) { crypt = new CryptUtils(key); } + + if (version == null) { + version = new Version(); + } + + if (server) { + serverVersion = version; + } else { + clientVersion = version; + } + } + + /** + * The version of this client-or-server. + * + * @return the version + */ + public Version getVersion() { + if (server) { + return serverVersion; + } + + return clientVersion; } /** @@ -110,7 +159,7 @@ abstract class ConnectAction { try { out = new BufferedOutputStream(s.getOutputStream()); try { - action(); + action(server ? serverVersion : clientVersion); } finally { out.close(); }