From 2e338ba5ae7a5e11ce63650182023c4e9f97f509 Mon Sep 17 00:00:00 2001 From: EndMove Date: Tue, 15 Feb 2022 08:44:57 +0100 Subject: [PATCH 01/64] Add gradle project and .gitignore --- .gitattributes | 6 + .gitignore | 160 +++++++++++++++ app/build.gradle | 35 ++++ app/src/main/java/lightcontainer/App.java | 14 ++ app/src/test/java/lightcontainer/AppTest.java | 14 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 59536 bytes gradle/wrapper/gradle-wrapper.properties | 5 + gradlew | 185 ++++++++++++++++++ gradlew.bat | 89 +++++++++ settings.gradle | 11 ++ 10 files changed, 519 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 app/build.gradle create mode 100644 app/src/main/java/lightcontainer/App.java create mode 100644 app/src/test/java/lightcontainer/AppTest.java create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..00a51af --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +# +# https://help.github.com/articles/dealing-with-line-endings/ +# +# These are explicitly windows files and should use crlf +*.bat text eol=crlf + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6cefc8a --- /dev/null +++ b/.gitignore @@ -0,0 +1,160 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/gradle,java,intellij +# Edit at https://www.toptal.com/developers/gitignore?templates=gradle,java,intellij + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +### Gradle ### +.gradle +**/build/ +!src/**/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# Eclipse Gradle plugin generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# End of https://www.toptal.com/developers/gitignore/api/gradle,java,intellij \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..2a11f36 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,35 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * This generated file contains a sample Java application project to get you started. + * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle + * User Manual available at https://docs.gradle.org/7.1/userguide/building_java_projects.html + */ + +plugins { + // Apply the application plugin to add support for building a CLI application in Java. + id 'application' +} + +repositories { + // Use Maven Central for resolving dependencies. + mavenCentral() +} + +dependencies { + // Use JUnit Jupiter for testing. + testImplementation 'org.junit.jupiter:junit-jupiter:5.7.1' + + // This dependency is used by the application. + implementation 'com.google.guava:guava:30.1-jre' +} + +application { + // Define the main class for the application. + mainClass = 'lightcontainer.App' +} + +tasks.named('test') { + // Use JUnit Platform for unit tests. + useJUnitPlatform() +} diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java new file mode 100644 index 0000000..aa63180 --- /dev/null +++ b/app/src/main/java/lightcontainer/App.java @@ -0,0 +1,14 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +package lightcontainer; + +public class App { + public String getGreeting() { + return "Hello World!"; + } + + public static void main(String[] args) { + System.out.println(new App().getGreeting()); + } +} diff --git a/app/src/test/java/lightcontainer/AppTest.java b/app/src/test/java/lightcontainer/AppTest.java new file mode 100644 index 0000000..f435009 --- /dev/null +++ b/app/src/test/java/lightcontainer/AppTest.java @@ -0,0 +1,14 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +package lightcontainer; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +class AppTest { + @Test void appHasAGreeting() { + App classUnderTest = new App(); + assertNotNull(classUnderTest.getGreeting(), "app should have a greeting"); + } +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..7454180f2ae8848c63b8b4dea2cb829da983f2fa GIT binary patch literal 59536 zcma&NbC71ylI~qywr$(CZQJHswz}-9F59+k+g;UV+cs{`J?GrGXYR~=-ydruB3JCa zB64N^cILAcWk5iofq)<(fq;O7{th4@;QxID0)qN`mJ?GIqLY#rX8-|G{5M0pdVW5^ zzXk$-2kQTAC?_N@B`&6-N-rmVFE=$QD?>*=4<|!MJu@}isLc4AW#{m2if&A5T5g&~ ziuMQeS*U5sL6J698wOd)K@oK@1{peP5&Esut<#VH^u)gp`9H4)`uE!2$>RTctN+^u z=ASkePDZA-X8)rp%D;p*~P?*a_=*Kwc<^>QSH|^<0>o37lt^+Mj1;4YvJ(JR-Y+?%Nu}JAYj5 z_Qc5%Ao#F?q32i?ZaN2OSNhWL;2oDEw_({7ZbgUjna!Fqn3NzLM@-EWFPZVmc>(fZ z0&bF-Ch#p9C{YJT9Rcr3+Y_uR^At1^BxZ#eo>$PLJF3=;t_$2|t+_6gg5(j{TmjYU zK12c&lE?Eh+2u2&6Gf*IdKS&6?rYbSEKBN!rv{YCm|Rt=UlPcW9j`0o6{66#y5t9C zruFA2iKd=H%jHf%ypOkxLnO8#H}#Zt{8p!oi6)7#NqoF({t6|J^?1e*oxqng9Q2Cc zg%5Vu!em)}Yuj?kaP!D?b?(C*w!1;>R=j90+RTkyEXz+9CufZ$C^umX^+4|J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-A|}e#LN{)(eXloDnX4Vs7eH|<@{r#LodP@Nz--$Dg_Par%DCpu2>2jUnqy~|J?eZ zBG4FVsz_A+ibdwv>mLp>P!(t}E>$JGaK$R~;fb{O3($y1ssQQo|5M;^JqC?7qe|hg zu0ZOqeFcp?qVn&Qu7FQJ4hcFi&|nR!*j)MF#b}QO^lN%5)4p*D^H+B){n8%VPUzi! zDihoGcP71a6!ab`l^hK&*dYrVYzJ0)#}xVrp!e;lI!+x+bfCN0KXwUAPU9@#l7@0& QuEJmfE|#`Dqx|px0L@K;Y5)KL literal 0 HcmV?d00001 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..69a9715 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..744e882 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MSYS* | MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..e41310b --- /dev/null +++ b/settings.gradle @@ -0,0 +1,11 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * The settings file is used to specify which projects to include in your build. + * + * Detailed information about configuring a multi-project build in Gradle can be found + * in the user manual at https://docs.gradle.org/7.1/userguide/multi_project_builds.html + */ + +rootProject.name = 'FileFrontEnd' +include('app') From fe4e80a148aafa3f89862969223bfc4b5d628616 Mon Sep 17 00:00:00 2001 From: EndMove Date: Tue, 15 Feb 2022 09:30:41 +0100 Subject: [PATCH 02/64] Add "domains" --- .idea/.gitignore | 8 +++ .idea/compiler.xml | 6 ++ .idea/discord.xml | 7 ++ .idea/jarRepositories.xml | 20 ++++++ .idea/libraries-with-intellij-classes.xml | 65 +++++++++++++++++++ .idea/misc.xml | 8 +++ .idea/vcs.xml | 6 ++ .../lightcontainer/domains/ClientHandler.java | 4 ++ .../lightcontainer/domains/FileFrontEnd.java | 5 ++ .../lightcontainer/domains/StorProcessor.java | 4 ++ 10 files changed, 133 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/discord.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/libraries-with-intellij-classes.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 app/src/main/java/lightcontainer/domains/ClientHandler.java create mode 100644 app/src/main/java/lightcontainer/domains/FileFrontEnd.java create mode 100644 app/src/main/java/lightcontainer/domains/StorProcessor.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 0000000..d8e9561 --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries-with-intellij-classes.xml b/.idea/libraries-with-intellij-classes.xml new file mode 100644 index 0000000..9fa3156 --- /dev/null +++ b/.idea/libraries-with-intellij-classes.xml @@ -0,0 +1,65 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..3e79c5f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/java/lightcontainer/domains/ClientHandler.java b/app/src/main/java/lightcontainer/domains/ClientHandler.java new file mode 100644 index 0000000..663d29e --- /dev/null +++ b/app/src/main/java/lightcontainer/domains/ClientHandler.java @@ -0,0 +1,4 @@ +package lightcontainer.domains; + +public class ClientHandler { +} diff --git a/app/src/main/java/lightcontainer/domains/FileFrontEnd.java b/app/src/main/java/lightcontainer/domains/FileFrontEnd.java new file mode 100644 index 0000000..6916615 --- /dev/null +++ b/app/src/main/java/lightcontainer/domains/FileFrontEnd.java @@ -0,0 +1,5 @@ +package lightcontainer.domains; + +public class FileFrontEnd { + +} diff --git a/app/src/main/java/lightcontainer/domains/StorProcessor.java b/app/src/main/java/lightcontainer/domains/StorProcessor.java new file mode 100644 index 0000000..fe8ef38 --- /dev/null +++ b/app/src/main/java/lightcontainer/domains/StorProcessor.java @@ -0,0 +1,4 @@ +package lightcontainer.domains; + +public class StorProcessor { +} From f91067504ef8aba84be3c193f67e36b4eaba4874 Mon Sep 17 00:00:00 2001 From: EndMove Date: Tue, 15 Feb 2022 11:35:45 +0100 Subject: [PATCH 03/64] Add StoreMulticastRunnable.java, Multicast receiver --- .idea/inspectionProfiles/Project_Default.xml | 6 ++ app/src/main/java/lightcontainer/App.java | 24 +++++-- .../domains/StoreMulticastRunnable.java | 69 +++++++++++++++++++ app/src/test/java/lightcontainer/AppTest.java | 8 +-- 4 files changed, 98 insertions(+), 9 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 app/src/main/java/lightcontainer/domains/StoreMulticastRunnable.java diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..601f39c --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java index aa63180..e85d0bf 100644 --- a/app/src/main/java/lightcontainer/App.java +++ b/app/src/main/java/lightcontainer/App.java @@ -3,12 +3,26 @@ */ package lightcontainer; -public class App { - public String getGreeting() { - return "Hello World!"; - } +import lightcontainer.domains.StoreMulticastRunnable; +public class App { public static void main(String[] args) { - System.out.println(new App().getGreeting()); + System.out.println("Hello World !"); + + int port = 42500; + String ip = "226.0.0.1"; + + StoreMulticastRunnable multicast = new StoreMulticastRunnable(ip, port); + (new Thread(multicast)).start(); + + // Sleep + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + // Close + multicast.stop(); } } diff --git a/app/src/main/java/lightcontainer/domains/StoreMulticastRunnable.java b/app/src/main/java/lightcontainer/domains/StoreMulticastRunnable.java new file mode 100644 index 0000000..a8ba557 --- /dev/null +++ b/app/src/main/java/lightcontainer/domains/StoreMulticastRunnable.java @@ -0,0 +1,69 @@ +package lightcontainer.domains; + +import java.net.DatagramPacket; +import java.net.InetAddress; +import java.net.MulticastSocket; + +/** + * StoreMulticastRunnable + * + * Class listening to the announcement of new StoreBackEnd. + * Allowing it to be used as a storage unit. + * + * @version 1.0 + * + * @see Runnable + * @author Jérémi NIHART + */ +public class StoreMulticastRunnable implements Runnable { + // Variable + private final String multicast_address; + private final int multicast_port; + + private final byte[] buffer = new byte[256]; + private MulticastSocket listener; + + // Constructor + public StoreMulticastRunnable(String multicast_address, int multicast_port) { + this.multicast_address = multicast_address; + this.multicast_port = multicast_port; + } + + /** + * Start Multicast listening on indicated port and IP group. + * + * @since 1.0 + * + * @see MulticastSocket#receive(DatagramPacket) + * @see DatagramPacket + */ + @Override + public void run() { + try { + // Create a new listening socket + this.listener = new MulticastSocket(this.multicast_port); + // Create an identifier for the multicast group on the specified ip + InetAddress listener_group = InetAddress.getByName(this.multicast_address); + // Creation of a packet for the information received + DatagramPacket packet = new DatagramPacket(buffer, buffer.length); + // Add the listener to the multicast group + listener.joinGroup(listener_group); + while(true) { + listener.receive(packet); + String data = new String(packet.getData(), 0, packet.getLength()); + System.out.println(data); // TODO ajouter un controller et lui signaler qu'il y a un nouveau StoreBackEnd + } + } catch (Exception ignore) { } + } + + /** + * Closes the MulticastSocket connection and aborts the listening and infinite listening loop. + * + * @since 1.0 + * + * @see StoreMulticastRunnable#run() + */ + public void stop() { + this.listener.close(); + } +} diff --git a/app/src/test/java/lightcontainer/AppTest.java b/app/src/test/java/lightcontainer/AppTest.java index f435009..9d64c1d 100644 --- a/app/src/test/java/lightcontainer/AppTest.java +++ b/app/src/test/java/lightcontainer/AppTest.java @@ -7,8 +7,8 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; class AppTest { - @Test void appHasAGreeting() { - App classUnderTest = new App(); - assertNotNull(classUnderTest.getGreeting(), "app should have a greeting"); - } +// @Test void appHasAGreeting() { +// App classUnderTest = new App(); +// assertNotNull(classUnderTest.getGreeting(), "app should have a greeting"); +// } } From fb5c14b28eb2bd9198fac1efe9e01cbeb164799a Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 15 Feb 2022 12:30:11 +0100 Subject: [PATCH 04/64] Standardized definitions --- .idea/.gitignore | 8 ++++++++ .idea/compiler.xml | 6 ++++++ .idea/jarRepositories.xml | 20 ++++++++++++++++++++ .idea/misc.xml | 10 ++++++++++ .idea/vcs.xml | 6 ++++++ app/src/main/resources/rules.txt | 21 +++++++++++++++++++++ 6 files changed, 71 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 app/src/main/resources/rules.txt diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5d98256 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/resources/rules.txt b/app/src/main/resources/rules.txt new file mode 100644 index 0000000..766386a --- /dev/null +++ b/app/src/main/resources/rules.txt @@ -0,0 +1,21 @@ +//Standardized definitions +digit = [0-9]; +port = [1-65536]{1,5}; TODO: Corriger +size = [0-9]{1,10}; +line = \r\n; +visiblechar = \p{Print}; +passchar = [^\s!]; +binary = .; +password = [^\s!]{5,50}; +bl = \s; +letter = [A-Za-z]; +digit_letter = [A-Za-z0-9]; +filename = [^\s!]{1,20}; +domain = [A-Za-z0-9.]{5,20}; +hash_filename = [A-Za-z0-9.]{50,200}; +hash_filecontent = [A-Za-z0-9.]{50,200}; +file_info = [A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200}; +login = [A-Za-z0-9]{2,20}; + +//StorBackEnd to FileFrontEnd +sbe_hello = \ No newline at end of file From c16185994ec8aeab59b08c632fe599ca69259535 Mon Sep 17 00:00:00 2001 From: EndMove Date: Tue, 15 Feb 2022 12:31:08 +0100 Subject: [PATCH 05/64] =?UTF-8?q?D=C3=A9veloppement=20d'un=20syst=C3=A8me?= =?UTF-8?q?=20de=20protocol,=20ajout=20d'une=20rule=20pour=20tester=20(tod?= =?UTF-8?q?o:=20cr=C3=A9ation=20de=20rule).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/App.java | 4 + .../lightcontainer/domains/ClientHandler.java | 4 - .../lightcontainer/domains/StorProcessor.java | 4 - .../domains/StoreMulticastRunnable.java | 1 + .../lightcontainer/protocol/HelloRule.java | 31 +++++ .../lightcontainer/protocol/Protocol.java | 125 ++++++++++++++++++ 6 files changed, 161 insertions(+), 8 deletions(-) delete mode 100644 app/src/main/java/lightcontainer/domains/ClientHandler.java delete mode 100644 app/src/main/java/lightcontainer/domains/StorProcessor.java create mode 100644 app/src/main/java/lightcontainer/protocol/HelloRule.java create mode 100644 app/src/main/java/lightcontainer/protocol/Protocol.java diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java index e85d0bf..e590d9d 100644 --- a/app/src/main/java/lightcontainer/App.java +++ b/app/src/main/java/lightcontainer/App.java @@ -4,6 +4,10 @@ package lightcontainer; import lightcontainer.domains.StoreMulticastRunnable; +import lightcontainer.protocol.Protocol; + +import java.util.HashMap; +import java.util.Map; public class App { public static void main(String[] args) { diff --git a/app/src/main/java/lightcontainer/domains/ClientHandler.java b/app/src/main/java/lightcontainer/domains/ClientHandler.java deleted file mode 100644 index 663d29e..0000000 --- a/app/src/main/java/lightcontainer/domains/ClientHandler.java +++ /dev/null @@ -1,4 +0,0 @@ -package lightcontainer.domains; - -public class ClientHandler { -} diff --git a/app/src/main/java/lightcontainer/domains/StorProcessor.java b/app/src/main/java/lightcontainer/domains/StorProcessor.java deleted file mode 100644 index fe8ef38..0000000 --- a/app/src/main/java/lightcontainer/domains/StorProcessor.java +++ /dev/null @@ -1,4 +0,0 @@ -package lightcontainer.domains; - -public class StorProcessor { -} diff --git a/app/src/main/java/lightcontainer/domains/StoreMulticastRunnable.java b/app/src/main/java/lightcontainer/domains/StoreMulticastRunnable.java index a8ba557..f6aede3 100644 --- a/app/src/main/java/lightcontainer/domains/StoreMulticastRunnable.java +++ b/app/src/main/java/lightcontainer/domains/StoreMulticastRunnable.java @@ -11,6 +11,7 @@ import java.net.MulticastSocket; * Allowing it to be used as a storage unit. * * @version 1.0 + * @since 1.0 * * @see Runnable * @author Jérémi NIHART diff --git a/app/src/main/java/lightcontainer/protocol/HelloRule.java b/app/src/main/java/lightcontainer/protocol/HelloRule.java new file mode 100644 index 0000000..c9c2b94 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/HelloRule.java @@ -0,0 +1,31 @@ +package lightcontainer.protocol; + +public class HelloRule extends Protocol { + // Variables + + // Constructor + protected HelloRule() { + super("HELLO", "HELLO "); // TODO : add the regex here (sbe_hello = "HELLO bl domain bl port line") + } + + /** + * Execute the rule on a command. + * + * This function allows you to check a command and process those groups (parameters) + * use the utility functions of {@link Protocol} to facilitate processing, see @see. + * + * @param cmd Command on which to execute the rule. + * @see Protocol#execute(String) + * @see #matcherCheck(String) + * @see #matcherGetGroups() + * @since 1.0 + */ + @Override + public void execute(String cmd) { + if (matcherCheck(cmd)) { + System.out.println("Good rule ;-) !"); + } else { + System.out.println("OUPPS unknown rule !"); + } + } +} diff --git a/app/src/main/java/lightcontainer/protocol/Protocol.java b/app/src/main/java/lightcontainer/protocol/Protocol.java new file mode 100644 index 0000000..e7449f3 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/Protocol.java @@ -0,0 +1,125 @@ +package lightcontainer.protocol; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Protocol + * + * Class allowing to define new rules for the LightContainer protocol, + * also provides utility functions to work with regexes and the command to compare. + * + * @version 1.0 + * @since 1.0 + * + * @see Pattern + * @author Jérémi NIHART + */ +public abstract class Protocol { + // Variables + private final String rule; + private final Pattern rulePattern; + private List groups; + + /** + * Protocol constructor + * @param rule Command (e.g: LOGIN). + * @param regex Regex to compile and use for this command (e.g: LOGIN ([A-Z0-9a-z]{1,20})). + * Do not forget to define the groups in the regex. + */ + protected Protocol(String rule, String regex) { + this.rule = rule; + this.rulePattern = Pattern.compile(regex); + } + + /** + * Retrieve, the name of the Rule. + * + * @return Name of this rule. + * + * @since 1.0 + */ + public String getRule() { + return this.rule; + } + + /** + * Check if a command matches the rule with the rule matcher. + * + * @return True : if the command match with the rule. + * False though. + * @param cmd Command to verify with the rule matcher. + * + * @since 1.0 + */ + protected boolean matcherCheck(String cmd) { + Matcher ruleMatcher = this.rulePattern.matcher(cmd); + if (ruleMatcher.matches()) { + this.groups = new ArrayList<>(); + for (int i=1; i <= ruleMatcher.groupCount(); i++) this.groups.add(ruleMatcher.group(i)); + return true; + } + return false; + } + + /** + * Get a list of all the groups extracted from the previously matched command with {@link #matcherCheck(String)}. + * + * Requires to have run {@link #matcherCheck(String)} + * + * @return String list containing all the groups extrapolated from the command. + * + * @since 1.0 + * + * @see Protocol#matcherCheck(String) + */ + protected List matcherGetGroups() { + return this.groups; + } + + /** + * Execute the rule on a command. + * + * This function allows you to check a command and process those groups (parameters) + * use the utility functions of {@link Protocol} to facilitate processing, see @see. + * + * @param cmd Command on which to execute the rule. + * + * @since 1.0 + * + * @see Protocol#execute(String) + * @see #matcherCheck(String) + * @see #matcherGetGroups() + */ + public abstract void execute(String cmd); + + /** + * Retrieve, the hashcode of the rule. + * + * @return Rule hashcode. + * + * @since 1.0 + */ + @Override + public int hashCode() { + return rule.hashCode() % 8; + } + + /** + * Compare the equality of two rules. + * + * @return True : if the rules are equals + * False if not. + * + * @since 1.0 + */ + @Override + public boolean equals(final Object obj) { + if (this == obj) return true; + if (!(obj instanceof Protocol)) return false; + final Protocol other = (Protocol) obj; + return hashCode() == other.hashCode(); + } +} From 90d36d38f9b1e2a6bc1e374ec02ec3dbc6cd572d Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sun, 20 Feb 2022 10:22:39 +0100 Subject: [PATCH 06/64] =?UTF-8?q?Regex=20Port=20:=20Corrig=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/resources/rules.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/resources/rules.txt b/app/src/main/resources/rules.txt index 766386a..6af8e16 100644 --- a/app/src/main/resources/rules.txt +++ b/app/src/main/resources/rules.txt @@ -1,6 +1,6 @@ //Standardized definitions digit = [0-9]; -port = [1-65536]{1,5}; TODO: Corriger +port = ((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4})); size = [0-9]{1,10}; line = \r\n; visiblechar = \p{Print}; From 2aa2bb97cbb2780f3b4be5232925c1428bd76181 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sun, 20 Feb 2022 10:59:11 +0100 Subject: [PATCH 07/64] Regex : StorBackEnd to FileFrontEnd --- app/src/main/resources/rules.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/resources/rules.txt b/app/src/main/resources/rules.txt index 6af8e16..6a67a77 100644 --- a/app/src/main/resources/rules.txt +++ b/app/src/main/resources/rules.txt @@ -1,6 +1,6 @@ //Standardized definitions digit = [0-9]; -port = ((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4})); +port = (6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4}); size = [0-9]{1,10}; line = \r\n; visiblechar = \p{Print}; @@ -18,4 +18,4 @@ file_info = [A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200}; login = [A-Za-z0-9]{2,20}; //StorBackEnd to FileFrontEnd -sbe_hello = \ No newline at end of file +sbe_hello = ^(HELLO)\s([A-Za-z0-9.]{5,20})\s((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([0-5][0-9]{4})|([0-9]{1,4}))$; //\r\n -> à tester \ No newline at end of file From a72317a9fcaec7127da460e7e61d52c36ae3c5dc Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sun, 20 Feb 2022 11:15:36 +0100 Subject: [PATCH 08/64] Regex : FileFrontEnd to StorBackEnd --- app/src/main/resources/rules.txt | 44 +++++++++++++++++++------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/app/src/main/resources/rules.txt b/app/src/main/resources/rules.txt index 6a67a77..2cfa297 100644 --- a/app/src/main/resources/rules.txt +++ b/app/src/main/resources/rules.txt @@ -1,21 +1,29 @@ //Standardized definitions -digit = [0-9]; -port = (6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4}); -size = [0-9]{1,10}; -line = \r\n; -visiblechar = \p{Print}; -passchar = [^\s!]; -binary = .; -password = [^\s!]{5,50}; -bl = \s; -letter = [A-Za-z]; -digit_letter = [A-Za-z0-9]; -filename = [^\s!]{1,20}; -domain = [A-Za-z0-9.]{5,20}; -hash_filename = [A-Za-z0-9.]{50,200}; -hash_filecontent = [A-Za-z0-9.]{50,200}; -file_info = [A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200}; -login = [A-Za-z0-9]{2,20}; +digit = [0-9] +port = (6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4}) +size = [0-9]{1,10} +line = \r\n +visiblechar = \p{Print} +passchar = [^\s!] +binary = . +password = [^\s!]{5,50} +bl = \s +letter = [A-Za-z] +digit_letter = [A-Za-z0-9] +filename = [^\s!]{1,20} +domain = [A-Za-z0-9.]{5,20} +hash_filename = [A-Za-z0-9.]{50,200} +hash_filecontent = [A-Za-z0-9.]{50,200} +file_info = [A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200} +login = [A-Za-z0-9]{2,20} //StorBackEnd to FileFrontEnd -sbe_hello = ^(HELLO)\s([A-Za-z0-9.]{5,20})\s((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([0-5][0-9]{4})|([0-9]{1,4}))$; //\r\n -> à tester \ No newline at end of file +sbe_hello = ^(HELLO)\s([A-Za-z0-9.]{5,20})\s((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([0-5][0-9]{4})|([0-9]{1,4}))\r\n$ //TODO \r\n -> à tester pour voir si déjà dans le flux ou doit être construit + +//FileFrontEnd to StorBackEnd +ffe_sendfile = ^(SENDFILE)\s([A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200})\r\n(.*)$ +sbe_sendresult = ^(SEND_OK|SEND_ERROR)\r\n$ +ffe_erasefile = ^(ERASEFILE)\s([A-Za-z0-9.]{50,200})\r\n$ +sbe_eraseresult = ^(ERASE_OK|ERASE_ERROR)\r\n$ +ffe_retrievefile = ^(RETRIEVEFILE)\s([A-Za-z0-9.]{50,200})\r\n$ +sbe_retrieveresult = ^(RETRIEVE_OK)\s([A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200})\r\n(.*)|(RETRIEVE_ERROR)$ \ No newline at end of file From 56d3468df81f89947360e953b151e4532d7a74d5 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 22 Feb 2022 09:30:33 +0100 Subject: [PATCH 09/64] Regex : Client to FileFrontEnd --- .../lightcontainer/protocol/Protocol.java | 70 ++++++++----------- .../lightcontainer/protocol/SbeHello.java | 16 +++++ app/src/main/resources/rules.txt | 18 ++++- 3 files changed, 63 insertions(+), 41 deletions(-) create mode 100644 app/src/main/java/lightcontainer/protocol/SbeHello.java diff --git a/app/src/main/java/lightcontainer/protocol/Protocol.java b/app/src/main/java/lightcontainer/protocol/Protocol.java index e7449f3..07bb621 100644 --- a/app/src/main/java/lightcontainer/protocol/Protocol.java +++ b/app/src/main/java/lightcontainer/protocol/Protocol.java @@ -7,15 +7,14 @@ import java.util.regex.Pattern; /** * Protocol - * + *

* Class allowing to define new rules for the LightContainer protocol, * also provides utility functions to work with regexes and the command to compare. * - * @version 1.0 - * @since 1.0 - * - * @see Pattern - * @author Jérémi NIHART + * @author Jérémi NIHART + * @version 1.0 + * @see Pattern + * @since 1.0 */ public abstract class Protocol { // Variables @@ -25,9 +24,10 @@ public abstract class Protocol { /** * Protocol constructor - * @param rule Command (e.g: LOGIN). - * @param regex Regex to compile and use for this command (e.g: LOGIN ([A-Z0-9a-z]{1,20})). - * Do not forget to define the groups in the regex. + * + * @param rule Command (e.g: LOGIN). + * @param regex Regex to compile and use for this command (e.g: LOGIN ([A-Z0-9a-z]{1,20})). + * Do not forget to define the groups in the regex. */ protected Protocol(String rule, String regex) { this.rule = rule; @@ -37,9 +37,8 @@ public abstract class Protocol { /** * Retrieve, the name of the Rule. * - * @return Name of this rule. - * - * @since 1.0 + * @return Name of this rule. + * @since 1.0 */ public String getRule() { return this.rule; @@ -48,17 +47,16 @@ public abstract class Protocol { /** * Check if a command matches the rule with the rule matcher. * - * @return True : if the command match with the rule. - * False though. - * @param cmd Command to verify with the rule matcher. - * - * @since 1.0 + * @param cmd Command to verify with the rule matcher. + * @return True : if the command match with the rule. + * False though. + * @since 1.0 */ protected boolean matcherCheck(String cmd) { Matcher ruleMatcher = this.rulePattern.matcher(cmd); if (ruleMatcher.matches()) { this.groups = new ArrayList<>(); - for (int i=1; i <= ruleMatcher.groupCount(); i++) this.groups.add(ruleMatcher.group(i)); + for (int i = 1; i <= ruleMatcher.groupCount(); i++) this.groups.add(ruleMatcher.group(i)); return true; } return false; @@ -66,14 +64,12 @@ public abstract class Protocol { /** * Get a list of all the groups extracted from the previously matched command with {@link #matcherCheck(String)}. - * + * * Requires to have run {@link #matcherCheck(String)} * - * @return String list containing all the groups extrapolated from the command. - * - * @since 1.0 - * - * @see Protocol#matcherCheck(String) + * @return String list containing all the groups extrapolated from the command. + * @see Protocol#matcherCheck(String) + * @since 1.0 */ protected List matcherGetGroups() { return this.groups; @@ -81,26 +77,23 @@ public abstract class Protocol { /** * Execute the rule on a command. - * + *

* This function allows you to check a command and process those groups (parameters) * use the utility functions of {@link Protocol} to facilitate processing, see @see. * - * @param cmd Command on which to execute the rule. - * - * @since 1.0 - * - * @see Protocol#execute(String) - * @see #matcherCheck(String) - * @see #matcherGetGroups() + * @param cmd Command on which to execute the rule. + * @see Protocol#execute(String) + * @see #matcherCheck(String) + * @see #matcherGetGroups() + * @since 1.0 */ public abstract void execute(String cmd); /** * Retrieve, the hashcode of the rule. * - * @return Rule hashcode. - * - * @since 1.0 + * @return Rule hashcode. + * @since 1.0 */ @Override public int hashCode() { @@ -110,10 +103,9 @@ public abstract class Protocol { /** * Compare the equality of two rules. * - * @return True : if the rules are equals - * False if not. - * - * @since 1.0 + * @return True : if the rules are equals + * False if not. + * @since 1.0 */ @Override public boolean equals(final Object obj) { diff --git a/app/src/main/java/lightcontainer/protocol/SbeHello.java b/app/src/main/java/lightcontainer/protocol/SbeHello.java new file mode 100644 index 0000000..af30e5b --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/SbeHello.java @@ -0,0 +1,16 @@ +package lightcontainer.protocol; + +public class SbeHello extends Protocol { + + + protected SbeHello() { + super("HELLO", "^(HELLO)\\s([A-Za-z0-9.]{5,20})\\s((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([0-5][0-9]{4})|([0-9]{1,4}))\\r\\n$"); + } + + @Override + public void execute(String cmd) { + if (matcherCheck(cmd)) { + + } + } +} diff --git a/app/src/main/resources/rules.txt b/app/src/main/resources/rules.txt index 2cfa297..511bc2b 100644 --- a/app/src/main/resources/rules.txt +++ b/app/src/main/resources/rules.txt @@ -21,9 +21,23 @@ login = [A-Za-z0-9]{2,20} sbe_hello = ^(HELLO)\s([A-Za-z0-9.]{5,20})\s((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([0-5][0-9]{4})|([0-9]{1,4}))\r\n$ //TODO \r\n -> à tester pour voir si déjà dans le flux ou doit être construit //FileFrontEnd to StorBackEnd -ffe_sendfile = ^(SENDFILE)\s([A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200})\r\n(.*)$ +ffe_sendfile = ^(SENDFILE)\s([A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200})\r\n$ sbe_sendresult = ^(SEND_OK|SEND_ERROR)\r\n$ ffe_erasefile = ^(ERASEFILE)\s([A-Za-z0-9.]{50,200})\r\n$ sbe_eraseresult = ^(ERASE_OK|ERASE_ERROR)\r\n$ ffe_retrievefile = ^(RETRIEVEFILE)\s([A-Za-z0-9.]{50,200})\r\n$ -sbe_retrieveresult = ^(RETRIEVE_OK)\s([A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200})\r\n(.*)|(RETRIEVE_ERROR)$ \ No newline at end of file +sbe_retrieveresult = ^((RETRIEVE_OK)\s([A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200})\r\n)|((RETRIEVE_ERROR)\r\n)$ + +//Client to FileFrontEnd +client_signin = ^(SIGNIN)\s([A-Za-z0-9]{2,20})\s([^\s!]{5,50})\r\n$ +client_signup = ^(SIGNUP)\s([A-Za-z0-9]{2,20})\s([^\s!]{5,50})\r\n$ +ffe_signresult = ^(SIGN_OK|SIGN_ERROR)\r\n$ +client_filelist = ^(FILELIST)\r\n$ +ffe_filelistresult = ^(FILES)\s(([^\s!]{1,20}![0-9]{1,10}){0,50})\r\n$ +client_savefile = ^(SAVE_FILE)\s([^\s!]{1,20})\s([0-9]{1,10})\r\n$ +ffe_savefileresult = ^(SAVEFILE_OK|SAVEFILE_ERROR)\r\n$ +client_getfile = ^(GETFILE)\s([^\s!]{1,20})\r\n$ +ffe_getfileresult = ^((GETFILE_OK)\s(^\s!]{1,20})\s([0-9]{1,10})\r\n)|((GETFILE_ERROR)\r\n)$ +client_removefile = ^(REMOVEFILE)\s([^\s!]{1,20})\r\n$ +ffe_removefileresult = ^(REMOVEFILE_OK|REMOVEFILE_ERROR)\r\n$ +client_signout = ^(SIGNOUT)\r\n$ \ No newline at end of file From 306a10c441ff44eb78576434759dfdcb07febf8a Mon Sep 17 00:00:00 2001 From: EndMove Date: Tue, 22 Feb 2022 11:13:22 +0100 Subject: [PATCH 10/64] =?UTF-8?q?Avanc=C3=A9e=20majeur,=20nouvelle=20struc?= =?UTF-8?q?ture=20du=20projet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 2 +- .../lightcontainer/domains/ClientHandler.java | 57 +++++++++++++++ .../lightcontainer/domains/FileFrontEnd.java | 5 -- .../java/lightcontainer/domains/Server.java | 58 ++++++++++++++++ .../domains/StoreProcessor.java | 37 ++++++++++ .../java/lightcontainer/domains/Task.java | 17 +++++ .../enumerations/TaskStatus.java | 8 +++ .../lightcontainer/enumerations/TaskType.java | 7 ++ .../interfaces/ClientHandlerFFE.java | 4 ++ .../interfaces/StoreProcessorFFE.java | 4 ++ .../repository/ClientHandlerRepository.java | 20 ++++++ .../repository/FileFrontEnd.java | 18 +++++ .../repository/StoreProcessingRepository.java | 5 ++ .../lightcontainer/utils/FileReceiver.java | 37 ++++++++++ .../java/lightcontainer/utils/FileSender.java | 35 ++++++++++ .../java/lightcontainer/utils/NetChooser.java | 69 +++++++++++++++++++ 16 files changed, 377 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/lightcontainer/domains/ClientHandler.java delete mode 100644 app/src/main/java/lightcontainer/domains/FileFrontEnd.java create mode 100644 app/src/main/java/lightcontainer/domains/Server.java create mode 100644 app/src/main/java/lightcontainer/domains/StoreProcessor.java create mode 100644 app/src/main/java/lightcontainer/domains/Task.java create mode 100644 app/src/main/java/lightcontainer/enumerations/TaskStatus.java create mode 100644 app/src/main/java/lightcontainer/enumerations/TaskType.java create mode 100644 app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java create mode 100644 app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java create mode 100644 app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java create mode 100644 app/src/main/java/lightcontainer/repository/FileFrontEnd.java create mode 100644 app/src/main/java/lightcontainer/repository/StoreProcessingRepository.java create mode 100644 app/src/main/java/lightcontainer/utils/FileReceiver.java create mode 100644 app/src/main/java/lightcontainer/utils/FileSender.java create mode 100644 app/src/main/java/lightcontainer/utils/NetChooser.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 3e79c5f..5821b2f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,5 +4,5 @@ - + \ No newline at end of file diff --git a/app/src/main/java/lightcontainer/domains/ClientHandler.java b/app/src/main/java/lightcontainer/domains/ClientHandler.java new file mode 100644 index 0000000..6c968b9 --- /dev/null +++ b/app/src/main/java/lightcontainer/domains/ClientHandler.java @@ -0,0 +1,57 @@ +package lightcontainer.domains; + +import lightcontainer.interfaces.ClientHandlerFFE; + +import java.io.*; +import java.net.Socket; +import java.nio.charset.StandardCharsets; + +/**TODO + * Connexion avec le client. (type server) + */ +public class ClientHandler implements Runnable { + // Variables + private ClientHandlerFFE fileFrontEnd; + private final Socket client; + private BufferedReader reader; + private PrintWriter writer; + + // Constructor + public ClientHandler(Socket client, ClientHandlerFFE ffe) { + this.fileFrontEnd = ffe; + this.client = client; + initClient(); + } + + /** + * Initializes socket input/output + */ + private void initClient() { + try { + this.reader = new BufferedReader(new InputStreamReader( + this.client.getInputStream(), + StandardCharsets.UTF_8 + )); + this.writer = new PrintWriter(new OutputStreamWriter( + this.client.getOutputStream(), + StandardCharsets.UTF_8 + ), true); + } catch (IOException e) { + e.printStackTrace(); + } + } + + // Thread Function + @Override + public void run() { + while (true) { + try { + String command = this.reader.readLine(); + // TODO gestion de la réception de commandes, fichier, ... + if (command != null) System.out.println(command); + } catch (IOException e) { + e.printStackTrace(); + } + } + } +} diff --git a/app/src/main/java/lightcontainer/domains/FileFrontEnd.java b/app/src/main/java/lightcontainer/domains/FileFrontEnd.java deleted file mode 100644 index 6916615..0000000 --- a/app/src/main/java/lightcontainer/domains/FileFrontEnd.java +++ /dev/null @@ -1,5 +0,0 @@ -package lightcontainer.domains; - -public class FileFrontEnd { - -} diff --git a/app/src/main/java/lightcontainer/domains/Server.java b/app/src/main/java/lightcontainer/domains/Server.java new file mode 100644 index 0000000..5c32cd1 --- /dev/null +++ b/app/src/main/java/lightcontainer/domains/Server.java @@ -0,0 +1,58 @@ +package lightcontainer.domains; + +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; + +public class Server { + // Variables + private ServerSocket server; + private final int server_port; + private boolean server_run; + + // Constructor + public Server(int port) { + this.server_port = port; + this.server_run = false; + } + + /** + * Initializes the server and starts it on the previously selected port. + * + * @since 1.0 + * + * @see Thread#start() + * @see ClientHandler + */ + public void start() { + try { + this.server = new ServerSocket(this.server_port); + while (server_run) { + // Accepting connection requests (blocking) + Socket client = this.server.accept(); + // Create a new Handler client by passing these dependencies to it + ClientHandler clientHandler = new ClientHandler(client, null); // TODO passer FileFrontEnd ou faire ca dans le repository ?! + // Add the client handler to its repository (clienthandlerrepository) + // this.repository.add(clientHandler); TODO REPOSITORY + // Start the thread + (new Thread(clientHandler)).start(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Stops the server and terminates the new connection. + * + * @since 1.0 + */ + public void stop() { + if (this.server_run) { + try { + this.server_run = false; + this.server.close(); + } catch (IOException ignored) { } + } + } +} diff --git a/app/src/main/java/lightcontainer/domains/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/StoreProcessor.java new file mode 100644 index 0000000..8861929 --- /dev/null +++ b/app/src/main/java/lightcontainer/domains/StoreProcessor.java @@ -0,0 +1,37 @@ +package lightcontainer.domains; + +import lightcontainer.interfaces.StoreProcessorFFE; + +import java.net.Socket; + +/** + * StoreProcessor + * + * Class communicating with the storebackend and + * processing the tasks in the FileFrontEnd + * + * @version 1.0 + * @since 1.0 + * + * @see Runnable + * @author Jérémi NIHART + */ +public class StoreProcessor implements Runnable { + // Variables + private StoreProcessorFFE fileFrontEnd; + + // Constructor + public StoreProcessor(Socket socket, StoreProcessorFFE fileFrontEnd) { + this.fileFrontEnd = fileFrontEnd; + } + + /** + * Start the dialogue with the storebackend. + * + * @since 1.0 + */ + @Override + public void run() { + + } +} diff --git a/app/src/main/java/lightcontainer/domains/Task.java b/app/src/main/java/lightcontainer/domains/Task.java new file mode 100644 index 0000000..6cd8fc0 --- /dev/null +++ b/app/src/main/java/lightcontainer/domains/Task.java @@ -0,0 +1,17 @@ +package lightcontainer.domains; + +import lightcontainer.enumerations.TaskStatus; +import lightcontainer.enumerations.TaskType; + +public class Task { + // Variables + private TaskType type; + private TaskStatus status; + private String command; + private String client; + private String store; + + public Task() { + + } +} diff --git a/app/src/main/java/lightcontainer/enumerations/TaskStatus.java b/app/src/main/java/lightcontainer/enumerations/TaskStatus.java new file mode 100644 index 0000000..64261f9 --- /dev/null +++ b/app/src/main/java/lightcontainer/enumerations/TaskStatus.java @@ -0,0 +1,8 @@ +package lightcontainer.enumerations; + +public enum TaskStatus { + PENDING, + PROCESSING, + ERROR, + SUCCESS +} diff --git a/app/src/main/java/lightcontainer/enumerations/TaskType.java b/app/src/main/java/lightcontainer/enumerations/TaskType.java new file mode 100644 index 0000000..3d4054c --- /dev/null +++ b/app/src/main/java/lightcontainer/enumerations/TaskType.java @@ -0,0 +1,7 @@ +package lightcontainer.enumerations; + +public enum TaskType { + SEND, + RECEIVE, + DELETE +} diff --git a/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java b/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java new file mode 100644 index 0000000..a1783f7 --- /dev/null +++ b/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java @@ -0,0 +1,4 @@ +package lightcontainer.interfaces; + +public interface ClientHandlerFFE { +} diff --git a/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java b/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java new file mode 100644 index 0000000..e6fde95 --- /dev/null +++ b/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java @@ -0,0 +1,4 @@ +package lightcontainer.interfaces; + +public interface StoreProcessorFFE { +} diff --git a/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java new file mode 100644 index 0000000..66f183b --- /dev/null +++ b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java @@ -0,0 +1,20 @@ +package lightcontainer.repository; + +import lightcontainer.domains.ClientHandler; + +import java.util.ArrayList; +import java.util.List; + +public class ClientHandlerRepository { + // Variable + private final List handlers = new ArrayList<>(); + + // Constructor + public ClientHandlerRepository() { + + } + + public void addClient(ClientHandler client) { + this.handlers.add(client); + } +} diff --git a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java new file mode 100644 index 0000000..1f5b17d --- /dev/null +++ b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java @@ -0,0 +1,18 @@ +package lightcontainer.repository; + +import lightcontainer.domains.Task; +import lightcontainer.interfaces.ClientHandlerFFE; +import lightcontainer.interfaces.StoreProcessorFFE; + +import java.util.Deque; +import java.util.LinkedList; + +public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { + // Variables + private Deque tasks = new LinkedList<>(); + + // Constructor + public FileFrontEnd() { + + } +} diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessingRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessingRepository.java new file mode 100644 index 0000000..39912ef --- /dev/null +++ b/app/src/main/java/lightcontainer/repository/StoreProcessingRepository.java @@ -0,0 +1,5 @@ +package lightcontainer.repository; + +public class StoreProcessingRepository { + +} diff --git a/app/src/main/java/lightcontainer/utils/FileReceiver.java b/app/src/main/java/lightcontainer/utils/FileReceiver.java new file mode 100644 index 0000000..c59452f --- /dev/null +++ b/app/src/main/java/lightcontainer/utils/FileReceiver.java @@ -0,0 +1,37 @@ +package lightcontainer.utils; + +import java.io.BufferedOutputStream; +import java.io.FileOutputStream; +import java.io.InputStream; + +public class FileReceiver { + private static final int DEFAULT_BUFFER = 8000; + private String path; + + public FileReceiver(String path) { this.path = path; } + + public boolean receiveFile(InputStream input, String fileName, long fileSize) { + int bytesReceived = 0; + BufferedOutputStream bosFile = null; + + try { + byte[] buffer = new byte[DEFAULT_BUFFER]; + bosFile = new BufferedOutputStream(new FileOutputStream(String.format("%s/%s", path, fileName))); + long currentOffset = 0; + + while((currentOffset < fileSize) && ((bytesReceived = input.read(buffer)) > 0)) { + bosFile.write(buffer, 0, bytesReceived); + currentOffset += bytesReceived; + } + bosFile.flush(); + bosFile.close(); + + return true; + } catch(Exception ex) { + ex.printStackTrace(); + if(bosFile != null) { try { bosFile.close(); } catch(Exception e) {} } + return false; + } + } + +} diff --git a/app/src/main/java/lightcontainer/utils/FileSender.java b/app/src/main/java/lightcontainer/utils/FileSender.java new file mode 100644 index 0000000..92f93f3 --- /dev/null +++ b/app/src/main/java/lightcontainer/utils/FileSender.java @@ -0,0 +1,35 @@ +package lightcontainer.utils; + +import java.io.*; + +public class FileSender { + private static final int DEFAULT_BUFFER=8000; + private String path; + + public FileSender(String path) { this.path = path; } + + public boolean sendFile(String filename, OutputStream out) { + BufferedInputStream bisFile = null; + int bytesReaded = 0; + + try { + File f = new File(String.format("%s/%s", path, filename)); + long fileSize = f.length(); + if(f.exists()) { + byte[] buffer = new byte[DEFAULT_BUFFER]; + bisFile = new BufferedInputStream(new FileInputStream(f)); + long currentOffset = 0; + while((currentOffset < fileSize) && (bytesReaded = bisFile.read(buffer)) > 0) { + out.write(buffer, 0, bytesReaded); out.flush(); + currentOffset+= bytesReaded; + } + bisFile.close(); + return true; + } else + return false; + } catch(IOException ex) { + ex.printStackTrace(); + return false; + } + } +} \ No newline at end of file diff --git a/app/src/main/java/lightcontainer/utils/NetChooser.java b/app/src/main/java/lightcontainer/utils/NetChooser.java new file mode 100644 index 0000000..f9ecd98 --- /dev/null +++ b/app/src/main/java/lightcontainer/utils/NetChooser.java @@ -0,0 +1,69 @@ +package lightcontainer.utils; + +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Scanner; + +public class NetChooser { + private List interfaces; + + public NetChooser() { + loadInterfaces(); + Scanner console = new Scanner(System.in); + String[] allInterfaceNames = getInterfaces(); + for(int index=0; index < allInterfaceNames.length; ++index) { + System.out.printf("%d. %s\n", index, allInterfaceNames[index]); + } + System.out.printf("Select your interface :"); + NetworkInterface selected = getInterfacesByIndex(console.nextInt()); + System.out.printf("Selected interface: %s\n", selected.getDisplayName()); + + } + + private void loadInterfaces() { + try { + interfaces = new ArrayList<>(); + Enumeration discoveredInterfaces = NetworkInterface.getNetworkInterfaces(); + while (discoveredInterfaces.hasMoreElements()) { + NetworkInterface currentInterface = discoveredInterfaces.nextElement(); + Enumeration inetAddresses = currentInterface.getInetAddresses(); + int ipCount = 0; + while(inetAddresses.hasMoreElements()) { + InetAddress currentAddress = inetAddresses.nextElement(); + ipCount++; + } + if(ipCount > 0) + interfaces.add(currentInterface); + } + } catch(SocketException ex) { + ex.printStackTrace(); + } + + } + + public NetworkInterface getInterfacesByIndex(int i) { + if(i >= 0) + return interfaces.get(i); + else + return null; + } + + public String[] getInterfaces() { + if(interfaces.size() > 0) { + String[] result = new String[interfaces.size()]; + for (int i = 0; i < interfaces.size(); ++i) { + result[i] = interfaces.get(i).getDisplayName(); + } + return result; + } else + return null; + } + + public static void main(String[] args) { + new NetChooser(); + } +} \ No newline at end of file From ec8a58044d02abb39ab3aac6d77547c18f9fba72 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 22 Feb 2022 11:13:46 +0100 Subject: [PATCH 11/64] =?UTF-8?q?Regex=20:=20Client=20to=20FileFrontEnd=20?= =?UTF-8?q?impl=C3=A9mentation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/ClientFileList.java | 12 ++++++ .../protocol/ClientGetFile.java | 12 ++++++ .../protocol/ClientRemoveFile.java | 13 +++++++ .../protocol/ClientSaveFile.java | 12 ++++++ .../lightcontainer/protocol/ClientSignIn.java | 13 +++++++ .../protocol/ClientSignOut.java | 12 ++++++ .../lightcontainer/protocol/ClientSignUp.java | 12 ++++++ .../protocol/SbeEraseResult.java | 12 ++++++ .../lightcontainer/protocol/SbeHello.java | 2 +- .../protocol/SbeRetrieveResult.java | 12 ++++++ .../protocol/SbeSendResult.java | 13 +++++++ app/src/main/resources/rules.txt | 38 +++++++++---------- 12 files changed, 143 insertions(+), 20 deletions(-) create mode 100644 app/src/main/java/lightcontainer/protocol/ClientFileList.java create mode 100644 app/src/main/java/lightcontainer/protocol/ClientGetFile.java create mode 100644 app/src/main/java/lightcontainer/protocol/ClientRemoveFile.java create mode 100644 app/src/main/java/lightcontainer/protocol/ClientSaveFile.java create mode 100644 app/src/main/java/lightcontainer/protocol/ClientSignIn.java create mode 100644 app/src/main/java/lightcontainer/protocol/ClientSignOut.java create mode 100644 app/src/main/java/lightcontainer/protocol/ClientSignUp.java create mode 100644 app/src/main/java/lightcontainer/protocol/SbeEraseResult.java create mode 100644 app/src/main/java/lightcontainer/protocol/SbeRetrieveResult.java create mode 100644 app/src/main/java/lightcontainer/protocol/SbeSendResult.java diff --git a/app/src/main/java/lightcontainer/protocol/ClientFileList.java b/app/src/main/java/lightcontainer/protocol/ClientFileList.java new file mode 100644 index 0000000..c88f72f --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ClientFileList.java @@ -0,0 +1,12 @@ +package lightcontainer.protocol; + +public class ClientFileList extends Protocol{ + protected ClientFileList() { + super("FILELIST", "^FILELIST\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/ClientGetFile.java b/app/src/main/java/lightcontainer/protocol/ClientGetFile.java new file mode 100644 index 0000000..4b0fa24 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ClientGetFile.java @@ -0,0 +1,12 @@ +package lightcontainer.protocol; + +public class ClientGetFile extends Protocol{ + protected ClientGetFile() { + super("GETFILE","^GETFILE ([^ !]{1,20})\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/ClientRemoveFile.java b/app/src/main/java/lightcontainer/protocol/ClientRemoveFile.java new file mode 100644 index 0000000..dd5375b --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ClientRemoveFile.java @@ -0,0 +1,13 @@ +package lightcontainer.protocol; + +public class ClientRemoveFile extends Protocol{ + + protected ClientRemoveFile() { + super("REMOVEFILE", "^REMOVEFILE ([^ !]{1,20})\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/ClientSaveFile.java b/app/src/main/java/lightcontainer/protocol/ClientSaveFile.java new file mode 100644 index 0000000..a3b7b11 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ClientSaveFile.java @@ -0,0 +1,12 @@ +package lightcontainer.protocol; + +public class ClientSaveFile extends Protocol { + protected ClientSaveFile() { + super("SAVEFILE", "^SAVE_FILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/ClientSignIn.java b/app/src/main/java/lightcontainer/protocol/ClientSignIn.java new file mode 100644 index 0000000..43edf56 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ClientSignIn.java @@ -0,0 +1,13 @@ +package lightcontainer.protocol; + +public class ClientSignIn extends Protocol { + + protected ClientSignIn() { + super("SIGNIN", "^(SIGNIN) ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/ClientSignOut.java b/app/src/main/java/lightcontainer/protocol/ClientSignOut.java new file mode 100644 index 0000000..909b047 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ClientSignOut.java @@ -0,0 +1,12 @@ +package lightcontainer.protocol; + +public class ClientSignOut extends Protocol { + protected ClientSignOut() { + super("SIGNOUT", "^SIGNOUT\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/ClientSignUp.java b/app/src/main/java/lightcontainer/protocol/ClientSignUp.java new file mode 100644 index 0000000..91c67d3 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ClientSignUp.java @@ -0,0 +1,12 @@ +package lightcontainer.protocol; + +public class ClientSignUp extends Protocol{ + protected ClientSignUp() { + super("SIGNUP","^(SIGNUP) ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/SbeEraseResult.java b/app/src/main/java/lightcontainer/protocol/SbeEraseResult.java new file mode 100644 index 0000000..301edd8 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/SbeEraseResult.java @@ -0,0 +1,12 @@ +package lightcontainer.protocol; + +public class SbeEraseResult extends Protocol { + protected SbeEraseResult() { + super("ERASERESULT", "^(ERASE_OK|ERASE_ERROR)\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/SbeHello.java b/app/src/main/java/lightcontainer/protocol/SbeHello.java index af30e5b..6cd750a 100644 --- a/app/src/main/java/lightcontainer/protocol/SbeHello.java +++ b/app/src/main/java/lightcontainer/protocol/SbeHello.java @@ -4,7 +4,7 @@ public class SbeHello extends Protocol { protected SbeHello() { - super("HELLO", "^(HELLO)\\s([A-Za-z0-9.]{5,20})\\s((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([0-5][0-9]{4})|([0-9]{1,4}))\\r\\n$"); + super("HELLO", "^(HELLO) ([A-Za-z0-9.]{5,20}) ([\\d]{0,5})\r\n$"); } @Override diff --git a/app/src/main/java/lightcontainer/protocol/SbeRetrieveResult.java b/app/src/main/java/lightcontainer/protocol/SbeRetrieveResult.java new file mode 100644 index 0000000..091cca2 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/SbeRetrieveResult.java @@ -0,0 +1,12 @@ +package lightcontainer.protocol; + +public class SbeRetrieveResult extends Protocol { + protected SbeRetrieveResult() { + super("RETTRIEVERESULT", "^((RETRIEVE_OK) ([A-Za-z0-9.]{50,200} [0-9]{1,10} [A-Za-z0-9.]{50,200})\r\n)|((RETRIEVE_ERROR)\r\n)$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/java/lightcontainer/protocol/SbeSendResult.java b/app/src/main/java/lightcontainer/protocol/SbeSendResult.java new file mode 100644 index 0000000..48279e1 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/SbeSendResult.java @@ -0,0 +1,13 @@ +package lightcontainer.protocol; + +public class SbeSendResult extends Protocol { + + protected SbeSendResult() { + super("SENDRESULT", "^(SEND_OK|SEND_ERROR)\r\n$"); + } + + @Override + public void execute(String cmd) { + + } +} diff --git a/app/src/main/resources/rules.txt b/app/src/main/resources/rules.txt index 511bc2b..e5d69af 100644 --- a/app/src/main/resources/rules.txt +++ b/app/src/main/resources/rules.txt @@ -4,40 +4,40 @@ port = (6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9 size = [0-9]{1,10} line = \r\n visiblechar = \p{Print} -passchar = [^\s!] +passchar = [^ !] binary = . -password = [^\s!]{5,50} -bl = \s +password = [^ !]{5,50} +bl = //espace letter = [A-Za-z] digit_letter = [A-Za-z0-9] -filename = [^\s!]{1,20} +filename = [^ !]{1,20} domain = [A-Za-z0-9.]{5,20} hash_filename = [A-Za-z0-9.]{50,200} hash_filecontent = [A-Za-z0-9.]{50,200} -file_info = [A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200} +file_info = [A-Za-z0-9.]{50,200} [0-9]{1,10} [A-Za-z0-9.]{50,200} login = [A-Za-z0-9]{2,20} //StorBackEnd to FileFrontEnd -sbe_hello = ^(HELLO)\s([A-Za-z0-9.]{5,20})\s((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([0-5][0-9]{4})|([0-9]{1,4}))\r\n$ //TODO \r\n -> à tester pour voir si déjà dans le flux ou doit être construit +sbe_hello = ^HELLO ([A-Za-z0-9.]{5,20}) ([\d]{0,5})\r\n$ //TODO \r\n -> à tester pour voir si déjà dans le flux ou doit être construit //FileFrontEnd to StorBackEnd -ffe_sendfile = ^(SENDFILE)\s([A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200})\r\n$ +ffe_sendfile = ^SENDFILE ([A-Za-z0-9.]{50,200} [0-9]{1,10} [A-Za-z0-9.]{50,200})\r\n$ sbe_sendresult = ^(SEND_OK|SEND_ERROR)\r\n$ -ffe_erasefile = ^(ERASEFILE)\s([A-Za-z0-9.]{50,200})\r\n$ +ffe_erasefile = ^ERASEFILE ([A-Za-z0-9.]{50,200})\r\n$ sbe_eraseresult = ^(ERASE_OK|ERASE_ERROR)\r\n$ -ffe_retrievefile = ^(RETRIEVEFILE)\s([A-Za-z0-9.]{50,200})\r\n$ -sbe_retrieveresult = ^((RETRIEVE_OK)\s([A-Za-z0-9.]{50,200}\s[0-9]{1,10}\s[A-Za-z0-9.]{50,200})\r\n)|((RETRIEVE_ERROR)\r\n)$ +ffe_retrievefile = ^RETRIEVEFILE ([A-Za-z0-9.]{50,200})\r\n$ +sbe_retrieveresult = ^(RETRIEVE_OK ([A-Za-z0-9.]{50,200} [0-9]{1,10} [A-Za-z0-9.]{50,200})\r\n)|(RETRIEVE_ERROR\r\n)$ //Client to FileFrontEnd -client_signin = ^(SIGNIN)\s([A-Za-z0-9]{2,20})\s([^\s!]{5,50})\r\n$ -client_signup = ^(SIGNUP)\s([A-Za-z0-9]{2,20})\s([^\s!]{5,50})\r\n$ +client_signin = ^SIGNIN ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$ +client_signup = ^SIGNUP ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$ ffe_signresult = ^(SIGN_OK|SIGN_ERROR)\r\n$ -client_filelist = ^(FILELIST)\r\n$ -ffe_filelistresult = ^(FILES)\s(([^\s!]{1,20}![0-9]{1,10}){0,50})\r\n$ -client_savefile = ^(SAVE_FILE)\s([^\s!]{1,20})\s([0-9]{1,10})\r\n$ +client_filelist = ^FILELIST\r\n$ +ffe_filelistresult = ^FILES(( [^ !]{1,20})!([0-9]{1,10})){0,50}$ +client_savefile = ^SAVE_FILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$ ffe_savefileresult = ^(SAVEFILE_OK|SAVEFILE_ERROR)\r\n$ -client_getfile = ^(GETFILE)\s([^\s!]{1,20})\r\n$ -ffe_getfileresult = ^((GETFILE_OK)\s(^\s!]{1,20})\s([0-9]{1,10})\r\n)|((GETFILE_ERROR)\r\n)$ -client_removefile = ^(REMOVEFILE)\s([^\s!]{1,20})\r\n$ +client_getfile = ^GETFILE ([^ !]{1,20})\r\n$ +ffe_getfileresult = ^(GETFILE_OK (^ !]{1,20}) ([0-9]{1,10})\r\n)|(GETFILE_ERROR\r\n)$ +client_removefile = ^REMOVEFILE ([^ !]{1,20})\r\n$ ffe_removefileresult = ^(REMOVEFILE_OK|REMOVEFILE_ERROR)\r\n$ -client_signout = ^(SIGNOUT)\r\n$ \ No newline at end of file +client_signout = ^SIGNOUT\r\n$ \ No newline at end of file From 083586682f162a3c4469a41e6c297c63d0a927b0 Mon Sep 17 00:00:00 2001 From: EndMove Date: Tue, 22 Feb 2022 12:32:03 +0100 Subject: [PATCH 12/64] =?UTF-8?q?Mise=20en=20place=20d'un=20syst=C3=A8me?= =?UTF-8?q?=20pour=20autoclose=20le=20ClientHandler=20et=20StoreProcessor?= =?UTF-8?q?=20+=20quelques=20corrections=20+=20avanc=C3=A9e=20mineures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/domains/ClientHandler.java | 44 ++++++++++++-- .../domains/StoreMulticastRunnable.java | 1 + .../domains/StoreProcessor.java | 60 +++++++++++++++++-- .../repository/FileFrontEnd.java | 2 + .../repository/StoreProcessingRepository.java | 5 -- .../repository/StoreProcessorRepository.java | 5 ++ 6 files changed, 102 insertions(+), 15 deletions(-) delete mode 100644 app/src/main/java/lightcontainer/repository/StoreProcessingRepository.java create mode 100644 app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java diff --git a/app/src/main/java/lightcontainer/domains/ClientHandler.java b/app/src/main/java/lightcontainer/domains/ClientHandler.java index 6c968b9..8c1fb15 100644 --- a/app/src/main/java/lightcontainer/domains/ClientHandler.java +++ b/app/src/main/java/lightcontainer/domains/ClientHandler.java @@ -6,13 +6,24 @@ import java.io.*; import java.net.Socket; import java.nio.charset.StandardCharsets; -/**TODO - * Connexion avec le client. (type server) +/** + * ClientHandler + * + * Class communicating with the client, and + * intercepting and sending files to the client. + * + * @version 1.0 + * @since 1.0 + * + * @see Runnable + * @see AutoCloseable + * @author Jérémi NIHART */ -public class ClientHandler implements Runnable { +public class ClientHandler implements Runnable, AutoCloseable { // Variables private ClientHandlerFFE fileFrontEnd; private final Socket client; + private BufferedReader reader; private PrintWriter writer; @@ -24,7 +35,12 @@ public class ClientHandler implements Runnable { } /** - * Initializes socket input/output + * Initialise the Client's Reader and Writer. + * + * @since 1.0 + * + * @see BufferedReader + * @see PrintWriter */ private void initClient() { try { @@ -41,17 +57,33 @@ public class ClientHandler implements Runnable { } } - // Thread Function + /** + * Thread Function + * Start the dialogue with the client. + * + * @since 1.0 + */ @Override public void run() { while (true) { try { String command = this.reader.readLine(); // TODO gestion de la réception de commandes, fichier, ... - if (command != null) System.out.println(command); + if (command != null) System.out.println("Client: " + command); } catch (IOException e) { e.printStackTrace(); } } } + + /** + * AutoClosable Function + * Close the Client thread and resources. + * + * @since 1.0 + */ + @Override + public void close() { + + } } diff --git a/app/src/main/java/lightcontainer/domains/StoreMulticastRunnable.java b/app/src/main/java/lightcontainer/domains/StoreMulticastRunnable.java index f6aede3..835b0dd 100644 --- a/app/src/main/java/lightcontainer/domains/StoreMulticastRunnable.java +++ b/app/src/main/java/lightcontainer/domains/StoreMulticastRunnable.java @@ -52,6 +52,7 @@ public class StoreMulticastRunnable implements Runnable { while(true) { listener.receive(packet); String data = new String(packet.getData(), 0, packet.getLength()); + System.out.println(data); // TODO ajouter un controller et lui signaler qu'il y a un nouveau StoreBackEnd } } catch (Exception ignore) { } diff --git a/app/src/main/java/lightcontainer/domains/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/StoreProcessor.java index 8861929..fb8ea2c 100644 --- a/app/src/main/java/lightcontainer/domains/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/StoreProcessor.java @@ -2,7 +2,9 @@ package lightcontainer.domains; import lightcontainer.interfaces.StoreProcessorFFE; +import java.io.*; import java.net.Socket; +import java.nio.charset.StandardCharsets; /** * StoreProcessor @@ -14,24 +16,74 @@ import java.net.Socket; * @since 1.0 * * @see Runnable + * @see AutoCloseable * @author Jérémi NIHART */ -public class StoreProcessor implements Runnable { +public class StoreProcessor implements Runnable, AutoCloseable { // Variables - private StoreProcessorFFE fileFrontEnd; + private final StoreProcessorFFE fileFrontEnd; + private final Socket store; + + private BufferedReader reader; + private PrintWriter writer; // Constructor - public StoreProcessor(Socket socket, StoreProcessorFFE fileFrontEnd) { - this.fileFrontEnd = fileFrontEnd; + public StoreProcessor(Socket socket, StoreProcessorFFE ffe) { + this.fileFrontEnd = ffe; + this.store = socket; + initStore(); } /** + * Initialise the Store's Reader and Writer. + * + * @since 1.0 + * + * @see BufferedReader + * @see PrintWriter + */ + private void initStore() { + try { + this.reader = new BufferedReader(new InputStreamReader( + this.store.getInputStream(), + StandardCharsets.UTF_8 + )); + this.writer = new PrintWriter(new OutputStreamWriter( + this.store.getOutputStream(), + StandardCharsets.UTF_8 + ), true); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Thread Function * Start the dialogue with the storebackend. * * @since 1.0 */ @Override public void run() { + while (true) { + try { + String command = this.reader.readLine(); + // TODO gestion de la réception de commandes, fichier, ... + if (command != null) System.out.println("StoreBackEnd: " + command); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + /** + * AutoClosable Function + * Close the Storage thread and resources. + * + * @since 1.0 + */ + @Override + public void close() { } } diff --git a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java index 1f5b17d..b4db479 100644 --- a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java +++ b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java @@ -10,6 +10,8 @@ import java.util.LinkedList; public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { // Variables private Deque tasks = new LinkedList<>(); + private ClientHandlerRepository clientRepository; // TODO -> pourquoi pas une interface ? end + private StoreProcessorRepository storeRepository; // TODO -> pourquoi pas une interface ? end // Constructor public FileFrontEnd() { diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessingRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessingRepository.java deleted file mode 100644 index 39912ef..0000000 --- a/app/src/main/java/lightcontainer/repository/StoreProcessingRepository.java +++ /dev/null @@ -1,5 +0,0 @@ -package lightcontainer.repository; - -public class StoreProcessingRepository { - -} diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java new file mode 100644 index 0000000..a330360 --- /dev/null +++ b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java @@ -0,0 +1,5 @@ +package lightcontainer.repository; + +public class StoreProcessorRepository { + +} From e77076002912cb6996b52e39a29e8e0588e2434b Mon Sep 17 00:00:00 2001 From: EndMove Date: Sat, 26 Feb 2022 12:25:03 +0100 Subject: [PATCH 13/64] =?UTF-8?q?Id=C3=A9e=20test=20synchronisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lightcontainer/domains/Task.java | 2 +- .../interfaces/StoreProcessorFFE.java | 9 +++++++ .../repository/FileFrontEnd.java | 27 +++++++++++++++++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/lightcontainer/domains/Task.java b/app/src/main/java/lightcontainer/domains/Task.java index 6cd8fc0..45494c8 100644 --- a/app/src/main/java/lightcontainer/domains/Task.java +++ b/app/src/main/java/lightcontainer/domains/Task.java @@ -9,7 +9,7 @@ public class Task { private TaskStatus status; private String command; private String client; - private String store; + private String storeDomain; public Task() { diff --git a/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java b/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java index e6fde95..7a5ffb6 100644 --- a/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java +++ b/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java @@ -1,4 +1,13 @@ package lightcontainer.interfaces; +import lightcontainer.domains.StoreProcessor; + public interface StoreProcessorFFE { + + /** + * Permet à un {@link StoreProcessor} d'avertir le FFE qu'il est disponible + * @param store + */ + void onStoreAvailable(StoreProcessor store); + } diff --git a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java index b4db479..d7dfde2 100644 --- a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java +++ b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java @@ -1,20 +1,43 @@ package lightcontainer.repository; +import lightcontainer.domains.ClientHandler; +import lightcontainer.domains.StoreProcessor; import lightcontainer.domains.Task; import lightcontainer.interfaces.ClientHandlerFFE; import lightcontainer.interfaces.StoreProcessorFFE; +import java.util.Collections; import java.util.Deque; import java.util.LinkedList; +import java.util.concurrent.ConcurrentLinkedDeque; public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { // Variables - private Deque tasks = new LinkedList<>(); + private Deque tasks = new ConcurrentLinkedDeque<>(); private ClientHandlerRepository clientRepository; // TODO -> pourquoi pas une interface ? end private StoreProcessorRepository storeRepository; // TODO -> pourquoi pas une interface ? end // Constructor - public FileFrontEnd() { + public FileFrontEnd(ClientHandlerRepository clientRepo, StoreProcessorRepository storeRepo) { + this.clientRepository = clientRepo; + this.storeRepository = storeRepo; + } + + /** + * Appelé quand nouvelle tâche + */ + public void alertStoreProcessors(Task task) { + // On avertit les stor processors d'une nouvelle tâche + + } + + /** + * Permet à un {@link StoreProcessor} d'avertir le FFE qu'il est disponible + * + * @param store + */ + @Override + public void onStoreAvailable(StoreProcessor store) { } } From d7b66f092f2128dfc88e82b137f07393eac59c4f Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 12:42:13 +0100 Subject: [PATCH 14/64] =?UTF-8?q?Ajout=20event=20qui=20permet=20aux=20Stor?= =?UTF-8?q?Processor=20de=20pr=C3=A9ciser=20qu'ils=20sont=20disponibles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/lightcontainer/domains/StoreProcessor.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/lightcontainer/domains/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/StoreProcessor.java index fb8ea2c..fc4f721 100644 --- a/app/src/main/java/lightcontainer/domains/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/StoreProcessor.java @@ -67,12 +67,18 @@ public class StoreProcessor implements Runnable, AutoCloseable { public void run() { while (true) { try { + // Envoie donnée au StoreBackEnd String command = this.reader.readLine(); // TODO gestion de la réception de commandes, fichier, ... if (command != null) System.out.println("StoreBackEnd: " + command); + + // Réception donnée du StoreBackEnd } catch (IOException e) { e.printStackTrace(); } + + // Alerter le FileFrontEnd que ce store processor est disponible pour gérer de nouvelle demande + fileFrontEnd.onStoreAvailable(this); } } From ca961c04a7056477207963ea54e2791a4607a604 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 13:08:42 +0100 Subject: [PATCH 15/64] =?UTF-8?q?Cr=C3=A9ation=20interface=20pour=20les=20?= =?UTF-8?q?r=C3=A8gles=20de=20lecture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/ProtocolReader.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 app/src/main/java/lightcontainer/protocol/ProtocolReader.java diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java new file mode 100644 index 0000000..307847d --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java @@ -0,0 +1,24 @@ +package lightcontainer.protocol; + +public interface ProtocolReader { + + + /** + * Permet de récupérer le nom de la commande (ex. FILELIST, SENDRESULT) + */ + String getCmd(); + + /** + * Permet de lancer la décomposition d'une commande pour en extraire les données + * @param data Contenu de la commande + */ + void execute(String data); + + /** + * Permet de demander au protocol s'il capable de décomposer/gérer cette commande + * @param data Commande ("GETFILE" bl filename line) + * @return TRUE si ce protocol peut gérer + */ + boolean match(String data); + +} From c7af99a876d1bb4ab8694ea65d883909482cf780 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 13:27:00 +0100 Subject: [PATCH 16/64] =?UTF-8?q?Cr=C3=A9ation=20r=C3=A8gle=20de=20lecture?= =?UTF-8?q?=20HelloRule.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/HelloRule.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 app/src/main/java/lightcontainer/protocol/rules/HelloRule.java diff --git a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java new file mode 100644 index 0000000..6edb27d --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java @@ -0,0 +1,18 @@ +package lightcontainer.protocol.rules; + +import lightcontainer.protocol.ProtocolReader; + +public class HelloRule extends ProtocolReader { + private static final String PATTERN = "^HELLO ([A-Za-z0-9]{5,20}) ([0-9]{1,5})\r\n$"; + + public HelloRule() { + super(PATTERN); + } + + + @Override + protected void onExecuted(String[] data) { + + } + +} From c1fe6a0a966422604f09259c808ee091f375f694 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 13:37:38 +0100 Subject: [PATCH 17/64] =?UTF-8?q?Modification=20du=20syst=C3=A8me=20de=20P?= =?UTF-8?q?rotocolReader.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/ProtocolReader.java | 36 +++++++++++++------ .../protocol/rules/HelloRule.java | 5 ++- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java index 307847d..472dc0a 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java @@ -1,24 +1,40 @@ package lightcontainer.protocol; -public interface ProtocolReader { +import java.util.regex.Matcher; +import java.util.regex.Pattern; +public abstract class ProtocolReader { - /** - * Permet de récupérer le nom de la commande (ex. FILELIST, SENDRESULT) - */ - String getCmd(); + private final Pattern rulePattern; + + protected ProtocolReader(String pattern) { + this.rulePattern = Pattern.compile(pattern); + } /** * Permet de lancer la décomposition d'une commande pour en extraire les données * @param data Contenu de la commande */ - void execute(String data); + public boolean execute(String data) { + Matcher ruleMatcher = this.rulePattern.matcher(data); + + if (ruleMatcher.matches()) { + String[] groups = new String[ruleMatcher.groupCount()]; + + for (int i= 0; i < groups.length; ++i) + groups[i] = ruleMatcher.group(i); + + onExecuted(groups); + return true; + } + + return false; + } /** - * Permet de demander au protocol s'il capable de décomposer/gérer cette commande - * @param data Commande ("GETFILE" bl filename line) - * @return TRUE si ce protocol peut gérer + * Cette méthode est appelée lors de l'exécution de la règle + * @param data */ - boolean match(String data); + protected abstract void onExecuted(String... data); } diff --git a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java index 6edb27d..529f8f7 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java @@ -11,8 +11,11 @@ public class HelloRule extends ProtocolReader { @Override - protected void onExecuted(String[] data) { + protected void onExecuted(String... data) { + String domain = data[0]; + String port = data[1]; + System.out.printf("Règle Hello avec domain=%s et port=%s", domain, port); } } From d6751210341b6a5ea61d2e22f0949b1882168a5d Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 13:48:46 +0100 Subject: [PATCH 18/64] =?UTF-8?q?Cr=C3=A9ation=20d'un=20test=20pour=20la?= =?UTF-8?q?=20r=C3=A8gle=20HelloRule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/HelloRuleTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java diff --git a/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java b/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java new file mode 100644 index 0000000..8305c90 --- /dev/null +++ b/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java @@ -0,0 +1,20 @@ +package lightcontainer.protocol.rules; + +import lightcontainer.protocol.ProtocolReader; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class HelloRuleTest { + + @Test + public void whenRuleIsRightThenIsExecute() { + // GIVEN + ProtocolReader protocolReader = new HelloRule(); + String request = "HELLO bento 42890\r\n"; + + // EXPECT + assertTrue(protocolReader.execute(request)); + } + +} \ No newline at end of file From 978ba57237bbc1a9c7d2f7ce65eb81e47ee0eadd Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 13:50:36 +0100 Subject: [PATCH 19/64] =?UTF-8?q?-=20HelloRule.java=20:=20Ajout=20retour?= =?UTF-8?q?=20=C3=A0=20la=20ligne=20-=20ProtocolReader.java=20:=20patch=20?= =?UTF-8?q?ajout=20des=20group=20dans=20le=20tableau=20donn=C3=A9=20=C3=A0?= =?UTF-8?q?=20la=20r=C3=A8gle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/protocol/ProtocolReader.java | 4 ++-- .../main/java/lightcontainer/protocol/rules/HelloRule.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java index 472dc0a..1d45c83 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java @@ -21,8 +21,8 @@ public abstract class ProtocolReader { if (ruleMatcher.matches()) { String[] groups = new String[ruleMatcher.groupCount()]; - for (int i= 0; i < groups.length; ++i) - groups[i] = ruleMatcher.group(i); + for (int i = 1; i <= groups.length; ++i) + groups[i - 1] = ruleMatcher.group(i); onExecuted(groups); return true; diff --git a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java index 529f8f7..f4b6c8a 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java @@ -15,7 +15,7 @@ public class HelloRule extends ProtocolReader { String domain = data[0]; String port = data[1]; - System.out.printf("Règle Hello avec domain=%s et port=%s", domain, port); + System.out.printf("Règle Hello avec domain=%s et port=%s\n", domain, port); } } From 90ef2d450e5a4a0114ce68d6572a934f36e67143 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 13:54:16 +0100 Subject: [PATCH 20/64] =?UTF-8?q?-=20HelloRule.java=20:=20Ajout=20constant?= =?UTF-8?q?e=20pour=20position=20des=20donn=C3=A9es=20dans=20le=20tableau?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lightcontainer/protocol/rules/HelloRule.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java index f4b6c8a..589473e 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java @@ -3,8 +3,15 @@ package lightcontainer.protocol.rules; import lightcontainer.protocol.ProtocolReader; public class HelloRule extends ProtocolReader { + private static final String PATTERN = "^HELLO ([A-Za-z0-9]{5,20}) ([0-9]{1,5})\r\n$"; + // Index du domain dans le tableau de donnée + private static final int DOMAIN = 0; + + //Index du port dans le tableau de donnée + private static final int PORT = 1; + public HelloRule() { super(PATTERN); } @@ -12,8 +19,8 @@ public class HelloRule extends ProtocolReader { @Override protected void onExecuted(String... data) { - String domain = data[0]; - String port = data[1]; + String domain = data[DOMAIN]; + String port = data[PORT]; System.out.printf("Règle Hello avec domain=%s et port=%s\n", domain, port); } From baa13b8aa220231430bb31437c3b1fa59a2e5c39 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 13:59:41 +0100 Subject: [PATCH 21/64] =?UTF-8?q?-=20HelloRule.java=20:=20Compression=20r?= =?UTF-8?q?=C3=A9cup=C3=A9ration=20data=20-=20Suppression=20de=20l'ancienn?= =?UTF-8?q?e=20r=C3=A8gle=20HelloRule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/protocol/rules/HelloRule.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java index 589473e..30acdb9 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java @@ -19,8 +19,7 @@ public class HelloRule extends ProtocolReader { @Override protected void onExecuted(String... data) { - String domain = data[DOMAIN]; - String port = data[PORT]; + String domain = data[DOMAIN], port = data[PORT]; System.out.printf("Règle Hello avec domain=%s et port=%s\n", domain, port); } From 780c56df11a38953152b894572b123c3b46d57ef Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 14:00:40 +0100 Subject: [PATCH 22/64] =?UTF-8?q?-=20Suppression=20de=20l'ancienne=20r?= =?UTF-8?q?=C3=A8gle=20HelloRule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/protocol/HelloRule.java | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 app/src/main/java/lightcontainer/protocol/HelloRule.java diff --git a/app/src/main/java/lightcontainer/protocol/HelloRule.java b/app/src/main/java/lightcontainer/protocol/HelloRule.java deleted file mode 100644 index c9c2b94..0000000 --- a/app/src/main/java/lightcontainer/protocol/HelloRule.java +++ /dev/null @@ -1,31 +0,0 @@ -package lightcontainer.protocol; - -public class HelloRule extends Protocol { - // Variables - - // Constructor - protected HelloRule() { - super("HELLO", "HELLO "); // TODO : add the regex here (sbe_hello = "HELLO bl domain bl port line") - } - - /** - * Execute the rule on a command. - * - * This function allows you to check a command and process those groups (parameters) - * use the utility functions of {@link Protocol} to facilitate processing, see @see. - * - * @param cmd Command on which to execute the rule. - * @see Protocol#execute(String) - * @see #matcherCheck(String) - * @see #matcherGetGroups() - * @since 1.0 - */ - @Override - public void execute(String cmd) { - if (matcherCheck(cmd)) { - System.out.println("Good rule ;-) !"); - } else { - System.out.println("OUPPS unknown rule !"); - } - } -} From a883918363cdacf95d21926b853c1631832a9202 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 26 Feb 2022 14:32:59 +0100 Subject: [PATCH 23/64] Suppression protocols inutiles --- .../lightcontainer/protocol/ClientFileList.java | 12 ------------ .../lightcontainer/protocol/ClientGetFile.java | 12 ------------ .../protocol/ClientRemoveFile.java | 13 ------------- .../lightcontainer/protocol/ClientSaveFile.java | 12 ------------ .../lightcontainer/protocol/ClientSignIn.java | 13 ------------- .../lightcontainer/protocol/ClientSignOut.java | 12 ------------ .../lightcontainer/protocol/ClientSignUp.java | 12 ------------ .../lightcontainer/protocol/SbeEraseResult.java | 12 ------------ .../java/lightcontainer/protocol/SbeHello.java | 16 ---------------- .../protocol/SbeRetrieveResult.java | 12 ------------ .../lightcontainer/protocol/SbeSendResult.java | 13 ------------- 11 files changed, 139 deletions(-) delete mode 100644 app/src/main/java/lightcontainer/protocol/ClientFileList.java delete mode 100644 app/src/main/java/lightcontainer/protocol/ClientGetFile.java delete mode 100644 app/src/main/java/lightcontainer/protocol/ClientRemoveFile.java delete mode 100644 app/src/main/java/lightcontainer/protocol/ClientSaveFile.java delete mode 100644 app/src/main/java/lightcontainer/protocol/ClientSignIn.java delete mode 100644 app/src/main/java/lightcontainer/protocol/ClientSignOut.java delete mode 100644 app/src/main/java/lightcontainer/protocol/ClientSignUp.java delete mode 100644 app/src/main/java/lightcontainer/protocol/SbeEraseResult.java delete mode 100644 app/src/main/java/lightcontainer/protocol/SbeHello.java delete mode 100644 app/src/main/java/lightcontainer/protocol/SbeRetrieveResult.java delete mode 100644 app/src/main/java/lightcontainer/protocol/SbeSendResult.java diff --git a/app/src/main/java/lightcontainer/protocol/ClientFileList.java b/app/src/main/java/lightcontainer/protocol/ClientFileList.java deleted file mode 100644 index c88f72f..0000000 --- a/app/src/main/java/lightcontainer/protocol/ClientFileList.java +++ /dev/null @@ -1,12 +0,0 @@ -package lightcontainer.protocol; - -public class ClientFileList extends Protocol{ - protected ClientFileList() { - super("FILELIST", "^FILELIST\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/ClientGetFile.java b/app/src/main/java/lightcontainer/protocol/ClientGetFile.java deleted file mode 100644 index 4b0fa24..0000000 --- a/app/src/main/java/lightcontainer/protocol/ClientGetFile.java +++ /dev/null @@ -1,12 +0,0 @@ -package lightcontainer.protocol; - -public class ClientGetFile extends Protocol{ - protected ClientGetFile() { - super("GETFILE","^GETFILE ([^ !]{1,20})\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/ClientRemoveFile.java b/app/src/main/java/lightcontainer/protocol/ClientRemoveFile.java deleted file mode 100644 index dd5375b..0000000 --- a/app/src/main/java/lightcontainer/protocol/ClientRemoveFile.java +++ /dev/null @@ -1,13 +0,0 @@ -package lightcontainer.protocol; - -public class ClientRemoveFile extends Protocol{ - - protected ClientRemoveFile() { - super("REMOVEFILE", "^REMOVEFILE ([^ !]{1,20})\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/ClientSaveFile.java b/app/src/main/java/lightcontainer/protocol/ClientSaveFile.java deleted file mode 100644 index a3b7b11..0000000 --- a/app/src/main/java/lightcontainer/protocol/ClientSaveFile.java +++ /dev/null @@ -1,12 +0,0 @@ -package lightcontainer.protocol; - -public class ClientSaveFile extends Protocol { - protected ClientSaveFile() { - super("SAVEFILE", "^SAVE_FILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/ClientSignIn.java b/app/src/main/java/lightcontainer/protocol/ClientSignIn.java deleted file mode 100644 index 43edf56..0000000 --- a/app/src/main/java/lightcontainer/protocol/ClientSignIn.java +++ /dev/null @@ -1,13 +0,0 @@ -package lightcontainer.protocol; - -public class ClientSignIn extends Protocol { - - protected ClientSignIn() { - super("SIGNIN", "^(SIGNIN) ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/ClientSignOut.java b/app/src/main/java/lightcontainer/protocol/ClientSignOut.java deleted file mode 100644 index 909b047..0000000 --- a/app/src/main/java/lightcontainer/protocol/ClientSignOut.java +++ /dev/null @@ -1,12 +0,0 @@ -package lightcontainer.protocol; - -public class ClientSignOut extends Protocol { - protected ClientSignOut() { - super("SIGNOUT", "^SIGNOUT\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/ClientSignUp.java b/app/src/main/java/lightcontainer/protocol/ClientSignUp.java deleted file mode 100644 index 91c67d3..0000000 --- a/app/src/main/java/lightcontainer/protocol/ClientSignUp.java +++ /dev/null @@ -1,12 +0,0 @@ -package lightcontainer.protocol; - -public class ClientSignUp extends Protocol{ - protected ClientSignUp() { - super("SIGNUP","^(SIGNUP) ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/SbeEraseResult.java b/app/src/main/java/lightcontainer/protocol/SbeEraseResult.java deleted file mode 100644 index 301edd8..0000000 --- a/app/src/main/java/lightcontainer/protocol/SbeEraseResult.java +++ /dev/null @@ -1,12 +0,0 @@ -package lightcontainer.protocol; - -public class SbeEraseResult extends Protocol { - protected SbeEraseResult() { - super("ERASERESULT", "^(ERASE_OK|ERASE_ERROR)\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/SbeHello.java b/app/src/main/java/lightcontainer/protocol/SbeHello.java deleted file mode 100644 index 6cd750a..0000000 --- a/app/src/main/java/lightcontainer/protocol/SbeHello.java +++ /dev/null @@ -1,16 +0,0 @@ -package lightcontainer.protocol; - -public class SbeHello extends Protocol { - - - protected SbeHello() { - super("HELLO", "^(HELLO) ([A-Za-z0-9.]{5,20}) ([\\d]{0,5})\r\n$"); - } - - @Override - public void execute(String cmd) { - if (matcherCheck(cmd)) { - - } - } -} diff --git a/app/src/main/java/lightcontainer/protocol/SbeRetrieveResult.java b/app/src/main/java/lightcontainer/protocol/SbeRetrieveResult.java deleted file mode 100644 index 091cca2..0000000 --- a/app/src/main/java/lightcontainer/protocol/SbeRetrieveResult.java +++ /dev/null @@ -1,12 +0,0 @@ -package lightcontainer.protocol; - -public class SbeRetrieveResult extends Protocol { - protected SbeRetrieveResult() { - super("RETTRIEVERESULT", "^((RETRIEVE_OK) ([A-Za-z0-9.]{50,200} [0-9]{1,10} [A-Za-z0-9.]{50,200})\r\n)|((RETRIEVE_ERROR)\r\n)$"); - } - - @Override - public void execute(String cmd) { - - } -} diff --git a/app/src/main/java/lightcontainer/protocol/SbeSendResult.java b/app/src/main/java/lightcontainer/protocol/SbeSendResult.java deleted file mode 100644 index 48279e1..0000000 --- a/app/src/main/java/lightcontainer/protocol/SbeSendResult.java +++ /dev/null @@ -1,13 +0,0 @@ -package lightcontainer.protocol; - -public class SbeSendResult extends Protocol { - - protected SbeSendResult() { - super("SENDRESULT", "^(SEND_OK|SEND_ERROR)\r\n$"); - } - - @Override - public void execute(String cmd) { - - } -} From 8201d3db9120a5b5ef3e11a9d361ba41b30acc18 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 26 Feb 2022 14:41:35 +0100 Subject: [PATCH 24/64] =?UTF-8?q?ProtocolWriter=20:=20mod=C3=A8le=20pour?= =?UTF-8?q?=20r=C3=A8gles=20protocoles=20d'=C3=A9criture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/ProtocolWriter.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/src/main/java/lightcontainer/protocol/ProtocolWriter.java diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java new file mode 100644 index 0000000..c05e428 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java @@ -0,0 +1,23 @@ +package lightcontainer.protocol; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public abstract class ProtocolWriter { + + private final Pattern rulePattern; + + protected ProtocolWriter(String pattern) { + this.rulePattern = Pattern.compile(pattern); + } + + public String execute(String data) { + Matcher ruleMatcher = this.rulePattern.matcher(data); + + if (ruleMatcher.matches()) { + + } + + return null; + } +} From 0ae48806796a253197f8ed2bf1e2176f13a12305 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 26 Feb 2022 15:00:37 +0100 Subject: [PATCH 25/64] =?UTF-8?q?ProtocolWriter=20:=20mod=C3=A8le=20pour?= =?UTF-8?q?=20r=C3=A8gles=20protocoles=20d'=C3=A9criture=20termin=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/ProtocolWriter.java | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java index c05e428..051794a 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java @@ -1,23 +1,45 @@ package lightcontainer.protocol; +import java.util.StringJoiner; import java.util.regex.Matcher; import java.util.regex.Pattern; public abstract class ProtocolWriter { private final Pattern rulePattern; + private final String cmdName; - protected ProtocolWriter(String pattern) { + + protected ProtocolWriter(String cmdName, String pattern) { this.rulePattern = Pattern.compile(pattern); + this.cmdName = cmdName; } - public String execute(String data) { - Matcher ruleMatcher = this.rulePattern.matcher(data); + /** + * Permet de récupérer le nom du protocol + * @return + */ + public String getCmdName() { + return cmdName; + } - if (ruleMatcher.matches()) { + /** + * Permet de contruire une commande selon une règle établie. + * @param datas Les données à ajouter dans la commande; L'ordre défini leur position dans la commande + * @return La commande construite + */ + public String execute(String... datas) { + // Concatatène le nom de la commande avec les données (trim), avec un espace entre chaque + String command = null; + StringJoiner builder = new StringJoiner(" ", this.cmdName, ""); - } + for (String data : datas) + builder.add(data); - return null; + command = builder.toString(); + + // Vérifie que tout match (cf. Matcher). Si match alors on retourne la commande build, sinon on retourne NULL + Matcher ruleMatcher = this.rulePattern.matcher(command); + return ruleMatcher.matches() ? command : null; } } From ee867c9b1d3e8f9efd96fab3d44e2a30ebaa79fc Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 26 Feb 2022 15:07:46 +0100 Subject: [PATCH 26/64] =?UTF-8?q?SignoutRule=20cr=C3=A9=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/{ => reader}/HelloRule.java | 2 +- .../protocol/rules/writer/SignoutRule.java | 14 ++++++++++++++ .../protocol/rules/HelloRuleTest.java | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) rename app/src/main/java/lightcontainer/protocol/rules/{ => reader}/HelloRule.java (93%) create mode 100644 app/src/main/java/lightcontainer/protocol/rules/writer/SignoutRule.java diff --git a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java similarity index 93% rename from app/src/main/java/lightcontainer/protocol/rules/HelloRule.java rename to app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java index 30acdb9..a39019b 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java @@ -1,4 +1,4 @@ -package lightcontainer.protocol.rules; +package lightcontainer.protocol.rules.reader; import lightcontainer.protocol.ProtocolReader; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SignoutRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SignoutRule.java new file mode 100644 index 0000000..ff42d2c --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SignoutRule.java @@ -0,0 +1,14 @@ +package lightcontainer.protocol.rules.writer; + +import lightcontainer.protocol.ProtocolWriter; + +public class SignoutRule extends ProtocolWriter { + + private static final String PATTERN = "^SIGNOUT\r\n$"; + + public static final String NAME = "SIGNOUT"; + + public SignoutRule() { + super(NAME, PATTERN); + } +} diff --git a/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java b/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java index 8305c90..55517f4 100644 --- a/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java +++ b/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java @@ -1,6 +1,7 @@ package lightcontainer.protocol.rules; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.rules.reader.HelloRule; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; From 2c0d56b30488599ff772d4798b376a9c7bbf9a73 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 26 Feb 2022 15:12:56 +0100 Subject: [PATCH 27/64] Classe test pour SignoutRule --- .../protocol/rules/{ => reader}/HelloRuleTest.java | 2 +- .../protocol/rules/writer/SignoutRuleTest.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) rename app/src/test/java/lightcontainer/protocol/rules/{ => reader}/HelloRuleTest.java (91%) create mode 100644 app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java diff --git a/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java b/app/src/test/java/lightcontainer/protocol/rules/reader/HelloRuleTest.java similarity index 91% rename from app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java rename to app/src/test/java/lightcontainer/protocol/rules/reader/HelloRuleTest.java index 55517f4..c2a1b04 100644 --- a/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java +++ b/app/src/test/java/lightcontainer/protocol/rules/reader/HelloRuleTest.java @@ -1,4 +1,4 @@ -package lightcontainer.protocol.rules; +package lightcontainer.protocol.rules.reader; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.reader.HelloRule; diff --git a/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java b/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java new file mode 100644 index 0000000..ab427ff --- /dev/null +++ b/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java @@ -0,0 +1,7 @@ +package lightcontainer.protocol.rules.writer; + +import static org.junit.jupiter.api.Assertions.*; + +class SignoutRuleTest { + +} \ No newline at end of file From d3361a76794a3dc0df3a7db1df54359beb51fc9a Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 26 Feb 2022 15:20:05 +0100 Subject: [PATCH 28/64] =?UTF-8?q?SignoutRule=20test=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/protocol/ProtocolWriter.java | 2 +- .../protocol/rules/writer/SignoutRuleTest.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java index 051794a..4605a30 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java @@ -31,7 +31,7 @@ public abstract class ProtocolWriter { public String execute(String... datas) { // Concatatène le nom de la commande avec les données (trim), avec un espace entre chaque String command = null; - StringJoiner builder = new StringJoiner(" ", this.cmdName, ""); + StringJoiner builder = new StringJoiner(" ", this.cmdName, "\r\n"); for (String data : datas) builder.add(data); diff --git a/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java b/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java index ab427ff..31bf799 100644 --- a/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java +++ b/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java @@ -1,7 +1,21 @@ package lightcontainer.protocol.rules.writer; +import lightcontainer.protocol.ProtocolWriter; +import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.*; class SignoutRuleTest { + @Test + public void whenRuleIsRightThenReturnCommand() { + //GIVEN + ProtocolWriter protocolWriter = new SignoutRule(); + String[] datas = {}; + + //EXPECT + assertNotNull(protocolWriter.execute(datas)); + assertEquals("SIGNOUT\r\n", protocolWriter.execute(datas)); + } + } \ No newline at end of file From 43f9dc9fd93bd6bedf2d755d4233598b2e35c40f Mon Sep 17 00:00:00 2001 From: EndMove Date: Sat, 26 Feb 2022 15:37:58 +0100 Subject: [PATCH 29/64] Restructuring, complete. Cloturation server, client and clienthandler and storeprocessor. --- app/src/main/java/lightcontainer/App.java | 41 ++++++------ .../domains/{ => client}/ClientHandler.java | 21 ++++-- .../domains/{ => client}/StoreProcessor.java | 32 ++++++---- .../MulticastServerListener.java} | 37 +++++++---- .../UnicastServerListener.java} | 16 +++-- .../enumerations/TaskStatus.java | 5 ++ .../lightcontainer/enumerations/TaskType.java | 5 ++ .../interfaces/ClientHandlerFFE.java | 7 ++ .../interfaces/MulticastSPR.java | 22 +++++++ .../interfaces/StoreProcessorFFE.java | 12 ++-- .../lightcontainer/interfaces/UnicastCHR.java | 23 +++++++ .../repository/ClientHandlerRepository.java | 58 +++++++++++++++-- .../repository/FileFrontEnd.java | 6 +- .../repository/StoreProcessorRepository.java | 64 ++++++++++++++++++- 14 files changed, 278 insertions(+), 71 deletions(-) rename app/src/main/java/lightcontainer/domains/{ => client}/ClientHandler.java (82%) rename app/src/main/java/lightcontainer/domains/{ => client}/StoreProcessor.java (77%) rename app/src/main/java/lightcontainer/domains/{StoreMulticastRunnable.java => server/MulticastServerListener.java} (52%) rename app/src/main/java/lightcontainer/domains/{Server.java => server/UnicastServerListener.java} (75%) create mode 100644 app/src/main/java/lightcontainer/interfaces/MulticastSPR.java create mode 100644 app/src/main/java/lightcontainer/interfaces/UnicastCHR.java diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java index e590d9d..47a4788 100644 --- a/app/src/main/java/lightcontainer/App.java +++ b/app/src/main/java/lightcontainer/App.java @@ -3,30 +3,33 @@ */ package lightcontainer; -import lightcontainer.domains.StoreMulticastRunnable; -import lightcontainer.protocol.Protocol; - -import java.util.HashMap; -import java.util.Map; +import lightcontainer.domains.server.MulticastServerListener; +import lightcontainer.domains.server.UnicastServerListener; +import lightcontainer.interfaces.MulticastSPR; +import lightcontainer.repository.ClientHandlerRepository; +import lightcontainer.repository.FileFrontEnd; +import lightcontainer.repository.StoreProcessorRepository; public class App { + // Constant config server + // -- Unicast client port + private static final int UNICAST_PORT = 8500; + // -- Multicast listener ip, port + private static final String MULTICAST_IP = "226.0.0.1"; + private static final int MULTICAST_PORT = 42500; + public static void main(String[] args) { - System.out.println("Hello World !"); + // Create all repository + ClientHandlerRepository clientRep = new ClientHandlerRepository(); + StoreProcessorRepository storeRep = new StoreProcessorRepository(); - int port = 42500; - String ip = "226.0.0.1"; + new UnicastServerListener(clientRep, UNICAST_PORT); + new MulticastServerListener(storeRep, MULTICAST_IP, MULTICAST_PORT); - StoreMulticastRunnable multicast = new StoreMulticastRunnable(ip, port); - (new Thread(multicast)).start(); + FileFrontEnd ffe = new FileFrontEnd(clientRep, storeRep); - // Sleep - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - // Close - multicast.stop(); + // close repo et client et server. + clientRep.close(); + storeRep.close(); } } diff --git a/app/src/main/java/lightcontainer/domains/ClientHandler.java b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java similarity index 82% rename from app/src/main/java/lightcontainer/domains/ClientHandler.java rename to app/src/main/java/lightcontainer/domains/client/ClientHandler.java index 8c1fb15..9dc6100 100644 --- a/app/src/main/java/lightcontainer/domains/ClientHandler.java +++ b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java @@ -1,4 +1,4 @@ -package lightcontainer.domains; +package lightcontainer.domains.client; import lightcontainer.interfaces.ClientHandlerFFE; @@ -9,10 +9,11 @@ import java.nio.charset.StandardCharsets; /** * ClientHandler * + * UNICAST CLIENT * Class communicating with the client, and * intercepting and sending files to the client. * - * @version 1.0 + * @version 1.1 * @since 1.0 * * @see Runnable @@ -23,6 +24,7 @@ public class ClientHandler implements Runnable, AutoCloseable { // Variables private ClientHandlerFFE fileFrontEnd; private final Socket client; + private boolean client_run; private BufferedReader reader; private PrintWriter writer; @@ -31,6 +33,7 @@ public class ClientHandler implements Runnable, AutoCloseable { public ClientHandler(Socket client, ClientHandlerFFE ffe) { this.fileFrontEnd = ffe; this.client = client; + this.client_run = false; initClient(); } @@ -65,14 +68,13 @@ public class ClientHandler implements Runnable, AutoCloseable { */ @Override public void run() { - while (true) { + this.client_run = true; + while (this.client_run) { try { String command = this.reader.readLine(); // TODO gestion de la réception de commandes, fichier, ... if (command != null) System.out.println("Client: " + command); - } catch (IOException e) { - e.printStackTrace(); - } + } catch (IOException ignore) { } } } @@ -84,6 +86,11 @@ public class ClientHandler implements Runnable, AutoCloseable { */ @Override public void close() { - + if (this.client_run) { + try { + this.client_run = false; + this.client.close(); + } catch (IOException ignored) { } + } } } diff --git a/app/src/main/java/lightcontainer/domains/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java similarity index 77% rename from app/src/main/java/lightcontainer/domains/StoreProcessor.java rename to app/src/main/java/lightcontainer/domains/client/StoreProcessor.java index fb8ea2c..f9b56a0 100644 --- a/app/src/main/java/lightcontainer/domains/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java @@ -1,4 +1,4 @@ -package lightcontainer.domains; +package lightcontainer.domains.client; import lightcontainer.interfaces.StoreProcessorFFE; @@ -9,10 +9,11 @@ import java.nio.charset.StandardCharsets; /** * StoreProcessor * + * MULTICAST CLIENT * Class communicating with the storebackend and * processing the tasks in the FileFrontEnd * - * @version 1.0 + * @version 1.1 * @since 1.0 * * @see Runnable @@ -23,6 +24,7 @@ public class StoreProcessor implements Runnable, AutoCloseable { // Variables private final StoreProcessorFFE fileFrontEnd; private final Socket store; + private boolean client_run; private BufferedReader reader; private PrintWriter writer; @@ -31,16 +33,16 @@ public class StoreProcessor implements Runnable, AutoCloseable { public StoreProcessor(Socket socket, StoreProcessorFFE ffe) { this.fileFrontEnd = ffe; this.store = socket; + this.client_run = false; initStore(); } /** * Initialise the Store's Reader and Writer. * - * @since 1.0 - * - * @see BufferedReader - * @see PrintWriter + * @see BufferedReader + * @see PrintWriter + * @since 1.0 */ private void initStore() { try { @@ -61,18 +63,17 @@ public class StoreProcessor implements Runnable, AutoCloseable { * Thread Function * Start the dialogue with the storebackend. * - * @since 1.0 + * @since 1.0 */ @Override public void run() { - while (true) { + this.client_run = true; + while (this.client_run) { try { String command = this.reader.readLine(); // TODO gestion de la réception de commandes, fichier, ... if (command != null) System.out.println("StoreBackEnd: " + command); - } catch (IOException e) { - e.printStackTrace(); - } + } catch (IOException ignore) { } } } @@ -80,10 +81,15 @@ public class StoreProcessor implements Runnable, AutoCloseable { * AutoClosable Function * Close the Storage thread and resources. * - * @since 1.0 + * @since 1.0 */ @Override public void close() { - + if (this.client_run) { + try { + this.client_run = false; + this.store.close(); + } catch (IOException ignored) { } + } } } diff --git a/app/src/main/java/lightcontainer/domains/StoreMulticastRunnable.java b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java similarity index 52% rename from app/src/main/java/lightcontainer/domains/StoreMulticastRunnable.java rename to app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java index 835b0dd..e54371b 100644 --- a/app/src/main/java/lightcontainer/domains/StoreMulticastRunnable.java +++ b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java @@ -1,8 +1,10 @@ -package lightcontainer.domains; +package lightcontainer.domains.server; -import java.net.DatagramPacket; -import java.net.InetAddress; -import java.net.MulticastSocket; +import lightcontainer.domains.client.StoreProcessor; +import lightcontainer.interfaces.MulticastSPR; + +import java.io.IOException; +import java.net.*; /** * StoreMulticastRunnable @@ -16,18 +18,21 @@ import java.net.MulticastSocket; * @see Runnable * @author Jérémi NIHART */ -public class StoreMulticastRunnable implements Runnable { +public class MulticastServerListener implements Runnable { // Variable private final String multicast_address; private final int multicast_port; + private final MulticastSPR repository; private final byte[] buffer = new byte[256]; private MulticastSocket listener; // Constructor - public StoreMulticastRunnable(String multicast_address, int multicast_port) { + public MulticastServerListener(MulticastSPR repository, String multicast_address, int multicast_port) { + this.repository = repository; this.multicast_address = multicast_address; this.multicast_port = multicast_port; + repository.setServerListener(this); } /** @@ -46,14 +51,22 @@ public class StoreMulticastRunnable implements Runnable { // Create an identifier for the multicast group on the specified ip InetAddress listener_group = InetAddress.getByName(this.multicast_address); // Creation of a packet for the information received - DatagramPacket packet = new DatagramPacket(buffer, buffer.length); + DatagramPacket packet = new DatagramPacket(this.buffer, this.buffer.length); // Add the listener to the multicast group - listener.joinGroup(listener_group); + this.listener.joinGroup(listener_group); while(true) { - listener.receive(packet); + // Read the packet received and build a string of characters + this.listener.receive(packet); String data = new String(packet.getData(), 0, packet.getLength()); - - System.out.println(data); // TODO ajouter un controller et lui signaler qu'il y a un nouveau StoreBackEnd + // Create a new StoreBacked (try used in the case of an error to maintain the listening loop) + try { + // TODO Récupérer le port du message du packet et le setup (add description of the line). + Socket socket = new Socket(packet.getAddress(), 2500); + // Create the store processor + StoreProcessor storeProcessor = new StoreProcessor(socket, null); // TODO : Voir comment on procède get via repo ou ici ?! + // Add the store processor to its repository + this.repository.addStore(storeProcessor); + } catch (IOException ignore) { } } } catch (Exception ignore) { } } @@ -63,7 +76,7 @@ public class StoreMulticastRunnable implements Runnable { * * @since 1.0 * - * @see StoreMulticastRunnable#run() + * @see MulticastServerListener#run() */ public void stop() { this.listener.close(); diff --git a/app/src/main/java/lightcontainer/domains/Server.java b/app/src/main/java/lightcontainer/domains/server/UnicastServerListener.java similarity index 75% rename from app/src/main/java/lightcontainer/domains/Server.java rename to app/src/main/java/lightcontainer/domains/server/UnicastServerListener.java index 5c32cd1..c5ca8cd 100644 --- a/app/src/main/java/lightcontainer/domains/Server.java +++ b/app/src/main/java/lightcontainer/domains/server/UnicastServerListener.java @@ -1,19 +1,25 @@ -package lightcontainer.domains; +package lightcontainer.domains.server; + +import lightcontainer.domains.client.ClientHandler; +import lightcontainer.interfaces.UnicastCHR; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; -public class Server { +public class UnicastServerListener { // Variables private ServerSocket server; + private final UnicastCHR repository; private final int server_port; private boolean server_run; // Constructor - public Server(int port) { + public UnicastServerListener(UnicastCHR repository, int port) { + this.repository = repository; this.server_port = port; this.server_run = false; + repository.setServerListener(this); } /** @@ -26,8 +32,10 @@ public class Server { */ public void start() { try { + // Allow looping in the loop and create a socket server + this.server_run = true; this.server = new ServerSocket(this.server_port); - while (server_run) { + while (this.server_run) { // Accepting connection requests (blocking) Socket client = this.server.accept(); // Create a new Handler client by passing these dependencies to it diff --git a/app/src/main/java/lightcontainer/enumerations/TaskStatus.java b/app/src/main/java/lightcontainer/enumerations/TaskStatus.java index 64261f9..4113565 100644 --- a/app/src/main/java/lightcontainer/enumerations/TaskStatus.java +++ b/app/src/main/java/lightcontainer/enumerations/TaskStatus.java @@ -1,5 +1,10 @@ package lightcontainer.enumerations; +import lightcontainer.domains.Task; + +/** + * Enumeration defining the status of a {@link Task}. + */ public enum TaskStatus { PENDING, PROCESSING, diff --git a/app/src/main/java/lightcontainer/enumerations/TaskType.java b/app/src/main/java/lightcontainer/enumerations/TaskType.java index 3d4054c..347e6ce 100644 --- a/app/src/main/java/lightcontainer/enumerations/TaskType.java +++ b/app/src/main/java/lightcontainer/enumerations/TaskType.java @@ -1,5 +1,10 @@ package lightcontainer.enumerations; +import lightcontainer.domains.Task; + +/** + * enumeration to define the type of a {@link Task}. + */ public enum TaskType { SEND, RECEIVE, diff --git a/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java b/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java index a1783f7..a3a303f 100644 --- a/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java +++ b/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java @@ -1,4 +1,11 @@ package lightcontainer.interfaces; +import lightcontainer.domains.client.ClientHandler; +import lightcontainer.repository.FileFrontEnd; + +/** + * A communication interface between a {@link ClientHandler} and the {@link FileFrontEnd}. + */ public interface ClientHandlerFFE { + // functions } diff --git a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java new file mode 100644 index 0000000..b2108ec --- /dev/null +++ b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java @@ -0,0 +1,22 @@ +package lightcontainer.interfaces; + +import lightcontainer.domains.client.StoreProcessor; +import lightcontainer.domains.server.MulticastServerListener; +import lightcontainer.repository.StoreProcessorRepository; + +/** + * A communication interface between a {@link StoreProcessor} and the {@link StoreProcessorRepository}. + */ +public interface MulticastSPR { + /** + * Setter, allow to define the ServerListener of a repository. + * @param server ServerListener to set as default. + */ + void setServerListener(MulticastServerListener server); + + /** + * Add a StorePorcessor. + * @param store Store processor to add. + */ + void addStore(StoreProcessor store); +} diff --git a/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java b/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java index 7a5ffb6..5e95d5f 100644 --- a/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java +++ b/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java @@ -1,13 +1,15 @@ package lightcontainer.interfaces; -import lightcontainer.domains.StoreProcessor; +import lightcontainer.domains.client.StoreProcessor; +import lightcontainer.repository.FileFrontEnd; +/** + * A communication interface between a {@link StoreProcessor} and the {@link FileFrontEnd}. + */ public interface StoreProcessorFFE { - /** - * Permet à un {@link StoreProcessor} d'avertir le FFE qu'il est disponible - * @param store + * Allows a {@link StoreProcessor} to notify the FFE that it's available. + * @param store The store processor that is now available. */ void onStoreAvailable(StoreProcessor store); - } diff --git a/app/src/main/java/lightcontainer/interfaces/UnicastCHR.java b/app/src/main/java/lightcontainer/interfaces/UnicastCHR.java new file mode 100644 index 0000000..599093c --- /dev/null +++ b/app/src/main/java/lightcontainer/interfaces/UnicastCHR.java @@ -0,0 +1,23 @@ +package lightcontainer.interfaces; + +import lightcontainer.domains.client.ClientHandler; +import lightcontainer.domains.server.MulticastServerListener; +import lightcontainer.domains.server.UnicastServerListener; +import lightcontainer.repository.ClientHandlerRepository; + +/** + * A communication interface between a {@link ClientHandler} and the {@link ClientHandlerRepository}. + */ +public interface UnicastCHR { + /** + * Setter, allow to define the ServerListener of a repository. + * @param server ServerListener to set as default. + */ + void setServerListener(UnicastServerListener server); + + /** + * Add a ClientHandler. + * @param client Client Handler to add. + */ + void addClient(ClientHandler client); +} diff --git a/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java index 66f183b..8cc9383 100644 --- a/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java +++ b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java @@ -1,20 +1,68 @@ package lightcontainer.repository; -import lightcontainer.domains.ClientHandler; +import lightcontainer.domains.client.ClientHandler; +import lightcontainer.domains.server.UnicastServerListener; +import lightcontainer.interfaces.UnicastCHR; import java.util.ArrayList; import java.util.List; - -public class ClientHandlerRepository { +// TODO : C'est genre un ClientHandlerManager quoi hein, normal qu'il fasse blinder de chose ;) +/** + * ClientHandlerRepository + * + * Repository storing ClientHandler class. + * Contains some utility functions. + * + * @version 1.0 + * @since 1.0 + * + * @see ClientHandler + * @see AutoCloseable + * @author Jérémi NIHART + */ +public class ClientHandlerRepository implements AutoCloseable, UnicastCHR { // Variable - private final List handlers = new ArrayList<>(); + private final List handlers; + private UnicastServerListener server; // Constructor public ClientHandlerRepository() { - + this.handlers = new ArrayList<>(); } + /** + * Setter, allow to define the ServerListener of a repository. + * @param server ServerListener to set as default. + * + * @since 1.0 + */ + @Override + public void setServerListener(UnicastServerListener server) { + this.server = server; + } + + /** + * Add a ClientHandler. + * @param client Client Handler to add. + * + * @since 1.0 + */ + @Override public void addClient(ClientHandler client) { this.handlers.add(client); } + + /** + * AutoClosable Function + * Closes all ClientHandlers stored in this repository and deallocates all resources. + * + * @since 1.0 + */ + @Override + public void close() { + // Stop the server. + this.server.stop(); + // Stop each clients. + this.handlers.forEach(ClientHandler::close); + } } diff --git a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java index d7dfde2..b7028c5 100644 --- a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java +++ b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java @@ -1,14 +1,11 @@ package lightcontainer.repository; -import lightcontainer.domains.ClientHandler; -import lightcontainer.domains.StoreProcessor; +import lightcontainer.domains.client.StoreProcessor; import lightcontainer.domains.Task; import lightcontainer.interfaces.ClientHandlerFFE; import lightcontainer.interfaces.StoreProcessorFFE; -import java.util.Collections; import java.util.Deque; -import java.util.LinkedList; import java.util.concurrent.ConcurrentLinkedDeque; public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { @@ -28,7 +25,6 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { */ public void alertStoreProcessors(Task task) { // On avertit les stor processors d'une nouvelle tâche - } /** diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java index a330360..7ed9a74 100644 --- a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java +++ b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java @@ -1,5 +1,67 @@ package lightcontainer.repository; -public class StoreProcessorRepository { +import lightcontainer.domains.client.StoreProcessor; +import lightcontainer.domains.server.MulticastServerListener; +import lightcontainer.interfaces.MulticastSPR; +import java.util.ArrayList; +import java.util.List; +// TODO : C'est genre un ClientHandlerManager quoi hein, normal qu'il fasse blinder de chose ;) +/** + * StoreProcessorRepository + * + * Repository storing StorePorcessor class. + * Contains some utility functions. + * + * @version 1.0 + * @since 1.0 + * + * @see StoreProcessor + * @author Jérémi NIHART + */ +public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { + // Variables + private final List handlers; + private MulticastServerListener server; + + // Constructor + public StoreProcessorRepository() { + this.handlers = new ArrayList<>(); + } + + /** + * Setter, allow to define the ServerListener of a repository. + * @param server ServerListener to set as default. + * + * @since 1.0 + */ + @Override + public void setServerListener(MulticastServerListener server) { + this.server = server; + } + + /** + * Add a StorePorcessor. + * @param store Store processor to add. + * + * @since 1.0 + */ + @Override + public void addStore(StoreProcessor store) { + this.handlers.add(store); + } + + /** + * AutoClosable Function + * Closes all StoreProcessor stored in this repository and deallocates all resources. + * + * @since 1.0 + */ + @Override + public void close() { + // Stop the server. + this.server.stop(); + // Close each client. + this.handlers.forEach(StoreProcessor::close); + } } From 1dc0512bd0a5e0d12b0a22763ce6dde833018ebf Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 15:43:08 +0100 Subject: [PATCH 30/64] =?UTF-8?q?Suppresion=20class=20innutilis=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/protocol/Protocol.java | 117 ------------------ 1 file changed, 117 deletions(-) delete mode 100644 app/src/main/java/lightcontainer/protocol/Protocol.java diff --git a/app/src/main/java/lightcontainer/protocol/Protocol.java b/app/src/main/java/lightcontainer/protocol/Protocol.java deleted file mode 100644 index 07bb621..0000000 --- a/app/src/main/java/lightcontainer/protocol/Protocol.java +++ /dev/null @@ -1,117 +0,0 @@ -package lightcontainer.protocol; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Protocol - *

- * Class allowing to define new rules for the LightContainer protocol, - * also provides utility functions to work with regexes and the command to compare. - * - * @author Jérémi NIHART - * @version 1.0 - * @see Pattern - * @since 1.0 - */ -public abstract class Protocol { - // Variables - private final String rule; - private final Pattern rulePattern; - private List groups; - - /** - * Protocol constructor - * - * @param rule Command (e.g: LOGIN). - * @param regex Regex to compile and use for this command (e.g: LOGIN ([A-Z0-9a-z]{1,20})). - * Do not forget to define the groups in the regex. - */ - protected Protocol(String rule, String regex) { - this.rule = rule; - this.rulePattern = Pattern.compile(regex); - } - - /** - * Retrieve, the name of the Rule. - * - * @return Name of this rule. - * @since 1.0 - */ - public String getRule() { - return this.rule; - } - - /** - * Check if a command matches the rule with the rule matcher. - * - * @param cmd Command to verify with the rule matcher. - * @return True : if the command match with the rule. - * False though. - * @since 1.0 - */ - protected boolean matcherCheck(String cmd) { - Matcher ruleMatcher = this.rulePattern.matcher(cmd); - if (ruleMatcher.matches()) { - this.groups = new ArrayList<>(); - for (int i = 1; i <= ruleMatcher.groupCount(); i++) this.groups.add(ruleMatcher.group(i)); - return true; - } - return false; - } - - /** - * Get a list of all the groups extracted from the previously matched command with {@link #matcherCheck(String)}. - * - * Requires to have run {@link #matcherCheck(String)} - * - * @return String list containing all the groups extrapolated from the command. - * @see Protocol#matcherCheck(String) - * @since 1.0 - */ - protected List matcherGetGroups() { - return this.groups; - } - - /** - * Execute the rule on a command. - *

- * This function allows you to check a command and process those groups (parameters) - * use the utility functions of {@link Protocol} to facilitate processing, see @see. - * - * @param cmd Command on which to execute the rule. - * @see Protocol#execute(String) - * @see #matcherCheck(String) - * @see #matcherGetGroups() - * @since 1.0 - */ - public abstract void execute(String cmd); - - /** - * Retrieve, the hashcode of the rule. - * - * @return Rule hashcode. - * @since 1.0 - */ - @Override - public int hashCode() { - return rule.hashCode() % 8; - } - - /** - * Compare the equality of two rules. - * - * @return True : if the rules are equals - * False if not. - * @since 1.0 - */ - @Override - public boolean equals(final Object obj) { - if (this == obj) return true; - if (!(obj instanceof Protocol)) return false; - final Protocol other = (Protocol) obj; - return hashCode() == other.hashCode(); - } -} From 8b12bf0d5ffa7cefeed2572f2fbba8de113d446f Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 26 Feb 2022 16:01:47 +0100 Subject: [PATCH 31/64] =?UTF-8?q?ProtocolRepository=20impl=C3=A9ment=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interfaces/ProtocolRepository.java | 15 +++++++ .../repository/ProtocolRepositoryImpl.java | 44 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java create mode 100644 app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java diff --git a/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java b/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java new file mode 100644 index 0000000..2ee0743 --- /dev/null +++ b/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java @@ -0,0 +1,15 @@ +package lightcontainer.interfaces; + +import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.ProtocolWriter; + +public interface ProtocolRepository { + + boolean executeReader(String data); + + String executeWriter(String... datas); + + void addReader(ProtocolReader reader); + + void addWriter(ProtocolWriter writer); +} diff --git a/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java b/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java new file mode 100644 index 0000000..52071f6 --- /dev/null +++ b/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java @@ -0,0 +1,44 @@ +package lightcontainer.repository; + +import lightcontainer.interfaces.ProtocolRepository; +import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.ProtocolWriter; + +import java.util.HashSet; +import java.util.Set; + +public class ProtocolRepositoryImpl implements ProtocolRepository { + private Set readers = new HashSet<>(); + private Set writers = new HashSet<>(); + + @Override + public boolean executeReader(String data) { + for (ProtocolReader reader : readers) { + if (reader.execute(data)) { + return true; + } + } + return false; + } + + @Override + public String executeWriter(String... datas) { + for (ProtocolWriter writer : writers) { + String command = writer.execute(datas); + if (command != null) { + return command; + } + } + return null; + } + + @Override + public void addReader(ProtocolReader reader) { + this.readers.add(reader); + } + + @Override + public void addWriter(ProtocolWriter writer) { + this.writers.add(writer); + } +} From 9fdc69d75fa4c50e438c186ee8e9a1f3ea6ecaaa Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 26 Feb 2022 16:55:50 +0100 Subject: [PATCH 32/64] =?UTF-8?q?Syst=C3=A8me=20permettant=20de=20retourne?= =?UTF-8?q?r=20des=20r=C3=A9sultats=20divers=20apr=C3=A8s=20l'ex=C3=A9cuti?= =?UTF-8?q?on=20d'un=20ProtocolReader=20sans=20cast=20(g=C3=A9n=C3=A9rique?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/App.java | 8 +++- .../server/MulticastServerListener.java | 42 +++++++++++-------- .../interfaces/ProtocolRepository.java | 2 +- .../protocol/ProtocolReader.java | 13 +++--- .../protocol/rules/reader/HelloRule.java | 33 +++++++++++++-- .../repository/ProtocolRepositoryImpl.java | 13 +++--- .../protocol/rules/reader/HelloRuleTest.java | 8 +++- 7 files changed, 82 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java index 47a4788..397587f 100644 --- a/app/src/main/java/lightcontainer/App.java +++ b/app/src/main/java/lightcontainer/App.java @@ -6,8 +6,11 @@ package lightcontainer; import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.domains.server.UnicastServerListener; import lightcontainer.interfaces.MulticastSPR; +import lightcontainer.interfaces.ProtocolRepository; +import lightcontainer.protocol.rules.reader.HelloRule; import lightcontainer.repository.ClientHandlerRepository; import lightcontainer.repository.FileFrontEnd; +import lightcontainer.repository.ProtocolRepositoryImpl; import lightcontainer.repository.StoreProcessorRepository; public class App { @@ -22,9 +25,12 @@ public class App { // Create all repository ClientHandlerRepository clientRep = new ClientHandlerRepository(); StoreProcessorRepository storeRep = new StoreProcessorRepository(); + ProtocolRepository protocolRep = new ProtocolRepositoryImpl(); + + protocolRep.addReader(new HelloRule()); new UnicastServerListener(clientRep, UNICAST_PORT); - new MulticastServerListener(storeRep, MULTICAST_IP, MULTICAST_PORT); + new MulticastServerListener(storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT); FileFrontEnd ffe = new FileFrontEnd(clientRep, storeRep); diff --git a/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java index e54371b..33dee9a 100644 --- a/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java +++ b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java @@ -2,34 +2,38 @@ package lightcontainer.domains.server; import lightcontainer.domains.client.StoreProcessor; import lightcontainer.interfaces.MulticastSPR; +import lightcontainer.interfaces.ProtocolRepository; +import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.rules.reader.HelloRule; import java.io.IOException; import java.net.*; /** * StoreMulticastRunnable - * + *

* Class listening to the announcement of new StoreBackEnd. * Allowing it to be used as a storage unit. * - * @version 1.0 - * @since 1.0 - * - * @see Runnable - * @author Jérémi NIHART + * @author Jérémi NIHART + * @version 1.0 + * @see Runnable + * @since 1.0 */ public class MulticastServerListener implements Runnable { // Variable private final String multicast_address; private final int multicast_port; private final MulticastSPR repository; + private final ProtocolRepository protocolRep; private final byte[] buffer = new byte[256]; private MulticastSocket listener; // Constructor - public MulticastServerListener(MulticastSPR repository, String multicast_address, int multicast_port) { + public MulticastServerListener(MulticastSPR repository, ProtocolRepository protocolRep, String multicast_address, int multicast_port) { this.repository = repository; + this.protocolRep = protocolRep; this.multicast_address = multicast_address; this.multicast_port = multicast_port; repository.setServerListener(this); @@ -38,10 +42,9 @@ public class MulticastServerListener implements Runnable { /** * Start Multicast listening on indicated port and IP group. * - * @since 1.0 - * - * @see MulticastSocket#receive(DatagramPacket) - * @see DatagramPacket + * @see MulticastSocket#receive(DatagramPacket) + * @see DatagramPacket + * @since 1.0 */ @Override public void run() { @@ -54,29 +57,32 @@ public class MulticastServerListener implements Runnable { DatagramPacket packet = new DatagramPacket(this.buffer, this.buffer.length); // Add the listener to the multicast group this.listener.joinGroup(listener_group); - while(true) { + while (true) { // Read the packet received and build a string of characters this.listener.receive(packet); String data = new String(packet.getData(), 0, packet.getLength()); // Create a new StoreBacked (try used in the case of an error to maintain the listening loop) try { // TODO Récupérer le port du message du packet et le setup (add description of the line). - Socket socket = new Socket(packet.getAddress(), 2500); + HelloRule.Result readerResult = protocolRep.executeReader(data); + + Socket socket = new Socket(packet.getAddress(), readerResult.getPort()); // Create the store processor StoreProcessor storeProcessor = new StoreProcessor(socket, null); // TODO : Voir comment on procède get via repo ou ici ?! // Add the store processor to its repository this.repository.addStore(storeProcessor); - } catch (IOException ignore) { } + } catch (IOException ignore) { + } } - } catch (Exception ignore) { } + } catch (Exception ignore) { + } } /** * Closes the MulticastSocket connection and aborts the listening and infinite listening loop. * - * @since 1.0 - * - * @see MulticastServerListener#run() + * @see MulticastServerListener#run() + * @since 1.0 */ public void stop() { this.listener.close(); diff --git a/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java b/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java index 2ee0743..c772ba4 100644 --- a/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java +++ b/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java @@ -5,7 +5,7 @@ import lightcontainer.protocol.ProtocolWriter; public interface ProtocolRepository { - boolean executeReader(String data); + T executeReader(String data); String executeWriter(String... datas); diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java index 1d45c83..a61d3e7 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java @@ -11,11 +11,14 @@ public abstract class ProtocolReader { this.rulePattern = Pattern.compile(pattern); } + + public abstract class ProtocolResult {} + /** * Permet de lancer la décomposition d'une commande pour en extraire les données * @param data Contenu de la commande */ - public boolean execute(String data) { + public T execute(String data) { Matcher ruleMatcher = this.rulePattern.matcher(data); if (ruleMatcher.matches()) { @@ -24,17 +27,17 @@ public abstract class ProtocolReader { for (int i = 1; i <= groups.length; ++i) groups[i - 1] = ruleMatcher.group(i); - onExecuted(groups); - return true; + + return onExecuted(groups); } - return false; + return null; } /** * Cette méthode est appelée lors de l'exécution de la règle * @param data */ - protected abstract void onExecuted(String... data); + protected abstract T onExecuted(String... data); } diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java index a39019b..ba9567b 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java @@ -2,6 +2,9 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.protocol.ProtocolReader; +import java.util.ArrayList; +import java.util.List; + public class HelloRule extends ProtocolReader { private static final String PATTERN = "^HELLO ([A-Za-z0-9]{5,20}) ([0-9]{1,5})\r\n$"; @@ -17,11 +20,33 @@ public class HelloRule extends ProtocolReader { } - @Override - protected void onExecuted(String... data) { - String domain = data[DOMAIN], port = data[PORT]; + public class Result extends ProtocolResult { - System.out.printf("Règle Hello avec domain=%s et port=%s\n", domain, port); + private final String domain; + private final int port; + + public Result(String domain, int port) { + this.domain = domain; + this.port = port; + } + + public String getDomain() { + return domain; + } + + public int getPort() { + return port; + } + } + + + @Override + protected HelloRule.Result onExecuted(String... data) { + String domain = data[DOMAIN]; + int port = Integer.parseInt(data[PORT]); + + System.out.printf("Regle Hello avec domain=%s et port=%s\n", domain, port); + return new HelloRule.Result(domain, port); } } diff --git a/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java b/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java index 52071f6..7735ef0 100644 --- a/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java +++ b/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java @@ -8,17 +8,18 @@ import java.util.HashSet; import java.util.Set; public class ProtocolRepositoryImpl implements ProtocolRepository { - private Set readers = new HashSet<>(); - private Set writers = new HashSet<>(); + private final Set readers = new HashSet<>(); + private final Set writers = new HashSet<>(); @Override - public boolean executeReader(String data) { + public T executeReader(String data) { for (ProtocolReader reader : readers) { - if (reader.execute(data)) { - return true; + T readerResult = reader.execute(data); + if (readerResult != null) { + return readerResult; } } - return false; + return null; } @Override diff --git a/app/src/test/java/lightcontainer/protocol/rules/reader/HelloRuleTest.java b/app/src/test/java/lightcontainer/protocol/rules/reader/HelloRuleTest.java index c2a1b04..7b82f38 100644 --- a/app/src/test/java/lightcontainer/protocol/rules/reader/HelloRuleTest.java +++ b/app/src/test/java/lightcontainer/protocol/rules/reader/HelloRuleTest.java @@ -14,8 +14,12 @@ class HelloRuleTest { ProtocolReader protocolReader = new HelloRule(); String request = "HELLO bento 42890\r\n"; - // EXPECT - assertTrue(protocolReader.execute(request)); + // WHEN + HelloRule.Result ruleResult = protocolReader.execute(request); + + // THEN + assertEquals("bento", ruleResult.getDomain()); + assertEquals(42890, ruleResult.getPort()); } } \ No newline at end of file From 9eee080b60b36a52efeafe153a0de068fba4545f Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 17:48:42 +0100 Subject: [PATCH 33/64] =?UTF-8?q?V=C3=A9rification=20pour=20emp=C3=AAche?= =?UTF-8?q?=20le=20doublon=20de=20Storbackend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/App.java | 12 ++++++++---- .../domains/client/StoreProcessor.java | 18 +++++++++++++++++- .../server/MulticastServerListener.java | 5 ++++- .../protocol/rules/reader/HelloRule.java | 1 - .../repository/StoreProcessorRepository.java | 7 +++++-- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java index 397587f..d5111fa 100644 --- a/app/src/main/java/lightcontainer/App.java +++ b/app/src/main/java/lightcontainer/App.java @@ -18,10 +18,10 @@ public class App { // -- Unicast client port private static final int UNICAST_PORT = 8500; // -- Multicast listener ip, port - private static final String MULTICAST_IP = "226.0.0.1"; + private static final String MULTICAST_IP = "226.66.66.1"; private static final int MULTICAST_PORT = 42500; - public static void main(String[] args) { + public static void main(String[] args) throws InterruptedException { // Create all repository ClientHandlerRepository clientRep = new ClientHandlerRepository(); StoreProcessorRepository storeRep = new StoreProcessorRepository(); @@ -30,11 +30,15 @@ public class App { protocolRep.addReader(new HelloRule()); new UnicastServerListener(clientRep, UNICAST_PORT); - new MulticastServerListener(storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT); - + MulticastServerListener multiCast = new MulticastServerListener(storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT); + multiCast.run(); FileFrontEnd ffe = new FileFrontEnd(clientRep, storeRep); // close repo et client et server. + + Thread.sleep(60000); + + multiCast.stop(); clientRep.close(); storeRep.close(); } diff --git a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java index f9b56a0..55c4d2e 100644 --- a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java @@ -5,6 +5,7 @@ import lightcontainer.interfaces.StoreProcessorFFE; import java.io.*; import java.net.Socket; import java.nio.charset.StandardCharsets; +import java.util.Objects; /** * StoreProcessor @@ -21,6 +22,7 @@ import java.nio.charset.StandardCharsets; * @author Jérémi NIHART */ public class StoreProcessor implements Runnable, AutoCloseable { + private String domain; // Variables private final StoreProcessorFFE fileFrontEnd; private final Socket store; @@ -30,7 +32,8 @@ public class StoreProcessor implements Runnable, AutoCloseable { private PrintWriter writer; // Constructor - public StoreProcessor(Socket socket, StoreProcessorFFE ffe) { + public StoreProcessor(Socket socket, String domain, StoreProcessorFFE ffe) { + this.domain = domain; this.fileFrontEnd = ffe; this.store = socket; this.client_run = false; @@ -92,4 +95,17 @@ public class StoreProcessor implements Runnable, AutoCloseable { } catch (IOException ignored) { } } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + StoreProcessor that = (StoreProcessor) o; + return Objects.equals(domain, that.domain); + } + + @Override + public int hashCode() { + return Objects.hash(domain); + } } diff --git a/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java index 33dee9a..9f0ffc7 100644 --- a/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java +++ b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java @@ -65,13 +65,16 @@ public class MulticastServerListener implements Runnable { try { // TODO Récupérer le port du message du packet et le setup (add description of the line). HelloRule.Result readerResult = protocolRep.executeReader(data); + System.out.printf("Réception en multicast : Domain=%s | Port=%d\n", readerResult.getDomain(), readerResult.getPort()); Socket socket = new Socket(packet.getAddress(), readerResult.getPort()); // Create the store processor - StoreProcessor storeProcessor = new StoreProcessor(socket, null); // TODO : Voir comment on procède get via repo ou ici ?! + StoreProcessor storeProcessor = new StoreProcessor(socket, readerResult.getDomain(), null); // TODO : Voir comment on procède get via repo ou ici ?! // Add the store processor to its repository + this.repository.addStore(storeProcessor); } catch (IOException ignore) { + ignore.printStackTrace(); } } } catch (Exception ignore) { diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java index ba9567b..e3a0dc2 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java @@ -45,7 +45,6 @@ public class HelloRule extends ProtocolReader { String domain = data[DOMAIN]; int port = Integer.parseInt(data[PORT]); - System.out.printf("Regle Hello avec domain=%s et port=%s\n", domain, port); return new HelloRule.Result(domain, port); } diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java index 7ed9a74..b97aa29 100644 --- a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java +++ b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java @@ -5,7 +5,9 @@ import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.interfaces.MulticastSPR; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; // TODO : C'est genre un ClientHandlerManager quoi hein, normal qu'il fasse blinder de chose ;) /** * StoreProcessorRepository @@ -21,12 +23,12 @@ import java.util.List; */ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { // Variables - private final List handlers; + private final Set handlers; private MulticastServerListener server; // Constructor public StoreProcessorRepository() { - this.handlers = new ArrayList<>(); + this.handlers = new HashSet<>(); } /** @@ -49,6 +51,7 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { @Override public void addStore(StoreProcessor store) { this.handlers.add(store); + System.out.println(handlers.size()); } /** From 7cac782a61b01761a888559fc493c36a0e33af3a Mon Sep 17 00:00:00 2001 From: EndMove Date: Sat, 26 Feb 2022 17:53:53 +0100 Subject: [PATCH 34/64] Start the server when the repository get it. --- .../java/lightcontainer/repository/ClientHandlerRepository.java | 2 ++ .../lightcontainer/repository/StoreProcessorRepository.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java index 8cc9383..e96050f 100644 --- a/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java +++ b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java @@ -32,6 +32,7 @@ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR { /** * Setter, allow to define the ServerListener of a repository. + * & Start the server. * @param server ServerListener to set as default. * * @since 1.0 @@ -39,6 +40,7 @@ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR { @Override public void setServerListener(UnicastServerListener server) { this.server = server; + server.start(); } /** diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java index 7ed9a74..01fe81a 100644 --- a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java +++ b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java @@ -31,6 +31,7 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { /** * Setter, allow to define the ServerListener of a repository. + * & start the server. * @param server ServerListener to set as default. * * @since 1.0 @@ -38,6 +39,7 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { @Override public void setServerListener(MulticastServerListener server) { this.server = server; + server.run(); } /** From 362b82c31c77b7a76fadf683e6c03c5f4de41c58 Mon Sep 17 00:00:00 2001 From: EndMove Date: Sat, 26 Feb 2022 18:07:41 +0100 Subject: [PATCH 35/64] Ajout exemple de fichier json pour save data --- .../lightcontainer/storage/json-example.json | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 app/src/main/java/lightcontainer/storage/json-example.json diff --git a/app/src/main/java/lightcontainer/storage/json-example.json b/app/src/main/java/lightcontainer/storage/json-example.json new file mode 100644 index 0000000..6f982b6 --- /dev/null +++ b/app/src/main/java/lightcontainer/storage/json-example.json @@ -0,0 +1,38 @@ +{ + "unicast_port": 32000, + "multicast_ip": "224.25.0.1", + "multicast_port": 70000, + "network_interface": "LALALALA", + "tls": false, + "users": [ + { + "username": "endmove", + "password": "notre-hash", + "aes_key": "jkjiezjijfizef8e4864", + "files": [ + { + "file_name": "lol.jpeg", + "file_size": 15558, + "iv": "8d484e8e84 (lié à la méthode de cryptage)", + "storage": [ + "lol.benjamin" + ] + }, + { + "file_name": "super-man.png", + "file_size": 24457, + "iv": "zf4fe84f (lié à la méthode de cryptage)", + "storage": [ + "lol.benjamin" + ] + } + ] + }, + { + "username": "michel", + "password": "notre-hash du mdp", + "aes_key": "fjshufihehehuhuhuehu", + "files": [] + } + ] +} \ No newline at end of file From 06fb0086fbf4624d1af33c24abc33f0a0a498d24 Mon Sep 17 00:00:00 2001 From: EndMove Date: Sat, 26 Feb 2022 18:28:27 +0100 Subject: [PATCH 36/64] Optimization of server startup, deletion of my benjamin's balls space. Some bug fixes --- app/src/main/java/lightcontainer/App.java | 4 +--- .../domains/client/ClientHandler.java | 1 + .../domains/client/StoreProcessor.java | 8 +++++++- .../protocol/ProtocolReader.java | 9 +++------ .../protocol/ProtocolWriter.java | 18 +++++++++--------- .../repository/ProtocolRepositoryImpl.java | 4 ++-- .../repository/StoreProcessorRepository.java | 2 -- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java index d5111fa..3aae4e2 100644 --- a/app/src/main/java/lightcontainer/App.java +++ b/app/src/main/java/lightcontainer/App.java @@ -30,15 +30,13 @@ public class App { protocolRep.addReader(new HelloRule()); new UnicastServerListener(clientRep, UNICAST_PORT); - MulticastServerListener multiCast = new MulticastServerListener(storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT); - multiCast.run(); + new MulticastServerListener(storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT); FileFrontEnd ffe = new FileFrontEnd(clientRep, storeRep); // close repo et client et server. Thread.sleep(60000); - multiCast.stop(); clientRep.close(); storeRep.close(); } diff --git a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java index 9dc6100..53f7ba0 100644 --- a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java +++ b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java @@ -5,6 +5,7 @@ import lightcontainer.interfaces.ClientHandlerFFE; import java.io.*; import java.net.Socket; import java.nio.charset.StandardCharsets; +import java.util.Objects; /** * ClientHandler diff --git a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java index 55c4d2e..b573ab4 100644 --- a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java @@ -22,10 +22,10 @@ import java.util.Objects; * @author Jérémi NIHART */ public class StoreProcessor implements Runnable, AutoCloseable { - private String domain; // Variables private final StoreProcessorFFE fileFrontEnd; private final Socket store; + private final String domain; private boolean client_run; private BufferedReader reader; @@ -96,6 +96,9 @@ public class StoreProcessor implements Runnable, AutoCloseable { } } + /** + * Compare two StoreProcessor object to check if equals. + */ @Override public boolean equals(Object o) { if (this == o) return true; @@ -104,6 +107,9 @@ public class StoreProcessor implements Runnable, AutoCloseable { return Objects.equals(domain, that.domain); } + /** + * Get hash code + */ @Override public int hashCode() { return Objects.hash(domain); diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java index a61d3e7..89046df 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java @@ -4,14 +4,14 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public abstract class ProtocolReader { - + // Variables private final Pattern rulePattern; + // Constructor protected ProtocolReader(String pattern) { this.rulePattern = Pattern.compile(pattern); } - public abstract class ProtocolResult {} /** @@ -27,17 +27,14 @@ public abstract class ProtocolReader { for (int i = 1; i <= groups.length; ++i) groups[i - 1] = ruleMatcher.group(i); - return onExecuted(groups); } - return null; } /** * Cette méthode est appelée lors de l'exécution de la règle - * @param data + * @param data Paramètres pour créer la commande. */ protected abstract T onExecuted(String... data); - } diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java index 4605a30..ba857bd 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java @@ -5,19 +5,19 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public abstract class ProtocolWriter { - + // Variables private final Pattern rulePattern; private final String cmdName; - + // Constructor protected ProtocolWriter(String cmdName, String pattern) { this.rulePattern = Pattern.compile(pattern); this.cmdName = cmdName; } /** - * Permet de récupérer le nom du protocol - * @return + * Permet de récupérer le nom de la commande. + * @return Nom de la commande. */ public String getCmdName() { return cmdName; @@ -25,16 +25,16 @@ public abstract class ProtocolWriter { /** * Permet de contruire une commande selon une règle établie. - * @param datas Les données à ajouter dans la commande; L'ordre défini leur position dans la commande + * @param data Les données à ajouter dans la commande; L'ordre défini leur position dans la commande * @return La commande construite */ - public String execute(String... datas) { + public String execute(String... data) { // Concatatène le nom de la commande avec les données (trim), avec un espace entre chaque - String command = null; + String command; StringJoiner builder = new StringJoiner(" ", this.cmdName, "\r\n"); - for (String data : datas) - builder.add(data); + for (String param : data) + builder.add(param); command = builder.toString(); diff --git a/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java b/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java index 7735ef0..dad49c8 100644 --- a/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java +++ b/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java @@ -23,9 +23,9 @@ public class ProtocolRepositoryImpl implements ProtocolRepository { } @Override - public String executeWriter(String... datas) { + public String executeWriter(String... data) { for (ProtocolWriter writer : writers) { - String command = writer.execute(datas); + String command = writer.execute(data); if (command != null) { return command; } diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java index 2eea8d4..4171a5b 100644 --- a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java +++ b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java @@ -4,9 +4,7 @@ import lightcontainer.domains.client.StoreProcessor; import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.interfaces.MulticastSPR; -import java.util.ArrayList; import java.util.HashSet; -import java.util.List; import java.util.Set; // TODO : C'est genre un ClientHandlerManager quoi hein, normal qu'il fasse blinder de chose ;) /** From 65749186503c8a2c3a84b28dc9a3c52a92554d27 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 18:44:53 +0100 Subject: [PATCH 37/64] =?UTF-8?q?Ajout=20de=20la=20possibilit=C3=A9=20d'aj?= =?UTF-8?q?outer=20une=20command=20de=20retour=20pour=20un=20ProtocolReade?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domains/server/MulticastServerListener.java | 1 - .../lightcontainer/protocol/ProtocolReader.java | 16 +++++++++++++++- .../repository/StoreProcessorRepository.java | 1 - 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java index 9f0ffc7..98996f3 100644 --- a/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java +++ b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java @@ -71,7 +71,6 @@ public class MulticastServerListener implements Runnable { // Create the store processor StoreProcessor storeProcessor = new StoreProcessor(socket, readerResult.getDomain(), null); // TODO : Voir comment on procède get via repo ou ici ?! // Add the store processor to its repository - this.repository.addStore(storeProcessor); } catch (IOException ignore) { ignore.printStackTrace(); diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java index 89046df..295212c 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java @@ -12,7 +12,21 @@ public abstract class ProtocolReader { this.rulePattern = Pattern.compile(pattern); } - public abstract class ProtocolResult {} + public abstract class ProtocolResult { + + /** + * Command qui sera renvoyée par exemple au client + */ + private String resultCommand; + + public String getResultCommand() { + return resultCommand; + } + + public void setResultCommand(String resultCommand) { + this.resultCommand = resultCommand; + } + } /** * Permet de lancer la décomposition d'une commande pour en extraire les données diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java index 4171a5b..7132a74 100644 --- a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java +++ b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java @@ -51,7 +51,6 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { @Override public void addStore(StoreProcessor store) { this.handlers.add(store); - System.out.println(handlers.size()); } /** From 59ce081d8cd3850fc18a7b3b804ed606ea78919e Mon Sep 17 00:00:00 2001 From: Benjamin Date: Mon, 28 Feb 2022 16:53:11 +0100 Subject: [PATCH 38/64] =?UTF-8?q?Lise=20en=20place=20du=20syst=C3=A8me=20p?= =?UTF-8?q?ermettant=20=C3=A0=20un=20reader=20de=20choisir=20entre=20renvo?= =?UTF-8?q?yer=20la=20commande=20au=20client=20OU=20la=20mettre=20dans=20l?= =?UTF-8?q?a=20file=20d'attente=20pour=20les=20storbackends?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/App.java | 6 +++--- .../java/lightcontainer/domains/Task.java | 11 +++++++++-- .../domains/client/ClientHandler.java | 14 +++++++++++++- .../domains/server/UnicastServerListener.java | 7 +++++-- .../interfaces/ClientHandlerFFE.java | 8 ++++++++ .../protocol/ProtocolReader.java | 19 ++++++++++++++++++- .../repository/FileFrontEnd.java | 12 +++++++++++- 7 files changed, 67 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java index 3aae4e2..ec37202 100644 --- a/app/src/main/java/lightcontainer/App.java +++ b/app/src/main/java/lightcontainer/App.java @@ -5,7 +5,6 @@ package lightcontainer; import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.domains.server.UnicastServerListener; -import lightcontainer.interfaces.MulticastSPR; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.rules.reader.HelloRule; import lightcontainer.repository.ClientHandlerRepository; @@ -28,10 +27,11 @@ public class App { ProtocolRepository protocolRep = new ProtocolRepositoryImpl(); protocolRep.addReader(new HelloRule()); + protocolRep.addReader(new SigninRule()); - new UnicastServerListener(clientRep, UNICAST_PORT); + new UnicastServerListener(clientRep, protocolRep, UNICAST_PORT); new MulticastServerListener(storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT); - FileFrontEnd ffe = new FileFrontEnd(clientRep, storeRep); + FileFrontEnd ffe = new FileFrontEnd(clientRep, storeRep, protocolRep); // close repo et client et server. diff --git a/app/src/main/java/lightcontainer/domains/Task.java b/app/src/main/java/lightcontainer/domains/Task.java index 45494c8..9ff6369 100644 --- a/app/src/main/java/lightcontainer/domains/Task.java +++ b/app/src/main/java/lightcontainer/domains/Task.java @@ -5,13 +5,20 @@ import lightcontainer.enumerations.TaskType; public class Task { // Variables - private TaskType type; + private TaskType type; // TODO : Supprimer car innutile ? private TaskStatus status; private String command; private String client; private String storeDomain; - public Task() { + public Task(TaskStatus pending, String command, String client) { + status = pending; + this.command = command; + this.client = client; + } + public static Task newInstance(String command, String client) { + Task task = new Task(TaskStatus.PENDING, command, client); + return task; } } diff --git a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java index 53f7ba0..256d068 100644 --- a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java +++ b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java @@ -1,6 +1,8 @@ package lightcontainer.domains.client; import lightcontainer.interfaces.ClientHandlerFFE; +import lightcontainer.interfaces.ProtocolRepository; +import lightcontainer.protocol.ProtocolReader; import java.io.*; import java.net.Socket; @@ -25,15 +27,17 @@ public class ClientHandler implements Runnable, AutoCloseable { // Variables private ClientHandlerFFE fileFrontEnd; private final Socket client; + private ProtocolRepository protocolRep; private boolean client_run; private BufferedReader reader; private PrintWriter writer; // Constructor - public ClientHandler(Socket client, ClientHandlerFFE ffe) { + public ClientHandler(Socket client, ClientHandlerFFE ffe, ProtocolRepository protocolRep) { this.fileFrontEnd = ffe; this.client = client; + this.protocolRep = protocolRep; this.client_run = false; initClient(); } @@ -75,6 +79,14 @@ public class ClientHandler implements Runnable, AutoCloseable { String command = this.reader.readLine(); // TODO gestion de la réception de commandes, fichier, ... if (command != null) System.out.println("Client: " + command); + + ProtocolReader.ProtocolResult ruleResult = protocolRep.executeReader(command + "\r\n"); + + if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND) { + fileFrontEnd.newCommand(command, ruleResult.getResultCommand()); // Envoie dans la file de tâche FileFrontEnd en attente d'un traitement d'un StorBackEnd + } else { + writer.write(ruleResult.getResultCommand()); // Renvoye au client + } } catch (IOException ignore) { } } } diff --git a/app/src/main/java/lightcontainer/domains/server/UnicastServerListener.java b/app/src/main/java/lightcontainer/domains/server/UnicastServerListener.java index c5ca8cd..c604dee 100644 --- a/app/src/main/java/lightcontainer/domains/server/UnicastServerListener.java +++ b/app/src/main/java/lightcontainer/domains/server/UnicastServerListener.java @@ -1,6 +1,7 @@ package lightcontainer.domains.server; import lightcontainer.domains.client.ClientHandler; +import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.interfaces.UnicastCHR; import java.io.IOException; @@ -11,12 +12,14 @@ public class UnicastServerListener { // Variables private ServerSocket server; private final UnicastCHR repository; + private ProtocolRepository protocolRep; private final int server_port; private boolean server_run; // Constructor - public UnicastServerListener(UnicastCHR repository, int port) { + public UnicastServerListener(UnicastCHR repository, ProtocolRepository protocolRep, int port) { this.repository = repository; + this.protocolRep = protocolRep; this.server_port = port; this.server_run = false; repository.setServerListener(this); @@ -39,7 +42,7 @@ public class UnicastServerListener { // Accepting connection requests (blocking) Socket client = this.server.accept(); // Create a new Handler client by passing these dependencies to it - ClientHandler clientHandler = new ClientHandler(client, null); // TODO passer FileFrontEnd ou faire ca dans le repository ?! + ClientHandler clientHandler = new ClientHandler(client, null, protocolRep); // TODO passer FileFrontEnd ou faire ca dans le repository ?! // Add the client handler to its repository (clienthandlerrepository) // this.repository.add(clientHandler); TODO REPOSITORY // Start the thread diff --git a/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java b/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java index a3a303f..99536f1 100644 --- a/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java +++ b/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java @@ -8,4 +8,12 @@ import lightcontainer.repository.FileFrontEnd; */ public interface ClientHandlerFFE { // functions + + /** + * Demande le traitement d'une commande + * @param command Commande à traiter + * @param client identifiant du client à qui est affilié cette commande + */ + void newCommand(String command, String client); + } diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java index 295212c..b1102bf 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java @@ -12,19 +12,36 @@ public abstract class ProtocolReader { this.rulePattern = Pattern.compile(pattern); } + public enum ResultCmdReceiver { + CLIENT, + STOREBACKEND + } + public abstract class ProtocolResult { /** * Command qui sera renvoyée par exemple au client */ private String resultCommand; + /** + * Désigne vers ou cette commande est envoyée. + * ResultCmdReceiver.CLIENT : Signifie que cette commande va être directement revoyée au client. + * ResultCmdReceiver.STOREBACKEND : Signifie que cette commande va être envoyée dans la file de tâche du server et êre en attente d'envoie à un StorBackEnd + */ + private ResultCmdReceiver receiver; + + + public ResultCmdReceiver getReceiver() { + return receiver; + } public String getResultCommand() { return resultCommand; } - public void setResultCommand(String resultCommand) { + public void setResultCommand(String resultCommand, ResultCmdReceiver receiver) { this.resultCommand = resultCommand; + this.receiver = receiver; } } diff --git a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java index b7028c5..ce47bea 100644 --- a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java +++ b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java @@ -3,6 +3,7 @@ package lightcontainer.repository; import lightcontainer.domains.client.StoreProcessor; import lightcontainer.domains.Task; import lightcontainer.interfaces.ClientHandlerFFE; +import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.interfaces.StoreProcessorFFE; import java.util.Deque; @@ -13,11 +14,13 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { private Deque tasks = new ConcurrentLinkedDeque<>(); private ClientHandlerRepository clientRepository; // TODO -> pourquoi pas une interface ? end private StoreProcessorRepository storeRepository; // TODO -> pourquoi pas une interface ? end + private ProtocolRepository protocolRepository; // Constructor - public FileFrontEnd(ClientHandlerRepository clientRepo, StoreProcessorRepository storeRepo) { + public FileFrontEnd(ClientHandlerRepository clientRepo, StoreProcessorRepository storeRepo, ProtocolRepository protocolRepository) { this.clientRepository = clientRepo; this.storeRepository = storeRepo; + this.protocolRepository = protocolRepository; } /** @@ -36,4 +39,11 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { public void onStoreAvailable(StoreProcessor store) { } + + @Override + public void newCommand(String command, String client) { + // TODO : Ajouter la tâche - Alerter les StorBackEnds + Task task = Task.newInstance(command, client); + tasks.add(task); + } } From f0461537f665db4b3b2df94a94f93a2e6a29a0b3 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Mon, 28 Feb 2022 19:57:30 +0100 Subject: [PATCH 39/64] =?UTF-8?q?Possibilit=C3=A9=20de=20se=20connecter=20?= =?UTF-8?q?(factice),=20tout=20en=20recevant=20un=20message=20de=20confirm?= =?UTF-8?q?ation=20ou=20d'erreur.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/App.java | 9 +++ .../domains/client/ClientHandler.java | 48 +++++++++++++-- .../interfaces/ProtocolRepository.java | 2 +- .../protocol/rules/reader/SigninRule.java | 59 +++++++++++++++++++ .../protocol/rules/writer/SignError.java | 14 +++++ .../protocol/rules/writer/SignOk.java | 14 +++++ .../repository/ProtocolRepositoryImpl.java | 6 +- 7 files changed, 144 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java create mode 100644 app/src/main/java/lightcontainer/protocol/rules/writer/SignError.java create mode 100644 app/src/main/java/lightcontainer/protocol/rules/writer/SignOk.java diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java index ec37202..c3ee754 100644 --- a/app/src/main/java/lightcontainer/App.java +++ b/app/src/main/java/lightcontainer/App.java @@ -5,8 +5,13 @@ package lightcontainer; import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.domains.server.UnicastServerListener; +import lightcontainer.interfaces.MulticastSPR; import lightcontainer.interfaces.ProtocolRepository; +import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.reader.HelloRule; +import lightcontainer.protocol.rules.reader.SigninRule; +import lightcontainer.protocol.rules.writer.SignError; +import lightcontainer.protocol.rules.writer.SignOk; import lightcontainer.repository.ClientHandlerRepository; import lightcontainer.repository.FileFrontEnd; import lightcontainer.repository.ProtocolRepositoryImpl; @@ -29,6 +34,10 @@ public class App { protocolRep.addReader(new HelloRule()); protocolRep.addReader(new SigninRule()); + protocolRep.addWriter(new SignOk()); + protocolRep.addWriter(new SignError()); + + new UnicastServerListener(clientRep, protocolRep, UNICAST_PORT); new MulticastServerListener(storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT); FileFrontEnd ffe = new FileFrontEnd(clientRep, storeRep, protocolRep); diff --git a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java index 256d068..7d0b6ab 100644 --- a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java +++ b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java @@ -3,11 +3,13 @@ package lightcontainer.domains.client; import lightcontainer.interfaces.ClientHandlerFFE; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.rules.reader.SigninRule; +import lightcontainer.protocol.rules.writer.SignError; +import lightcontainer.protocol.rules.writer.SignOk; import java.io.*; import java.net.Socket; import java.nio.charset.StandardCharsets; -import java.util.Objects; /** * ClientHandler @@ -30,6 +32,12 @@ public class ClientHandler implements Runnable, AutoCloseable { private ProtocolRepository protocolRep; private boolean client_run; + /** + * Login of client. + * State : NULL if not connected and Login string if connected + */ + private String login; + private BufferedReader reader; private PrintWriter writer; @@ -82,15 +90,47 @@ public class ClientHandler implements Runnable, AutoCloseable { ProtocolReader.ProtocolResult ruleResult = protocolRep.executeReader(command + "\r\n"); - if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND) { - fileFrontEnd.newCommand(command, ruleResult.getResultCommand()); // Envoie dans la file de tâche FileFrontEnd en attente d'un traitement d'un StorBackEnd + + if (isConnected()) { + + if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND) { + fileFrontEnd.newCommand(command, ruleResult.getResultCommand()); // Envoie dans la file de tâche FileFrontEnd en attente d'un traitement d'un StorBackEnd + } else { + writer.write(ruleResult.getResultCommand()); // Renvoye au client + } + } else { - writer.write(ruleResult.getResultCommand()); // Renvoye au client + authentificate(ruleResult); } + } catch (IOException ignore) { } } } + private void authentificate(ProtocolReader.ProtocolResult ruleResult) { + try { + SigninRule.Result signinResult = (SigninRule.Result) ruleResult; + if (signinResult.checkCredentials()) { + this.login = signinResult.getLogin(); + writer.write(protocolRep.executeWriter(SignOk.NAME)); + writer.flush(); + return; + } + } catch (ClassCastException castException) {} + + writer.write(protocolRep.executeWriter(SignError.NAME)); // Envoie SignError car echec de la connection + writer.flush(); + this.close(); // Fermeture de la connection + } + + /** + * Permet de savoir si l'utilisateur s'est connecté (Avec login et mdp) + * @return + */ + private boolean isConnected() { + return login != null; + } + /** * AutoClosable Function * Close the Client thread and resources. diff --git a/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java b/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java index c772ba4..af435d1 100644 --- a/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java +++ b/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java @@ -7,7 +7,7 @@ public interface ProtocolRepository { T executeReader(String data); - String executeWriter(String... datas); + String executeWriter(String cmdName, String... datas); void addReader(ProtocolReader reader); diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java new file mode 100644 index 0000000..bbfc660 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java @@ -0,0 +1,59 @@ +package lightcontainer.protocol.rules.reader; + +import lightcontainer.protocol.ProtocolReader; + +public class SigninRule extends ProtocolReader { + + private static final String PATTERN = "^SIGNIN ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$"; + + // Index du domain dans le tableau de donnée + private static final int LOGIN = 0; + + //Index du port dans le tableau de donnée + private static final int PASSWORD = 1; + + public SigninRule() { + super(PATTERN); + } + + + public class Result extends ProtocolResult { + + private final String login; + + private final String password; + + public Result(String login, String password) { + + this.login = login; + this.password = password; + } + + public String getLogin() { + return login; + } + + public String getPassword() { + return password; + } + + public boolean checkCredentials() { + return getLogin().equals("aa") && getPassword().equals("aaaaa"); + } + } + + + @Override + protected SigninRule.Result onExecuted(String... data) { + SigninRule.Result result = new SigninRule.Result(data[LOGIN], data[PASSWORD]); + + // TODO : Création d'une règle d'écriture SIGN_OK et SIGN_ERROR proprement + if (result.checkCredentials()) { + result.setResultCommand("SIGN_OK\r\n", ResultCmdReceiver.CLIENT); + } else { + result.setResultCommand("SIGN_ERROR\r\n", ResultCmdReceiver.CLIENT); + } + + return result; + } +} diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SignError.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SignError.java new file mode 100644 index 0000000..0daa349 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SignError.java @@ -0,0 +1,14 @@ +package lightcontainer.protocol.rules.writer; + +import lightcontainer.protocol.ProtocolWriter; + +public class SignError extends ProtocolWriter { + + private static final String PATTERN = "^SIGN_ERROR\r\n$"; + + public static final String NAME = "SIGN_ERROR"; + + public SignError() { + super(NAME, PATTERN); + } +} diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SignOk.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SignOk.java new file mode 100644 index 0000000..848561c --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SignOk.java @@ -0,0 +1,14 @@ +package lightcontainer.protocol.rules.writer; + +import lightcontainer.protocol.ProtocolWriter; + +public class SignOk extends ProtocolWriter { + + private static final String PATTERN = "^SIGN_OK\r\n$"; + + public static final String NAME = "SIGN_OK"; + + public SignOk() { + super(NAME, PATTERN); + } +} diff --git a/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java b/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java index dad49c8..4bb1c84 100644 --- a/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java +++ b/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java @@ -23,10 +23,10 @@ public class ProtocolRepositoryImpl implements ProtocolRepository { } @Override - public String executeWriter(String... data) { + public String executeWriter(String cmdName, String... data) { for (ProtocolWriter writer : writers) { - String command = writer.execute(data); - if (command != null) { + String command; + if (cmdName.equals(writer.getCmdName()) && (command = writer.execute(data)) != null) { return command; } } From a1b3463d3b1e9f5af107aa1862198a5c4afa35d7 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 5 Mar 2022 12:12:12 +0100 Subject: [PATCH 40/64] =?UTF-8?q?Modification=20syst=C3=A8me=20de=20Protoc?= =?UTF-8?q?olReader.java=20qui=20permet=20de=20lire/ecrire=20un=20fichier?= =?UTF-8?q?=20sur=20le=20r=C3=A9seau.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/ProtocolReader.java | 73 +++++++++++++++++++ .../protocol/rules/reader/HelloRule.java | 4 + .../protocol/rules/reader/SigninRule.java | 2 +- 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java index b1102bf..55cadf5 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java @@ -1,5 +1,7 @@ package lightcontainer.protocol; +import java.io.BufferedReader; +import java.io.BufferedWriter; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -17,12 +19,41 @@ public abstract class ProtocolReader { STOREBACKEND } + public enum FileOptions { + + /** + * Ne lire/ecrire aucun fichier + */ + NONE, + + /** + * Lire un fichier : Implementer la méthode 'read' + */ + READ, + + /** + * Ecrire un fichier : Implementer la méthode 'write' + */ + WRITE + } + + /** + * Modèle utilisé par tout les résultats des règles de protocol. + * Lorsqu'il retourne son résultat, on vérifie si il y a une demande de lecture/écriture de fichier depuis le réseau. Si oui on appel ces méthodes, sinon on ne fait rien. + * Ensuite on regarde après l'exécution de ces méthode ou non si il y a une commande de retour ou non et l'envoyons au receiver spécifié par la commande. + */ public abstract class ProtocolResult { + /** + * Permet de déterminer si la class souhaite lire ou écrire un fichier. + */ + private final FileOptions option; + /** * Command qui sera renvoyée par exemple au client */ private String resultCommand; + /** * Désigne vers ou cette commande est envoyée. * ResultCmdReceiver.CLIENT : Signifie que cette commande va être directement revoyée au client. @@ -31,18 +62,60 @@ public abstract class ProtocolReader { private ResultCmdReceiver receiver; + /** + * Spécifier une option correct afin de permettre au système de détecter ce qu'il doit exécuter. + * @param option Option + */ + public ProtocolResult(FileOptions option) { + this.option = option; + } + + public ResultCmdReceiver getReceiver() { return receiver; } + + /** + * Récupérer la commande à envoyer + * @return + */ public String getResultCommand() { return resultCommand; } + /** + * Mettre la commande à envoyer + * @param resultCommand Commande à envoyer + * @param receiver Le receveur de cette commande + */ public void setResultCommand(String resultCommand, ResultCmdReceiver receiver) { this.resultCommand = resultCommand; this.receiver = receiver; } + + /** + * Permet de récupérer l'option associée au protocol. + * @return L'option associée + */ + public FileOptions getOption() { + return option; + } + + /** + * Permet de lire un fichier. Cad reçevoir le contenu d'un fichier provenant du réseau. + * Redéfinissez cette méthode pour l'utiliser + * @param reader Buffer rempli du fichier + */ + public void read(BufferedReader reader) {} + + + /** + * Permet d'écrire un fichier. Cad reçevoir le contenu d'un fichier provenant du réseau + * @param writer Buffer à remplir, et qui sera envoyer au destinataire + */ + public void write(BufferedWriter writer) {} + } /** diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java index e3a0dc2..1b46e7a 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java @@ -2,6 +2,7 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.protocol.ProtocolReader; +import java.io.BufferedReader; import java.util.ArrayList; import java.util.List; @@ -26,6 +27,7 @@ public class HelloRule extends ProtocolReader { private final int port; public Result(String domain, int port) { + super(FileOptions.NONE); this.domain = domain; this.port = port; } @@ -37,6 +39,8 @@ public class HelloRule extends ProtocolReader { public int getPort() { return port; } + + } diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java index bbfc660..dd097c6 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java @@ -24,7 +24,7 @@ public class SigninRule extends ProtocolReader { private final String password; public Result(String login, String password) { - + super(FileOptions.NONE); this.login = login; this.password = password; } From 58517266b1f3992dd64836c171324b3174147053 Mon Sep 17 00:00:00 2001 From: EndMove Date: Sat, 5 Mar 2022 14:33:56 +0100 Subject: [PATCH 41/64] =?UTF-8?q?R=C3=A9ception=20d'un=20fichier=20prototy?= =?UTF-8?q?pe,=20correction=20de=20bugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/App.java | 5 +- .../domains/client/ClientHandler.java | 20 ++++--- .../protocol/ProtocolReader.java | 58 +----------------- .../protocol/rules/reader/FilelistRule.java | 26 ++++++++ .../protocol/rules/reader/HelloRule.java | 1 - .../protocol/rules/reader/SavefileRule.java | 59 +++++++++++++++++++ .../protocol/rules/reader/SigninRule.java | 28 ++++----- 7 files changed, 117 insertions(+), 80 deletions(-) create mode 100644 app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java create mode 100644 app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java index c3ee754..07b9ed6 100644 --- a/app/src/main/java/lightcontainer/App.java +++ b/app/src/main/java/lightcontainer/App.java @@ -8,7 +8,9 @@ import lightcontainer.domains.server.UnicastServerListener; import lightcontainer.interfaces.MulticastSPR; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.rules.reader.FilelistRule; import lightcontainer.protocol.rules.reader.HelloRule; +import lightcontainer.protocol.rules.reader.SavefileRule; import lightcontainer.protocol.rules.reader.SigninRule; import lightcontainer.protocol.rules.writer.SignError; import lightcontainer.protocol.rules.writer.SignOk; @@ -33,11 +35,12 @@ public class App { protocolRep.addReader(new HelloRule()); protocolRep.addReader(new SigninRule()); + protocolRep.addReader(new FilelistRule()); + protocolRep.addReader(new SavefileRule()); protocolRep.addWriter(new SignOk()); protocolRep.addWriter(new SignError()); - new UnicastServerListener(clientRep, protocolRep, UNICAST_PORT); new MulticastServerListener(storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT); FileFrontEnd ffe = new FileFrontEnd(clientRep, storeRep, protocolRep); diff --git a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java index 7d0b6ab..fa26a85 100644 --- a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java +++ b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java @@ -61,12 +61,12 @@ public class ClientHandler implements Runnable, AutoCloseable { private void initClient() { try { this.reader = new BufferedReader(new InputStreamReader( - this.client.getInputStream(), - StandardCharsets.UTF_8 + this.client.getInputStream(), + StandardCharsets.UTF_8 )); this.writer = new PrintWriter(new OutputStreamWriter( - this.client.getOutputStream(), - StandardCharsets.UTF_8 + this.client.getOutputStream(), + StandardCharsets.UTF_8 ), true); } catch (IOException e) { e.printStackTrace(); @@ -90,24 +90,26 @@ public class ClientHandler implements Runnable, AutoCloseable { ProtocolReader.ProtocolResult ruleResult = protocolRep.executeReader(command + "\r\n"); - if (isConnected()) { + ruleResult.read( + this.client.getInputStream() + ); if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND) { fileFrontEnd.newCommand(command, ruleResult.getResultCommand()); // Envoie dans la file de tâche FileFrontEnd en attente d'un traitement d'un StorBackEnd } else { writer.write(ruleResult.getResultCommand()); // Renvoye au client + writer.flush(); } } else { - authentificate(ruleResult); + authentication(ruleResult); } - } catch (IOException ignore) { } } } - private void authentificate(ProtocolReader.ProtocolResult ruleResult) { + private void authentication(ProtocolReader.ProtocolResult ruleResult) { try { SigninRule.Result signinResult = (SigninRule.Result) ruleResult; if (signinResult.checkCredentials()) { @@ -116,7 +118,7 @@ public class ClientHandler implements Runnable, AutoCloseable { writer.flush(); return; } - } catch (ClassCastException castException) {} + } catch (ClassCastException ignored) {} writer.write(protocolRep.executeWriter(SignError.NAME)); // Envoie SignError car echec de la connection writer.flush(); diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java index 55cadf5..3715d73 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java @@ -1,7 +1,6 @@ package lightcontainer.protocol; -import java.io.BufferedReader; -import java.io.BufferedWriter; +import java.io.InputStream; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -19,36 +18,12 @@ public abstract class ProtocolReader { STOREBACKEND } - public enum FileOptions { - - /** - * Ne lire/ecrire aucun fichier - */ - NONE, - - /** - * Lire un fichier : Implementer la méthode 'read' - */ - READ, - - /** - * Ecrire un fichier : Implementer la méthode 'write' - */ - WRITE - } - /** * Modèle utilisé par tout les résultats des règles de protocol. * Lorsqu'il retourne son résultat, on vérifie si il y a une demande de lecture/écriture de fichier depuis le réseau. Si oui on appel ces méthodes, sinon on ne fait rien. * Ensuite on regarde après l'exécution de ces méthode ou non si il y a une commande de retour ou non et l'envoyons au receiver spécifié par la commande. */ public abstract class ProtocolResult { - - /** - * Permet de déterminer si la class souhaite lire ou écrire un fichier. - */ - private final FileOptions option; - /** * Command qui sera renvoyée par exemple au client */ @@ -61,24 +36,13 @@ public abstract class ProtocolReader { */ private ResultCmdReceiver receiver; - - /** - * Spécifier une option correct afin de permettre au système de détecter ce qu'il doit exécuter. - * @param option Option - */ - public ProtocolResult(FileOptions option) { - this.option = option; - } - - public ResultCmdReceiver getReceiver() { return receiver; } - /** * Récupérer la commande à envoyer - * @return + * @return Commande */ public String getResultCommand() { return resultCommand; @@ -94,28 +58,12 @@ public abstract class ProtocolReader { this.receiver = receiver; } - /** - * Permet de récupérer l'option associée au protocol. - * @return L'option associée - */ - public FileOptions getOption() { - return option; - } - /** * Permet de lire un fichier. Cad reçevoir le contenu d'un fichier provenant du réseau. * Redéfinissez cette méthode pour l'utiliser * @param reader Buffer rempli du fichier */ - public void read(BufferedReader reader) {} - - - /** - * Permet d'écrire un fichier. Cad reçevoir le contenu d'un fichier provenant du réseau - * @param writer Buffer à remplir, et qui sera envoyer au destinataire - */ - public void write(BufferedWriter writer) {} - + public void read(InputStream reader) {} } /** diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java new file mode 100644 index 0000000..c544d61 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java @@ -0,0 +1,26 @@ +package lightcontainer.protocol.rules.reader; + +import lightcontainer.protocol.ProtocolReader; + +public class FilelistRule extends ProtocolReader { + // Constants + private static final String PATTERN = "^FILELIST\r\n$"; + + // Constructor + public FilelistRule() { + super(PATTERN); + } + + public class Result extends ProtocolResult { } + + /** + * Cette méthode est appelée lors de l'exécution de la règle + * @param data Paramètres pour créer la commande. + */ + @Override + protected FilelistRule.Result onExecuted(String... data) { + FilelistRule.Result result = new Result(); + result.setResultCommand("FILES endbenja.txt!500\r\n", ResultCmdReceiver.CLIENT); + return result; + } +} diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java index 1b46e7a..407e2dc 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java @@ -27,7 +27,6 @@ public class HelloRule extends ProtocolReader { private final int port; public Result(String domain, int port) { - super(FileOptions.NONE); this.domain = domain; this.port = port; } diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java new file mode 100644 index 0000000..1929480 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java @@ -0,0 +1,59 @@ +package lightcontainer.protocol.rules.reader; + +import lightcontainer.protocol.ProtocolReader; +import lightcontainer.utils.FileReceiver; + +import java.io.IOException; +import java.io.InputStream; + +public class SavefileRule extends ProtocolReader { + // Constants + private static final String PATTERN = "^SAVEFILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$"; + private static final int FILE_NAME = 0; // Index file name. + private static final int FILE_SIZE = 1; // Index file size. + + // Constructor + public SavefileRule() { + super(PATTERN); + } + + public class Result extends ProtocolResult { + // Variables + private final String filename; + private final int size; + + // Construct + public Result(String filename, int size) { + this.filename = filename; + this.size = size; + } + + @Override + public void read(InputStream reader) { + super.read(reader); + System.out.printf("Sauvegarde du fichier : %s %d\n", filename, size); + + try { + FileReceiver fileReceiver = new FileReceiver("D:\\"); + if (!fileReceiver.receiveFile(reader, this.filename, this.size)) + throw new IOException(); + + this.setResultCommand("SAVEFILE_OK\r\n", ResultCmdReceiver.CLIENT); + } catch (IOException e) { + this.setResultCommand("SAVEFILE_ERROR\r\n", ResultCmdReceiver.CLIENT); + e.printStackTrace(); + } + } + } + + /** + * Cette méthode est appelée lors de l'exécution de la règle + * @param data Paramètres pour créer la commande. + */ + @Override + protected SavefileRule.Result onExecuted(String... data) { + SavefileRule.Result result = new SavefileRule.Result(data[FILE_NAME], Integer.parseInt(data[FILE_SIZE])); + + return result; + } +} diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java index dd097c6..ad8006b 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java @@ -2,29 +2,26 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.protocol.ProtocolReader; +import java.io.InputStream; + public class SigninRule extends ProtocolReader { + // Constants + private static final String PATTERN = "^SIGNIN ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$"; + private static final int LOGIN = 0; // Index du domain dans le tableau de données + private static final int PASSWORD = 1; // Index du port dans le tableau de données - private static final String PATTERN = "^SIGNIN ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$"; - - // Index du domain dans le tableau de donnée - private static final int LOGIN = 0; - - //Index du port dans le tableau de donnée - private static final int PASSWORD = 1; - + // Constructor public SigninRule() { super(PATTERN); } - public class Result extends ProtocolResult { - + // Variables private final String login; - private final String password; + // Result constructor public Result(String login, String password) { - super(FileOptions.NONE); this.login = login; this.password = password; } @@ -40,8 +37,12 @@ public class SigninRule extends ProtocolReader { public boolean checkCredentials() { return getLogin().equals("aa") && getPassword().equals("aaaaa"); } - } + @Override + public void read(InputStream reader) { + + } + } @Override protected SigninRule.Result onExecuted(String... data) { @@ -53,7 +54,6 @@ public class SigninRule extends ProtocolReader { } else { result.setResultCommand("SIGN_ERROR\r\n", ResultCmdReceiver.CLIENT); } - return result; } } From f0e98158444fe74b7ff88989429c50f96b9c6d00 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 5 Mar 2022 16:01:22 +0100 Subject: [PATCH 42/64] =?UTF-8?q?Ajout=20possibilit=C3=A9=20d'=C3=A9crire?= =?UTF-8?q?=20un=20fichier=20sur=20le=20r=C3=A9seau?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/App.java | 10 ++++------ .../domains/client/ClientHandler.java | 8 ++++---- .../lightcontainer/protocol/ProtocolWriter.java | 14 ++++++++++++-- .../writer/{SignError.java => SignErrorRule.java} | 4 ++-- .../rules/writer/{SignOk.java => SignOkRule.java} | 4 ++-- 5 files changed, 24 insertions(+), 16 deletions(-) rename app/src/main/java/lightcontainer/protocol/rules/writer/{SignError.java => SignErrorRule.java} (75%) rename app/src/main/java/lightcontainer/protocol/rules/writer/{SignOk.java => SignOkRule.java} (76%) diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java index 07b9ed6..8de81fd 100644 --- a/app/src/main/java/lightcontainer/App.java +++ b/app/src/main/java/lightcontainer/App.java @@ -5,15 +5,13 @@ package lightcontainer; import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.domains.server.UnicastServerListener; -import lightcontainer.interfaces.MulticastSPR; import lightcontainer.interfaces.ProtocolRepository; -import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.reader.FilelistRule; import lightcontainer.protocol.rules.reader.HelloRule; import lightcontainer.protocol.rules.reader.SavefileRule; import lightcontainer.protocol.rules.reader.SigninRule; -import lightcontainer.protocol.rules.writer.SignError; -import lightcontainer.protocol.rules.writer.SignOk; +import lightcontainer.protocol.rules.writer.SignErrorRule; +import lightcontainer.protocol.rules.writer.SignOkRule; import lightcontainer.repository.ClientHandlerRepository; import lightcontainer.repository.FileFrontEnd; import lightcontainer.repository.ProtocolRepositoryImpl; @@ -38,8 +36,8 @@ public class App { protocolRep.addReader(new FilelistRule()); protocolRep.addReader(new SavefileRule()); - protocolRep.addWriter(new SignOk()); - protocolRep.addWriter(new SignError()); + protocolRep.addWriter(new SignOkRule()); + protocolRep.addWriter(new SignErrorRule()); new UnicastServerListener(clientRep, protocolRep, UNICAST_PORT); new MulticastServerListener(storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT); diff --git a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java index fa26a85..0b32715 100644 --- a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java +++ b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java @@ -4,8 +4,8 @@ import lightcontainer.interfaces.ClientHandlerFFE; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.reader.SigninRule; -import lightcontainer.protocol.rules.writer.SignError; -import lightcontainer.protocol.rules.writer.SignOk; +import lightcontainer.protocol.rules.writer.SignErrorRule; +import lightcontainer.protocol.rules.writer.SignOkRule; import java.io.*; import java.net.Socket; @@ -114,13 +114,13 @@ public class ClientHandler implements Runnable, AutoCloseable { SigninRule.Result signinResult = (SigninRule.Result) ruleResult; if (signinResult.checkCredentials()) { this.login = signinResult.getLogin(); - writer.write(protocolRep.executeWriter(SignOk.NAME)); + writer.write(protocolRep.executeWriter(SignOkRule.NAME)); writer.flush(); return; } } catch (ClassCastException ignored) {} - writer.write(protocolRep.executeWriter(SignError.NAME)); // Envoie SignError car echec de la connection + writer.write(protocolRep.executeWriter(SignErrorRule.NAME)); // Envoie SignError car echec de la connection writer.flush(); this.close(); // Fermeture de la connection } diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java index ba857bd..80d6154 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java @@ -1,5 +1,7 @@ package lightcontainer.protocol; +import java.io.InputStream; +import java.io.OutputStream; import java.util.StringJoiner; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -19,16 +21,17 @@ public abstract class ProtocolWriter { * Permet de récupérer le nom de la commande. * @return Nom de la commande. */ - public String getCmdName() { + public final String getCmdName() { return cmdName; } + /** * Permet de contruire une commande selon une règle établie. * @param data Les données à ajouter dans la commande; L'ordre défini leur position dans la commande * @return La commande construite */ - public String execute(String... data) { + public final String execute(String... data) { // Concatatène le nom de la commande avec les données (trim), avec un espace entre chaque String command; StringJoiner builder = new StringJoiner(" ", this.cmdName, "\r\n"); @@ -42,4 +45,11 @@ public abstract class ProtocolWriter { Matcher ruleMatcher = this.rulePattern.matcher(command); return ruleMatcher.matches() ? command : null; } + + /** + * Permet d'écrire un fichier sur le réseau. Cad envoyer le contenu d'un fichier sur le réseau. + * Redéfinissez cette méthode pour l'utiliser. + * @param writer Buffer à remplir qui sera envoyer via le réseau + */ + public void write(OutputStream writer) {} } diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SignError.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java similarity index 75% rename from app/src/main/java/lightcontainer/protocol/rules/writer/SignError.java rename to app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java index 0daa349..0c35635 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SignError.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java @@ -2,13 +2,13 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; -public class SignError extends ProtocolWriter { +public class SignErrorRule extends ProtocolWriter { private static final String PATTERN = "^SIGN_ERROR\r\n$"; public static final String NAME = "SIGN_ERROR"; - public SignError() { + public SignErrorRule() { super(NAME, PATTERN); } } diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SignOk.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java similarity index 76% rename from app/src/main/java/lightcontainer/protocol/rules/writer/SignOk.java rename to app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java index 848561c..44b3f3c 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SignOk.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java @@ -2,13 +2,13 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; -public class SignOk extends ProtocolWriter { +public class SignOkRule extends ProtocolWriter { private static final String PATTERN = "^SIGN_OK\r\n$"; public static final String NAME = "SIGN_OK"; - public SignOk() { + public SignOkRule() { super(NAME, PATTERN); } } From 6cf8522674aba12ea627d18cb12042e068c8fdeb Mon Sep 17 00:00:00 2001 From: EndMove Date: Sat, 5 Mar 2022 16:34:07 +0100 Subject: [PATCH 43/64] =?UTF-8?q?Syst=C3=A8me=20cryptagraphique=20AES=20GC?= =?UTF-8?q?M=20256?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lightcontainer/utils/AES_GCM.java | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 app/src/main/java/lightcontainer/utils/AES_GCM.java diff --git a/app/src/main/java/lightcontainer/utils/AES_GCM.java b/app/src/main/java/lightcontainer/utils/AES_GCM.java new file mode 100644 index 0000000..5aeed9d --- /dev/null +++ b/app/src/main/java/lightcontainer/utils/AES_GCM.java @@ -0,0 +1,126 @@ +package lightcontainer.utils; + +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; +import javax.crypto.spec.GCMParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.util.Base64; + +public class AES_GCM { + // Constants + public static final int AES_KEY_SIZE = 256; + public static final int GCM_IV_LENGTH = 16; + public static final int GCM_TAG_LENGTH = 16; + + public static void main(String[] args) throws Exception + { + // Text pour test : + String plainText = "salut fils de pute"; + + String IV = generateIV(); + String key = generateSecretKey(); + + System.out.println("Original Text : " + plainText); + + byte[] cipherText = encrypt(plainText.getBytes(), key, IV); + System.out.println("Encrypted Text : " + Base64.getEncoder().encodeToString(cipherText)); + + String decryptedText = decrypt(cipherText, key, IV); + System.out.println("DeCrypted Text : " + decryptedText); + } + + /** + * Decoder to decode base64 vector to byte vector. + * @param base64Vector A base64 encoded vector. + * @return Byte vector. + */ + private static byte[] decodeBase64(String base64Vector) { + Base64.Decoder b64Decoder = Base64.getDecoder(); + return b64Decoder.decode(base64Vector); + } + + /** + * Encoder to encode vector to base64 string. + * @param rawVector A raw vector. + * @return A base64 encoded vector. + */ + private static String encodeBase64(byte[] rawVector) { + Base64.Encoder b64Encoder = Base64.getEncoder(); + return b64Encoder.encodeToString(rawVector); + } + + /** + * Generate a secret key base64 encoded. + * @return New Secret key b64 encoded. + */ + public static String generateSecretKey() throws NoSuchAlgorithmException { + KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); + keyGenerator.init(AES_KEY_SIZE); + SecretKey key = keyGenerator.generateKey(); + return encodeBase64(key.getEncoded()); + } + + /** + * Generate an IV (initialisation vector) base64 encoded. + * @return New generated IV b64 encoded. + */ + public static String generateIV() { + byte[] IV = new byte[GCM_IV_LENGTH]; + SecureRandom random = new SecureRandom(); + random.nextBytes(IV); + return encodeBase64(IV); + } + + /** + * Encrypt, with AES GCM. + * @param plainContent Content to encrypt. + * @param key Base64 encoded secret key. + * @param IV Base64 encoded vector. + * @return The encrypted cipherContent. + */ + public static byte[] encrypt(byte[] plainContent, String key, String IV) throws Exception + { + // Get Cipher Instance + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); + + // Create SecretKeySpec + SecretKeySpec keySpec = new SecretKeySpec(decodeBase64(key), "AES"); + + // Create GCMParameterSpec + GCMParameterSpec gcmParameterSpec = new GCMParameterSpec(GCM_TAG_LENGTH * 8, decodeBase64(IV)); + + // Initialize Cipher for ENCRYPT_MODE + cipher.init(Cipher.ENCRYPT_MODE, keySpec, gcmParameterSpec); + + // Perform Encryption + return cipher.doFinal(plainContent); + } + + /** + * Decrypt, with AES GCM. + * @param cipherContent The encrypted cipherContent + * @param key Base64 encoded secret key. + * @param IV Base64 encoded vector. + * @return The decrypted plainContent. + */ + public static String decrypt(byte[] cipherContent, String key, String IV) throws Exception + { + // Get Cipher Instance + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); + + // Create SecretKeySpec + SecretKeySpec keySpec = new SecretKeySpec(decodeBase64(key), "AES"); + + // Create GCMParameterSpec + GCMParameterSpec gcmParameterSpec = new GCMParameterSpec(GCM_TAG_LENGTH*8, decodeBase64(IV)); + + // Initialize Cipher for DECRYPT_MODE + cipher.init(Cipher.DECRYPT_MODE, keySpec, gcmParameterSpec); + + // Perform Decryption + return new String(cipher.doFinal(cipherContent)); + } +} \ No newline at end of file From 2f1f72b1fc999a8a71d02ca3ffdf199fa5ca6ab1 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 5 Mar 2022 16:51:12 +0100 Subject: [PATCH 44/64] =?UTF-8?q?Syst=C3=A8me=20de=20synchronisation=20de?= =?UTF-8?q?=20l'information=20entre=20FileFrontEnd<>StorBackEnd=20->=20imp?= =?UTF-8?q?l=C3=A9mentation=20de=20AppData=20+=20ajout=20de=20la=20bibliot?= =?UTF-8?q?h=C3=A8que=20GSON=20=C3=A0=20build.gradle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 + .../java/lightcontainer/storage/AppData.java | 132 ++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 app/src/main/java/lightcontainer/storage/AppData.java diff --git a/app/build.gradle b/app/build.gradle index 2a11f36..5345a80 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,6 +22,8 @@ dependencies { // This dependency is used by the application. implementation 'com.google.guava:guava:30.1-jre' + // Use gson to serialize/deserialize json files + implementation 'com.google.code.gson:gson:2.9.0' } application { diff --git a/app/src/main/java/lightcontainer/storage/AppData.java b/app/src/main/java/lightcontainer/storage/AppData.java new file mode 100644 index 0000000..ba10605 --- /dev/null +++ b/app/src/main/java/lightcontainer/storage/AppData.java @@ -0,0 +1,132 @@ +package lightcontainer.storage; + +import java.util.HashMap; +import java.util.Map; + +/** + * AppData represents the database of the FileFrontEnd program. + * It contains an AppConfig instance and a collection of Users. + * + * @author Maximilien LEDOUX + * @version 1.0 + * @see AppConfig + * @see User + * @since 1.0 + */ +public class AppData { + + private static AppData instance = null; + private AppConfig appConfig; + private final Map users; + + + /** + * Constructs a new instance of AppData. + * Sets appConfig to null and creates a new Hashmap of users. + */ + private AppData() { + this.appConfig = null; + this.users = new HashMap<>(); + } + + /** + * @return An instance of this class. Always returns the same instance. + */ + public static AppData getInstance() { + if (instance == null) { + instance = new AppData(); + } + return instance; + } + + /** + * @return The AppConfig + */ + public AppConfig getAppConfig() { + return appConfig; + } + + /** + * Sets the AppConfig. This method sets the AppConfig for once and for all. + * It is locked after first call. + * + * @param appConfig The network configuration of the program. + */ + public void setAppConfig(AppConfig appConfig) { + if (this.appConfig == null) { + this.appConfig = appConfig; + } + } + + /** + * @param userName The name of the user. + * @return The user corresponding to userName, null otherwise. + */ + public User getUser(String userName) { + return this.users.get(userName); + } + + /** + * Use this method when a user signs up. + * + * @param user The user to add. + * @return True if the user was added. False if a user with the same name already exists. + */ + public boolean addUser(User user) { + if (this.users.containsKey(user.getName())) { + return false; + } else { + this.users.put(user.getName(), user); + return true; + } + } + + /** + * @param fileName The name of the file + * @param user The user + * @return The file corresponding to the given name and belonging to the user. Null if the user cannot be found or the file cannot be found + * @deprecated Maybe not useful. DO NOT USE FOR THE TIME BEING + */ + public File getFileOf(String fileName, User user) { + return this.users.get(user.getName()).getFile(fileName); + } + + /** + * Call this method after receiving SAVEFILE_OK from the StorBackEnd. + * Do NOT call when receiving SAVEFILE_ERROR, or it will break the system's synchronization. + *

+ * Adds the file of for a specific user. + * True indicates the success of the operation. + * False indicates the failure of the operation. + * + * @param file The file to add + * @param user The user who wants to add the file + * @return True if the user is found and a file with the same name doesn't already exist for this user. False otherwise. + */ + public boolean addFileFor(File file, User user) { + if (!this.users.containsKey(user.getName())) { + return false; + } else { + return this.users.get(user.getName()).addFile(file); + } + } + + /** + * Call this method after receiving REMOVEFILE_OK from the StorBackEnd. + * Do NOT call when receiving REMOVEFILE_ERROR, or it will break the system's synchronization. + * Deletes the file of for a specific user. + * True indicates the success of the operation. + * False indicates the failure of the operation. + * + * @param fileName The name of the file to delete + * @param user The user who wants to delete the file + * @return True if the user is found and the file was deleted. False otherwise. + */ + public boolean deleteFileOf(String fileName, User user) { + if (!this.users.containsKey(user.getName())) { + return false; + } else { + return this.users.get(user.getName()).deleteFile(fileName); + } + } +} From 5e95cee500a33beaf8a70c8cfc44130c012af1bb Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 5 Mar 2022 16:59:40 +0100 Subject: [PATCH 45/64] =?UTF-8?q?Syst=C3=A8me=20de=20synchronisation=20de?= =?UTF-8?q?=20l'information=20entre=20FileFrontEnd<>StorBackEnd=20->=20imp?= =?UTF-8?q?l=C3=A9mentation=20de=20AppConfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/storage/AppConfig.java | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 app/src/main/java/lightcontainer/storage/AppConfig.java diff --git a/app/src/main/java/lightcontainer/storage/AppConfig.java b/app/src/main/java/lightcontainer/storage/AppConfig.java new file mode 100644 index 0000000..7f767b8 --- /dev/null +++ b/app/src/main/java/lightcontainer/storage/AppConfig.java @@ -0,0 +1,88 @@ +package lightcontainer.storage; + +/** + * AppConfig represents all network related information needed for the program to work. + * + * @author Maximilien LEDOUX + * @version 1.0 + * @since 1.0 + */ +public class AppConfig { + + private static AppConfig instance = null; + private int unicastPort; + private String multicastIp; + private int multicastPort; + private String networkInterface; + private boolean isTls; + + /** + * Constructs a new instance of AppConfig. + * Sets all data to default values. + */ + private AppConfig() { + this.unicastPort = -1; + this.multicastIp = "NONE"; + this.multicastPort = -1; + this.networkInterface = "NONE"; + this.isTls = false; + } + + /** + * @return An instance of this class. Always returns the same instance. + */ + public static AppConfig getInstance() { + if (instance == null) { + instance = new AppConfig(); + } + return instance; + } + + public int getUnicastPort() { + return unicastPort; + } + + public void setUnicastPort(int unicastPort) { + if (this.unicastPort == -1) { + this.unicastPort = unicastPort; + } + } + + public String getMulticastIp() { + return multicastIp; + } + + public void setMulticastIp(String multicastIp) { + if (this.multicastIp.equals("NONE")) { + this.multicastIp = multicastIp; + } + } + + public int getMulticastPort() { + return multicastPort; + } + + public void setMulticastPort(int multicastPort) { + if (this.multicastPort == -1) { + this.multicastPort = multicastPort; + } + } + + public String getNetworkInterface() { + return networkInterface; + } + + public void setNetworkInterface(String networkInterface) { + if (this.networkInterface.equals("NONE")) { + this.networkInterface = networkInterface; + } + } + + public boolean isTls() { + return isTls; + } + + public void setTls(boolean tls) { + this.isTls = tls; + } +} From 28fded57636eeaf9ca6d1cfdf2c8cced88c8e43e Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 5 Mar 2022 17:00:05 +0100 Subject: [PATCH 46/64] =?UTF-8?q?Syst=C3=A8me=20de=20synchronisation=20de?= =?UTF-8?q?=20l'information=20entre=20FileFrontEnd<>StorBackEnd=20->=20cr?= =?UTF-8?q?=C3=A9ation=20de=20Repository=20et=20JsonRepository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/storage/JsonRepository.java | 15 +++++++++++++++ .../java/lightcontainer/storage/Repository.java | 8 ++++++++ 2 files changed, 23 insertions(+) create mode 100644 app/src/main/java/lightcontainer/storage/JsonRepository.java create mode 100644 app/src/main/java/lightcontainer/storage/Repository.java diff --git a/app/src/main/java/lightcontainer/storage/JsonRepository.java b/app/src/main/java/lightcontainer/storage/JsonRepository.java new file mode 100644 index 0000000..a002404 --- /dev/null +++ b/app/src/main/java/lightcontainer/storage/JsonRepository.java @@ -0,0 +1,15 @@ +package lightcontainer.storage; + +public class JsonRepository implements Repository { + + + @Override + public void save(String fileName, AppData data) { + + } + + @Override + public AppData load(String fileName) { + return null; + } +} diff --git a/app/src/main/java/lightcontainer/storage/Repository.java b/app/src/main/java/lightcontainer/storage/Repository.java new file mode 100644 index 0000000..79f19fd --- /dev/null +++ b/app/src/main/java/lightcontainer/storage/Repository.java @@ -0,0 +1,8 @@ +package lightcontainer.storage; + +public interface Repository { + + void save(String fileName, AppData data); + + AppData load(String fileName); +} From 49fe7fb7e7fd70ae465d5e1443fb050e6a84023d Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 5 Mar 2022 17:08:36 +0100 Subject: [PATCH 47/64] =?UTF-8?q?Syst=C3=A8me=20de=20synchronisation=20de?= =?UTF-8?q?=20l'information=20entre=20FileFrontEnd<>StorBackEnd=20->=20imp?= =?UTF-8?q?l=C3=A9mentation=20de=20User?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lightcontainer/storage/User.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 app/src/main/java/lightcontainer/storage/User.java diff --git a/app/src/main/java/lightcontainer/storage/User.java b/app/src/main/java/lightcontainer/storage/User.java new file mode 100644 index 0000000..1623703 --- /dev/null +++ b/app/src/main/java/lightcontainer/storage/User.java @@ -0,0 +1,72 @@ +package lightcontainer.storage; + +import java.util.Map; +import java.util.Set; + +/** + * User represents a user of the system. + * + * @author Maximilien LEDOUX + * @version 1.0 + * @since 1.0 + */ +public class User { + + private final String Name; + private final String password; + private final String aesKey; + private final Map files; + + public User(String Name, String password, String aesKey, Map files) { + this.Name = Name; + this.password = password; + this.aesKey = aesKey; + this.files = files; + } + + public String getName() { + return Name; + } + + public String getPassword() { + return password; + } + + public String getAesKey() { + return aesKey; + } + + public Set> getFilesIterator() { + return files.entrySet(); + } + + public File getFile(String fileName) { + return this.files.get(fileName); + } + + /** + * @param file The file to add. + * @return False if a file with the same name already exists. Otherwise, adds the file and returns true. + */ + public boolean addFile(File file) { + if (this.files.containsKey(file.getName())) { + return false; + } else { + this.files.put(file.getName(), file); + return true; + } + } + + /** + * @param fileName The name of the file to delete. + * @return True if the file was deleted. False otherwise. + */ + public boolean deleteFile(String fileName) { + if (this.files.containsKey(fileName)) { + this.files.remove(fileName); + return true; + } else { + return false; + } + } +} From b2d34dbaf4eee549477fecf8d2b5be8efb9e8c7a Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 5 Mar 2022 17:25:55 +0100 Subject: [PATCH 48/64] =?UTF-8?q?Syst=C3=A8me=20de=20synchronisation=20de?= =?UTF-8?q?=20l'information=20entre=20FileFrontEnd<>StorBackEnd=20->=20imp?= =?UTF-8?q?l=C3=A9mentation=20de=20File?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lightcontainer/storage/File.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 app/src/main/java/lightcontainer/storage/File.java diff --git a/app/src/main/java/lightcontainer/storage/File.java b/app/src/main/java/lightcontainer/storage/File.java new file mode 100644 index 0000000..dcee5cc --- /dev/null +++ b/app/src/main/java/lightcontainer/storage/File.java @@ -0,0 +1,44 @@ +package lightcontainer.storage; + +import java.util.Iterator; +import java.util.Set; + +public class File { + + private final String name; + private final int size; + private final String iv; + private final Set storage; + + public File(String name, int size, String iv, Set storage) { + this.name = name; + this.size = size; + this.iv = iv; + this.storage = storage; + } + + public String getName() { + return name; + } + + public int getSize() { + return size; + } + + public String getIv() { + return iv; + } + + public Iterator getStorageIterator() { + return storage.iterator(); + } + + public boolean addStorage(String storage) { + if (this.storage.contains(storage)) { + return false; + } else { + this.storage.add(storage); + return true; + } + } +} From 0161077cdd0506a41008ac9ea1291f7772d17355 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 5 Mar 2022 17:35:09 +0100 Subject: [PATCH 49/64] =?UTF-8?q?Syst=C3=A8me=20de=20synchronisation=20de?= =?UTF-8?q?=20l'information=20entre=20FileFrontEnd<>StorBackEnd=20->=20add?= =?UTF-8?q?Storage=20:=20ajouter=20des=20StorBackEnd=20=C3=A0=20un=20fichi?= =?UTF-8?q?er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/lightcontainer/storage/AppData.java | 14 ++++++++++++++ app/src/main/java/lightcontainer/storage/User.java | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/app/src/main/java/lightcontainer/storage/AppData.java b/app/src/main/java/lightcontainer/storage/AppData.java index ba10605..88b245e 100644 --- a/app/src/main/java/lightcontainer/storage/AppData.java +++ b/app/src/main/java/lightcontainer/storage/AppData.java @@ -129,4 +129,18 @@ public class AppData { return this.users.get(user.getName()).deleteFile(fileName); } } + + /** + * @param user The user who wants to add a storage for their file + * @param file The file that needs a new storage + * @param storage The storage to add + * @return True if the storage was added. False otherwise. + */ + public boolean addStorage(User user, File file, String storage) { + if (!this.users.containsKey(user.getName())) { + return false; + } else { + return this.users.get(user.getName()).addStorage(file, storage); + } + } } diff --git a/app/src/main/java/lightcontainer/storage/User.java b/app/src/main/java/lightcontainer/storage/User.java index 1623703..683fb07 100644 --- a/app/src/main/java/lightcontainer/storage/User.java +++ b/app/src/main/java/lightcontainer/storage/User.java @@ -69,4 +69,17 @@ public class User { return false; } } + + /** + * @param file The file that needs a storage + * @param storage The storage name + * @return True if the storage was added to the file. False otherwise. + */ + public boolean addStorage(File file, String storage) { + if (this.files.containsKey(file.getName())) { + return file.addStorage(storage); + } else { + return false; + } + } } From a185a3ecb77fe04360ab7f2635080743c9f0a764 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Sat, 5 Mar 2022 17:48:56 +0100 Subject: [PATCH 50/64] =?UTF-8?q?Sauvegarde=20et=20lecture=20du=20fichier?= =?UTF-8?q?=20de=20synchronisation=20->=20changement=20de=20structure=20po?= =?UTF-8?q?ur=20une=20meilleur=20d=C3=A9coupe=20des=20responsabilit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/storage/FileReader.java | 6 ++++++ app/src/main/java/lightcontainer/storage/FileWriter.java | 6 ++++++ app/src/main/java/lightcontainer/storage/JsonReader.java | 9 +++++++++ .../main/java/lightcontainer/storage/JsonRepository.java | 6 ++++-- app/src/main/java/lightcontainer/storage/JsonWriter.java | 9 +++++++++ app/src/main/java/lightcontainer/storage/Repository.java | 4 ++-- 6 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/lightcontainer/storage/FileReader.java create mode 100644 app/src/main/java/lightcontainer/storage/FileWriter.java create mode 100644 app/src/main/java/lightcontainer/storage/JsonReader.java create mode 100644 app/src/main/java/lightcontainer/storage/JsonWriter.java diff --git a/app/src/main/java/lightcontainer/storage/FileReader.java b/app/src/main/java/lightcontainer/storage/FileReader.java new file mode 100644 index 0000000..4e79a0b --- /dev/null +++ b/app/src/main/java/lightcontainer/storage/FileReader.java @@ -0,0 +1,6 @@ +package lightcontainer.storage; + +public interface FileReader { + + AppData readFile(String fileName); +} diff --git a/app/src/main/java/lightcontainer/storage/FileWriter.java b/app/src/main/java/lightcontainer/storage/FileWriter.java new file mode 100644 index 0000000..3cef3aa --- /dev/null +++ b/app/src/main/java/lightcontainer/storage/FileWriter.java @@ -0,0 +1,6 @@ +package lightcontainer.storage; + +public interface FileWriter { + + void writeToFile(String fileName, AppData appData); +} diff --git a/app/src/main/java/lightcontainer/storage/JsonReader.java b/app/src/main/java/lightcontainer/storage/JsonReader.java new file mode 100644 index 0000000..0b67603 --- /dev/null +++ b/app/src/main/java/lightcontainer/storage/JsonReader.java @@ -0,0 +1,9 @@ +package lightcontainer.storage; + +public class JsonReader implements FileReader { + + @Override + public AppData readFile(String fileName) { + return null; + } +} diff --git a/app/src/main/java/lightcontainer/storage/JsonRepository.java b/app/src/main/java/lightcontainer/storage/JsonRepository.java index a002404..c2c693d 100644 --- a/app/src/main/java/lightcontainer/storage/JsonRepository.java +++ b/app/src/main/java/lightcontainer/storage/JsonRepository.java @@ -4,12 +4,14 @@ public class JsonRepository implements Repository { @Override - public void save(String fileName, AppData data) { + public void save(FileWriter fileWriter) { } @Override - public AppData load(String fileName) { + public AppData load(FileReader fileReader) { return null; } + + } diff --git a/app/src/main/java/lightcontainer/storage/JsonWriter.java b/app/src/main/java/lightcontainer/storage/JsonWriter.java new file mode 100644 index 0000000..56fceb9 --- /dev/null +++ b/app/src/main/java/lightcontainer/storage/JsonWriter.java @@ -0,0 +1,9 @@ +package lightcontainer.storage; + +public class JsonWriter implements FileWriter { + + @Override + public void writeToFile(String fileName, AppData appData) { + + } +} diff --git a/app/src/main/java/lightcontainer/storage/Repository.java b/app/src/main/java/lightcontainer/storage/Repository.java index 79f19fd..b688fc7 100644 --- a/app/src/main/java/lightcontainer/storage/Repository.java +++ b/app/src/main/java/lightcontainer/storage/Repository.java @@ -2,7 +2,7 @@ package lightcontainer.storage; public interface Repository { - void save(String fileName, AppData data); + void save(FileWriter fileWriter); - AppData load(String fileName); + AppData load(FileReader fileReader); } From 38a403d6a156e3216adc0da10860ae940d537144 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 5 Mar 2022 18:32:55 +0100 Subject: [PATCH 51/64] =?UTF-8?q?Ajout=20possibilit=C3=A9=20d'=C3=A9crire?= =?UTF-8?q?=20un=20fichier=20fichier=20sur=20le=20r=C3=A9seau=20et=20ajout?= =?UTF-8?q?=20de=20celle-ci=20pour=20le=20store=20backend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/App.java | 31 +++++++++++ .../domains/client/ClientHandler.java | 7 ++- .../domains/client/StoreProcessor.java | 55 +++++++++++++++++-- .../server/MulticastServerListener.java | 2 +- .../interfaces/ProtocolRepository.java | 2 +- .../protocol/ProtocolWriter.java | 42 ++++++++++---- .../repository/ProtocolRepositoryImpl.java | 4 +- 7 files changed, 121 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java index 8de81fd..44860f4 100644 --- a/app/src/main/java/lightcontainer/App.java +++ b/app/src/main/java/lightcontainer/App.java @@ -25,6 +25,36 @@ public class App { private static final String MULTICAST_IP = "226.66.66.1"; private static final int MULTICAST_PORT = 42500; + + /* + private static Thread t1 = null; + + public static void main(String[] args) throws InterruptedException { + t1 = new Thread(new Runnable() { + @Override + public void run() { + int i = 0; + while (true) { + System.out.println("HEY " + i++); + + try { + synchronized (t1) { + System.out.println("SUSPEND"); + t1.wait(); + } + } catch (InterruptedException e) {} + } + } + }); + t1.start(); + System.out.println("START"); + Thread.sleep(1000); + synchronized (t1) { + t1.notify(); + } + } + */ + public static void main(String[] args) throws InterruptedException { // Create all repository ClientHandlerRepository clientRep = new ClientHandlerRepository(); @@ -50,4 +80,5 @@ public class App { clientRep.close(); storeRep.close(); } + } diff --git a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java index 0b32715..773ecc3 100644 --- a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java +++ b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java @@ -3,6 +3,7 @@ package lightcontainer.domains.client; import lightcontainer.interfaces.ClientHandlerFFE; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.ProtocolWriter; import lightcontainer.protocol.rules.reader.SigninRule; import lightcontainer.protocol.rules.writer.SignErrorRule; import lightcontainer.protocol.rules.writer.SignOkRule; @@ -114,13 +115,15 @@ public class ClientHandler implements Runnable, AutoCloseable { SigninRule.Result signinResult = (SigninRule.Result) ruleResult; if (signinResult.checkCredentials()) { this.login = signinResult.getLogin(); - writer.write(protocolRep.executeWriter(SignOkRule.NAME)); + ProtocolWriter.ProtocolResult signokResult = protocolRep.executeWriter(SignOkRule.NAME); + writer.write(signokResult.getCommand()); writer.flush(); return; } } catch (ClassCastException ignored) {} - writer.write(protocolRep.executeWriter(SignErrorRule.NAME)); // Envoie SignError car echec de la connection + ProtocolWriter.ProtocolResult signErrorResult = protocolRep.executeWriter(SignErrorRule.NAME); + writer.write(signErrorResult.getCommand()); // Envoie SignError car echec de la connection writer.flush(); this.close(); // Fermeture de la connection } diff --git a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java index b573ab4..7a2321f 100644 --- a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java @@ -1,6 +1,9 @@ package lightcontainer.domains.client; +import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.interfaces.StoreProcessorFFE; +import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.ProtocolWriter; import java.io.*; import java.net.Socket; @@ -21,7 +24,7 @@ import java.util.Objects; * @see AutoCloseable * @author Jérémi NIHART */ -public class StoreProcessor implements Runnable, AutoCloseable { +public class StoreProcessor extends Thread implements AutoCloseable { // Variables private final StoreProcessorFFE fileFrontEnd; private final Socket store; @@ -30,12 +33,15 @@ public class StoreProcessor implements Runnable, AutoCloseable { private BufferedReader reader; private PrintWriter writer; + private String currentCommand; + private ProtocolRepository protocolRep; // Constructor - public StoreProcessor(Socket socket, String domain, StoreProcessorFFE ffe) { + public StoreProcessor(Socket socket, String domain, StoreProcessorFFE ffe, ProtocolRepository protocolRep) { this.domain = domain; this.fileFrontEnd = ffe; this.store = socket; + this.protocolRep = protocolRep; this.client_run = false; initStore(); } @@ -73,13 +79,52 @@ public class StoreProcessor implements Runnable, AutoCloseable { this.client_run = true; while (this.client_run) { try { - String command = this.reader.readLine(); - // TODO gestion de la réception de commandes, fichier, ... - if (command != null) System.out.println("StoreBackEnd: " + command); + alertAvalaible(); + + // Request + ProtocolWriter.ProtocolResult requestResult = protocolRep.executeWriter(this.currentCommand); + this.writer.write(requestResult.getCommand()); + requestResult.write(this.store.getOutputStream()); + + + // Response + String responseCommand = this.reader.readLine(); + if (responseCommand != null) + System.out.println("StoreBackEnd: " + responseCommand); + ProtocolReader.ProtocolResult responseResult = protocolRep.executeReader(responseCommand); + System.out.println("StoreBackEnd response to client: " + responseResult.getResultCommand()); + + } catch (IOException ignore) { } } } + /** + * Permet de demander au StoreBackEnd d'effectuer une commande + * @param command La commande à effectuer + */ + public void executeCommand(String command) { + synchronized (this) { + this.currentCommand = command; + this.notify(); + } + } + + /** + * Permet de déclarer le StoreBackEnd disponible + */ + private void alertAvalaible() { + synchronized (this) { + this.currentCommand = null; + + fileFrontEnd.onStoreAvailable(this); + + try { + this.wait(); + } catch (InterruptedException e) { e.printStackTrace(); } + } + } + /** * AutoClosable Function * Close the Storage thread and resources. diff --git a/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java index 98996f3..f88fa56 100644 --- a/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java +++ b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java @@ -69,7 +69,7 @@ public class MulticastServerListener implements Runnable { Socket socket = new Socket(packet.getAddress(), readerResult.getPort()); // Create the store processor - StoreProcessor storeProcessor = new StoreProcessor(socket, readerResult.getDomain(), null); // TODO : Voir comment on procède get via repo ou ici ?! + StoreProcessor storeProcessor = new StoreProcessor(socket, readerResult.getDomain(), null, protocolRep); // TODO : Voir comment on procède get via repo ou ici ?! // Add the store processor to its repository this.repository.addStore(storeProcessor); } catch (IOException ignore) { diff --git a/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java b/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java index af435d1..1f9f48f 100644 --- a/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java +++ b/app/src/main/java/lightcontainer/interfaces/ProtocolRepository.java @@ -7,7 +7,7 @@ public interface ProtocolRepository { T executeReader(String data); - String executeWriter(String cmdName, String... datas); + T executeWriter(String cmdName, String... data); void addReader(ProtocolReader reader); diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java index 80d6154..6b3801f 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java @@ -25,31 +25,51 @@ public abstract class ProtocolWriter { return cmdName; } + public class ProtocolResult { + + private String command; + + public String getCommand() { + return command; + } + + private void setCommand(String command) { + this.command = command; + } + + /** + * Permet d'écrire un fichier sur le réseau. Cad envoyer le contenu d'un fichier sur le réseau. + * Redéfinissez cette méthode pour l'utiliser. + * @param writer Buffer à remplir qui sera envoyer via le réseau + */ + public void write(OutputStream writer) {} + } /** * Permet de contruire une commande selon une règle établie. * @param data Les données à ajouter dans la commande; L'ordre défini leur position dans la commande * @return La commande construite */ - public final String execute(String... data) { + public final T execute(String... data) { // Concatatène le nom de la commande avec les données (trim), avec un espace entre chaque - String command; StringJoiner builder = new StringJoiner(" ", this.cmdName, "\r\n"); - for (String param : data) builder.add(param); - command = builder.toString(); + String command = builder.toString(); + Matcher ruleMatcher = this.rulePattern.matcher(command); // Vérifie que tout match (cf. Matcher). Si match alors on retourne la commande build, sinon on retourne NULL - // Vérifie que tout match (cf. Matcher). Si match alors on retourne la commande build, sinon on retourne NULL - Matcher ruleMatcher = this.rulePattern.matcher(command); - return ruleMatcher.matches() ? command : null; + if (ruleMatcher.matches()) { + ProtocolResult result = onExecuted(); + result.setCommand(command); + return (T) result; + } + return null; } /** - * Permet d'écrire un fichier sur le réseau. Cad envoyer le contenu d'un fichier sur le réseau. - * Redéfinissez cette méthode pour l'utiliser. - * @param writer Buffer à remplir qui sera envoyer via le réseau + * Cette méthode est appelée lors de l'exécution de la règle */ - public void write(OutputStream writer) {} + protected abstract T onExecuted(); + } diff --git a/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java b/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java index 4bb1c84..86da726 100644 --- a/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java +++ b/app/src/main/java/lightcontainer/repository/ProtocolRepositoryImpl.java @@ -23,9 +23,9 @@ public class ProtocolRepositoryImpl implements ProtocolRepository { } @Override - public String executeWriter(String cmdName, String... data) { + public T executeWriter(String cmdName, String... data) { for (ProtocolWriter writer : writers) { - String command; + T command; if (cmdName.equals(writer.getCmdName()) && (command = writer.execute(data)) != null) { return command; } From e3635b980b903619d2ae11f9cce611da4564edc0 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sun, 6 Mar 2022 17:29:04 +0100 Subject: [PATCH 52/64] =?UTF-8?q?-=20Syst=C3=A8me=20de=20de=20lecture/ecri?= =?UTF-8?q?ture=20fichier=20fini.=20-=20Syst=C3=A8me=20de=20t=C3=A2che=20p?= =?UTF-8?q?resque=20fini=20et=20synchronisation.=20Reste=20=C3=A0=20alerte?= =?UTF-8?q?r=20SBE=20d'une=20nouvelle=20t=C3=A2che=20et=20permettre=20?= =?UTF-8?q?=C3=A0=20un=20SBE=20d'attendre=20un=20t=C3=A2che?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/App.java | 12 ++++--- .../java/lightcontainer/domains/Task.java | 18 +++++++++- .../domains/client/ClientHandler.java | 33 +++++++++++++++++-- .../domains/client/StoreProcessor.java | 17 ++++++++-- .../enumerations/TaskStatus.java | 14 ++++++++ .../interfaces/StoreProcessorFFE.java | 4 ++- .../lightcontainer/interfaces/UnicastCHR.java | 3 ++ .../protocol/ProtocolReader.java | 6 ++-- .../protocol/ProtocolWriter.java | 6 ++-- .../protocol/rules/reader/FilelistRule.java | 11 +++++-- .../protocol/rules/reader/SavefileRule.java | 12 +++++-- .../protocol/rules/reader/SigninRule.java | 12 +++++-- .../protocol/rules/writer/FilesRule.java | 15 +++++++++ .../rules/writer/SaveFileErrorRule.java | 15 +++++++++ .../protocol/rules/writer/SaveFileOkRule.java | 15 +++++++++ .../protocol/rules/writer/SignErrorRule.java | 1 + .../repository/ClientHandlerRepository.java | 8 +++++ .../repository/FileFrontEnd.java | 17 ++++++++-- 18 files changed, 191 insertions(+), 28 deletions(-) create mode 100644 app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java create mode 100644 app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java create mode 100644 app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java index 44860f4..58584a3 100644 --- a/app/src/main/java/lightcontainer/App.java +++ b/app/src/main/java/lightcontainer/App.java @@ -10,8 +10,7 @@ import lightcontainer.protocol.rules.reader.FilelistRule; import lightcontainer.protocol.rules.reader.HelloRule; import lightcontainer.protocol.rules.reader.SavefileRule; import lightcontainer.protocol.rules.reader.SigninRule; -import lightcontainer.protocol.rules.writer.SignErrorRule; -import lightcontainer.protocol.rules.writer.SignOkRule; +import lightcontainer.protocol.rules.writer.*; import lightcontainer.repository.ClientHandlerRepository; import lightcontainer.repository.FileFrontEnd; import lightcontainer.repository.ProtocolRepositoryImpl; @@ -62,12 +61,15 @@ public class App { ProtocolRepository protocolRep = new ProtocolRepositoryImpl(); protocolRep.addReader(new HelloRule()); - protocolRep.addReader(new SigninRule()); - protocolRep.addReader(new FilelistRule()); - protocolRep.addReader(new SavefileRule()); + protocolRep.addReader(new SigninRule(protocolRep)); + protocolRep.addReader(new FilelistRule(protocolRep)); + protocolRep.addReader(new SavefileRule(protocolRep)); protocolRep.addWriter(new SignOkRule()); protocolRep.addWriter(new SignErrorRule()); + protocolRep.addWriter(new FilesRule()); + protocolRep.addWriter(new SaveFileOkRule()); + protocolRep.addWriter(new SaveFileErrorRule()); new UnicastServerListener(clientRep, protocolRep, UNICAST_PORT); new MulticastServerListener(storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT); diff --git a/app/src/main/java/lightcontainer/domains/Task.java b/app/src/main/java/lightcontainer/domains/Task.java index 9ff6369..556b339 100644 --- a/app/src/main/java/lightcontainer/domains/Task.java +++ b/app/src/main/java/lightcontainer/domains/Task.java @@ -5,7 +5,6 @@ import lightcontainer.enumerations.TaskType; public class Task { // Variables - private TaskType type; // TODO : Supprimer car innutile ? private TaskStatus status; private String command; private String client; @@ -21,4 +20,21 @@ public class Task { Task task = new Task(TaskStatus.PENDING, command, client); return task; } + + /** + * Permet de savoir si la réponse est destinée au client + * @param storeDomain Nom du store back end fournissant la réponse. + * @return TRUE si le client doit recevoir cette réponse. + */ + public boolean isResponseOfClient(String storeDomain) { + return (this.storeDomain == storeDomain && status == TaskStatus.PENDING); + } + + /** + * Permet de récupérer le login du client associé à la tâche + * @return Login du client + */ + public String getClient() { + return client; + } } diff --git a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java index 773ecc3..b75ade2 100644 --- a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java +++ b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java @@ -41,6 +41,7 @@ public class ClientHandler implements Runnable, AutoCloseable { private BufferedReader reader; private PrintWriter writer; + private ProtocolWriter.ProtocolResult response; // Constructor public ClientHandler(Socket client, ClientHandlerFFE ffe, ProtocolRepository protocolRep) { @@ -86,20 +87,27 @@ public class ClientHandler implements Runnable, AutoCloseable { while (this.client_run) { try { String command = this.reader.readLine(); - // TODO gestion de la réception de commandes, fichier, ... if (command != null) System.out.println("Client: " + command); ProtocolReader.ProtocolResult ruleResult = protocolRep.executeReader(command + "\r\n"); if (isConnected()) { + ProtocolWriter.ProtocolResult writerCommand = ruleResult.getResultCommand(); ruleResult.read( this.client.getInputStream() ); if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND) { - fileFrontEnd.newCommand(command, ruleResult.getResultCommand()); // Envoie dans la file de tâche FileFrontEnd en attente d'un traitement d'un StorBackEnd + fileFrontEnd.newCommand(command, writerCommand.getCommand()); // Envoie dans la file de tâche FileFrontEnd en attente d'un traitement d'un StorBackEnd + + // Attend la fin de la réalisation de la tâche + waitTaskResponse(); + + writer.write(response.getCommand()); // Renvoye au client + writer.flush(); + response.write(this.client.getOutputStream()); // Ecrit au client si nécessaire } else { - writer.write(ruleResult.getResultCommand()); // Renvoye au client + writer.write(writerCommand.getCommand()); // Renvoye au client writer.flush(); } @@ -107,6 +115,25 @@ public class ClientHandler implements Runnable, AutoCloseable { authentication(ruleResult); } } catch (IOException ignore) { } + + } + } + + /** + * Permet au Client d'attendre la fin de la réalisation de sa tâche + */ + private void waitTaskResponse() { + synchronized (this) { + try { + this.wait(); + } catch (InterruptedException e) { e.printStackTrace(); } + } + } + + public void respond(ProtocolWriter.ProtocolResult response) { + this.response = response; + synchronized (this) { + this.notify(); } } diff --git a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java index 7a2321f..450eb35 100644 --- a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java @@ -79,7 +79,7 @@ public class StoreProcessor extends Thread implements AutoCloseable { this.client_run = true; while (this.client_run) { try { - alertAvalaible(); + waitAction(); // Request ProtocolWriter.ProtocolResult requestResult = protocolRep.executeWriter(this.currentCommand); @@ -92,8 +92,11 @@ public class StoreProcessor extends Thread implements AutoCloseable { if (responseCommand != null) System.out.println("StoreBackEnd: " + responseCommand); ProtocolReader.ProtocolResult responseResult = protocolRep.executeReader(responseCommand); + responseResult.read(this.store.getInputStream()); System.out.println("StoreBackEnd response to client: " + responseResult.getResultCommand()); + alertAvalaible(responseResult.getResultCommand()); + // TODO : Faire en sorte que getResultCommand retourne un ProtocolWriter } catch (IOException ignore) { } } @@ -113,12 +116,20 @@ public class StoreProcessor extends Thread implements AutoCloseable { /** * Permet de déclarer le StoreBackEnd disponible */ - private void alertAvalaible() { + private void alertAvalaible(ProtocolWriter.ProtocolResult responseCommand) { synchronized (this) { + waitAction(); this.currentCommand = null; - fileFrontEnd.onStoreAvailable(this); + fileFrontEnd.onStoreAvailable(this, responseCommand); + } + } + /** + * Permet au Store d'attendre une action à réaliser + */ + private void waitAction() { + synchronized (this) { try { this.wait(); } catch (InterruptedException e) { e.printStackTrace(); } diff --git a/app/src/main/java/lightcontainer/enumerations/TaskStatus.java b/app/src/main/java/lightcontainer/enumerations/TaskStatus.java index 4113565..12200e6 100644 --- a/app/src/main/java/lightcontainer/enumerations/TaskStatus.java +++ b/app/src/main/java/lightcontainer/enumerations/TaskStatus.java @@ -6,8 +6,22 @@ import lightcontainer.domains.Task; * Enumeration defining the status of a {@link Task}. */ public enum TaskStatus { + + /** + * En attente d'être traitée + */ PENDING, + + /** + * En train d'être traitée + */ PROCESSING, + + /** + * Une erreur est survenue + */ ERROR, + + SUCCESS } diff --git a/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java b/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java index 5e95d5f..26be68b 100644 --- a/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java +++ b/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java @@ -1,6 +1,7 @@ package lightcontainer.interfaces; import lightcontainer.domains.client.StoreProcessor; +import lightcontainer.protocol.ProtocolWriter; import lightcontainer.repository.FileFrontEnd; /** @@ -10,6 +11,7 @@ public interface StoreProcessorFFE { /** * Allows a {@link StoreProcessor} to notify the FFE that it's available. * @param store The store processor that is now available. + * @param responseCommand */ - void onStoreAvailable(StoreProcessor store); + void onStoreAvailable(StoreProcessor store, ProtocolWriter.ProtocolResult response); } diff --git a/app/src/main/java/lightcontainer/interfaces/UnicastCHR.java b/app/src/main/java/lightcontainer/interfaces/UnicastCHR.java index 599093c..160b533 100644 --- a/app/src/main/java/lightcontainer/interfaces/UnicastCHR.java +++ b/app/src/main/java/lightcontainer/interfaces/UnicastCHR.java @@ -3,6 +3,7 @@ package lightcontainer.interfaces; import lightcontainer.domains.client.ClientHandler; import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.domains.server.UnicastServerListener; +import lightcontainer.protocol.ProtocolWriter; import lightcontainer.repository.ClientHandlerRepository; /** @@ -20,4 +21,6 @@ public interface UnicastCHR { * @param client Client Handler to add. */ void addClient(ClientHandler client); + + void respondToClient(String client, ProtocolWriter.ProtocolResult response); } diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java index 3715d73..54e3a9e 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java @@ -27,7 +27,7 @@ public abstract class ProtocolReader { /** * Command qui sera renvoyée par exemple au client */ - private String resultCommand; + private ProtocolWriter.ProtocolResult resultCommand; /** * Désigne vers ou cette commande est envoyée. @@ -44,7 +44,7 @@ public abstract class ProtocolReader { * Récupérer la commande à envoyer * @return Commande */ - public String getResultCommand() { + public ProtocolWriter.ProtocolResult getResultCommand() { return resultCommand; } @@ -53,7 +53,7 @@ public abstract class ProtocolReader { * @param resultCommand Commande à envoyer * @param receiver Le receveur de cette commande */ - public void setResultCommand(String resultCommand, ResultCmdReceiver receiver) { + public void setResultCommand(ProtocolWriter.ProtocolResult resultCommand, ResultCmdReceiver receiver) { this.resultCommand = resultCommand; this.receiver = receiver; } diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java index 6b3801f..665609a 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java @@ -60,7 +60,7 @@ public abstract class ProtocolWriter { Matcher ruleMatcher = this.rulePattern.matcher(command); // Vérifie que tout match (cf. Matcher). Si match alors on retourne la commande build, sinon on retourne NULL if (ruleMatcher.matches()) { - ProtocolResult result = onExecuted(); + ProtocolResult result = onExecuted(data); result.setCommand(command); return (T) result; } @@ -70,6 +70,8 @@ public abstract class ProtocolWriter { /** * Cette méthode est appelée lors de l'exécution de la règle */ - protected abstract T onExecuted(); + protected T onExecuted(String... data) { + return (T) new ProtocolResult(); + } } diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java index c544d61..3b292be 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java @@ -1,14 +1,21 @@ package lightcontainer.protocol.rules.reader; +import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.ProtocolWriter; +import lightcontainer.protocol.rules.writer.FilesRule; +import lightcontainer.protocol.rules.writer.SignOkRule; public class FilelistRule extends ProtocolReader { // Constants private static final String PATTERN = "^FILELIST\r\n$"; + private ProtocolRepository protocolRep; + // Constructor - public FilelistRule() { + public FilelistRule(ProtocolRepository protocolRep) { super(PATTERN); + this.protocolRep = protocolRep; } public class Result extends ProtocolResult { } @@ -20,7 +27,7 @@ public class FilelistRule extends ProtocolReader { @Override protected FilelistRule.Result onExecuted(String... data) { FilelistRule.Result result = new Result(); - result.setResultCommand("FILES endbenja.txt!500\r\n", ResultCmdReceiver.CLIENT); + result.setResultCommand(this.protocolRep.executeWriter(FilesRule.NAME, "endbenja.txt!500"), ResultCmdReceiver.CLIENT); return result; } } diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java index 1929480..a2565f1 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java @@ -1,6 +1,9 @@ package lightcontainer.protocol.rules.reader; +import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.rules.writer.SaveFileErrorRule; +import lightcontainer.protocol.rules.writer.SaveFileOkRule; import lightcontainer.utils.FileReceiver; import java.io.IOException; @@ -12,9 +15,12 @@ public class SavefileRule extends ProtocolReader { private static final int FILE_NAME = 0; // Index file name. private static final int FILE_SIZE = 1; // Index file size. + private ProtocolRepository protocolRep; + // Constructor - public SavefileRule() { + public SavefileRule(ProtocolRepository protocolRep) { super(PATTERN); + this.protocolRep = protocolRep; } public class Result extends ProtocolResult { @@ -38,9 +44,9 @@ public class SavefileRule extends ProtocolReader { if (!fileReceiver.receiveFile(reader, this.filename, this.size)) throw new IOException(); - this.setResultCommand("SAVEFILE_OK\r\n", ResultCmdReceiver.CLIENT); + this.setResultCommand(protocolRep.executeWriter(SaveFileOkRule.NAME), ResultCmdReceiver.CLIENT); } catch (IOException e) { - this.setResultCommand("SAVEFILE_ERROR\r\n", ResultCmdReceiver.CLIENT); + this.setResultCommand(protocolRep.executeWriter(SaveFileErrorRule.NAME), ResultCmdReceiver.CLIENT); e.printStackTrace(); } } diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java index ad8006b..4e498dd 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java @@ -1,6 +1,9 @@ package lightcontainer.protocol.rules.reader; +import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.rules.writer.SignErrorRule; +import lightcontainer.protocol.rules.writer.SignOkRule; import java.io.InputStream; @@ -10,9 +13,12 @@ public class SigninRule extends ProtocolReader { private static final int LOGIN = 0; // Index du domain dans le tableau de données private static final int PASSWORD = 1; // Index du port dans le tableau de données + private ProtocolRepository protocolRep; + // Constructor - public SigninRule() { + public SigninRule(ProtocolRepository protocolRep) { super(PATTERN); + this.protocolRep = protocolRep; } public class Result extends ProtocolResult { @@ -50,9 +56,9 @@ public class SigninRule extends ProtocolReader { // TODO : Création d'une règle d'écriture SIGN_OK et SIGN_ERROR proprement if (result.checkCredentials()) { - result.setResultCommand("SIGN_OK\r\n", ResultCmdReceiver.CLIENT); + result.setResultCommand(this.protocolRep.executeWriter(SignOkRule.NAME), ResultCmdReceiver.CLIENT); } else { - result.setResultCommand("SIGN_ERROR\r\n", ResultCmdReceiver.CLIENT); + result.setResultCommand(this.protocolRep.executeWriter(SignErrorRule.NAME), ResultCmdReceiver.CLIENT); } return result; } diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java new file mode 100644 index 0000000..7436141 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java @@ -0,0 +1,15 @@ +package lightcontainer.protocol.rules.writer; + +import lightcontainer.protocol.ProtocolWriter; + +public class FilesRule extends ProtocolWriter { + + private static final String PATTERN = "^FILES(( [^ !]{1,20})!([0-9]{1,10})){0,50}\r\n$"; + + public static final String NAME = "FILES"; + + public FilesRule() { + super(NAME, PATTERN); + } + +} diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java new file mode 100644 index 0000000..8dda3a7 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java @@ -0,0 +1,15 @@ +package lightcontainer.protocol.rules.writer; + +import lightcontainer.protocol.ProtocolWriter; + +public class SaveFileErrorRule extends ProtocolWriter { + + private static final String PATTERN = "^SAVEFILE_ERROR\r\n$"; + + public static final String NAME = "SAVEFILE_ERROR"; + + public SaveFileErrorRule() { + super(NAME, PATTERN); + } + +} diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java new file mode 100644 index 0000000..1bd90d3 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java @@ -0,0 +1,15 @@ +package lightcontainer.protocol.rules.writer; + +import lightcontainer.protocol.ProtocolWriter; + +public class SaveFileOkRule extends ProtocolWriter { + + private static final String PATTERN = "^SAVEFILE_OK\r\n$"; + + public static final String NAME = "SAVEFILE_OK"; + + public SaveFileOkRule() { + super(NAME, PATTERN); + } + +} diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java index 0c35635..b78a66f 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java @@ -11,4 +11,5 @@ public class SignErrorRule extends ProtocolWriter { public SignErrorRule() { super(NAME, PATTERN); } + } diff --git a/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java index e96050f..db1462d 100644 --- a/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java +++ b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java @@ -3,6 +3,7 @@ package lightcontainer.repository; import lightcontainer.domains.client.ClientHandler; import lightcontainer.domains.server.UnicastServerListener; import lightcontainer.interfaces.UnicastCHR; +import lightcontainer.protocol.ProtocolWriter; import java.util.ArrayList; import java.util.List; @@ -54,6 +55,13 @@ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR { this.handlers.add(client); } + @Override + public void respondToClient(String login, ProtocolWriter.ProtocolResult response) { + for (ClientHandler client : handlers) { + client.respond(response); + } + } + /** * AutoClosable Function * Closes all ClientHandlers stored in this repository and deallocates all resources. diff --git a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java index ce47bea..bcd226e 100644 --- a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java +++ b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java @@ -5,8 +5,10 @@ import lightcontainer.domains.Task; import lightcontainer.interfaces.ClientHandlerFFE; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.interfaces.StoreProcessorFFE; +import lightcontainer.protocol.ProtocolWriter; import java.util.Deque; +import java.util.Iterator; import java.util.concurrent.ConcurrentLinkedDeque; public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { @@ -28,16 +30,27 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { */ public void alertStoreProcessors(Task task) { // On avertit les stor processors d'une nouvelle tâche + } /** * Permet à un {@link StoreProcessor} d'avertir le FFE qu'il est disponible * - * @param store + * @param store Le SBE qui s'est occupé de la tâche + * @param response La réponse à envoyer au client */ @Override - public void onStoreAvailable(StoreProcessor store) { + public void onStoreAvailable(StoreProcessor store, ProtocolWriter.ProtocolResult response) { + // TODO : Chercher une tâche appropriée + Iterator it = tasks.iterator(); + while (it.hasNext()) { + Task task = it.next(); + if (task.isResponseOfClient(store.getName())) { + clientRepository.respondToClient(task.getClient(), response); + it.remove(); // Suppression de la tâche + } + } } @Override From 57984456f100b203407c5b1cc24f2063450071e6 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Mon, 7 Mar 2022 08:46:48 +0100 Subject: [PATCH 53/64] =?UTF-8?q?Sauvegarde=20et=20lecture=20du=20fichier?= =?UTF-8?q?=20de=20synchronisation=20->=20AppData=20vers=20Json=20termin?= =?UTF-8?q?=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lightcontainer/storage/Adapter.java | 16 +++++ .../java/lightcontainer/storage/AppData.java | 8 ++- .../lightcontainer/storage/JsonAdapter.java | 70 +++++++++++++++++++ .../lightcontainer/storage/JsonReader.java | 9 --- .../storage/JsonRepository.java | 17 ----- .../lightcontainer/storage/JsonWriter.java | 9 --- .../lightcontainer/storage/Repository.java | 12 +++- .../java/lightcontainer/storage/User.java | 15 ++-- 8 files changed, 108 insertions(+), 48 deletions(-) create mode 100644 app/src/main/java/lightcontainer/storage/Adapter.java create mode 100644 app/src/main/java/lightcontainer/storage/JsonAdapter.java delete mode 100644 app/src/main/java/lightcontainer/storage/JsonReader.java delete mode 100644 app/src/main/java/lightcontainer/storage/JsonRepository.java delete mode 100644 app/src/main/java/lightcontainer/storage/JsonWriter.java diff --git a/app/src/main/java/lightcontainer/storage/Adapter.java b/app/src/main/java/lightcontainer/storage/Adapter.java new file mode 100644 index 0000000..7ffb90d --- /dev/null +++ b/app/src/main/java/lightcontainer/storage/Adapter.java @@ -0,0 +1,16 @@ +package lightcontainer.storage; + +public interface Adapter { + + /** + * @param appData The appData to stringify + * @return The string representation of AppData + */ + String toString(AppData appData); + + /** + * @param appDataString The appData string to parse + * @return AppData + */ + AppData fromString(String appDataString); +} diff --git a/app/src/main/java/lightcontainer/storage/AppData.java b/app/src/main/java/lightcontainer/storage/AppData.java index 88b245e..2a693b2 100644 --- a/app/src/main/java/lightcontainer/storage/AppData.java +++ b/app/src/main/java/lightcontainer/storage/AppData.java @@ -1,6 +1,7 @@ package lightcontainer.storage; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; /** @@ -81,6 +82,10 @@ public class AppData { } } + public Iterator usersIterator() { + return users.values().iterator(); + } + /** * @param fileName The name of the file * @param user The user @@ -107,7 +112,8 @@ public class AppData { if (!this.users.containsKey(user.getName())) { return false; } else { - return this.users.get(user.getName()).addFile(file); + this.users.get(user.getName()).addFile(file); + return true; } } diff --git a/app/src/main/java/lightcontainer/storage/JsonAdapter.java b/app/src/main/java/lightcontainer/storage/JsonAdapter.java new file mode 100644 index 0000000..d055c12 --- /dev/null +++ b/app/src/main/java/lightcontainer/storage/JsonAdapter.java @@ -0,0 +1,70 @@ +package lightcontainer.storage; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; + +import java.util.Iterator; + +public class JsonAdapter implements Adapter { + + @Override + public String toString(AppData appData) { + return addData(appData); + } + + private String addData(AppData appData) { + AppConfig appConfig = appData.getAppConfig(); + JsonObject config = new JsonObject(); + config.addProperty("unicast_port", appConfig.getUnicastPort()); + config.addProperty("multicast_ip", appConfig.getMulticastIp()); + config.addProperty("multicast_port", appConfig.getMulticastPort()); + config.addProperty("network_interface", appConfig.getNetworkInterface()); + config.addProperty("tls", appConfig.isTls()); + JsonArray users = new JsonArray(); + Iterator userIterator = appData.usersIterator(); + addUsers(users, userIterator); + config.addProperty("users", users.toString()); + return config.toString(); + } + + private void addUsers(JsonArray users, Iterator userIterator) { + while (userIterator.hasNext()) { + User current = userIterator.next(); + JsonObject user = new JsonObject(); + user.addProperty("name", current.getName()); + user.addProperty("password", current.getPassword()); + user.addProperty("aes_key", current.getAesKey()); + JsonArray files = new JsonArray(); + Iterator fileIterator = current.fileIterator(); + addFiles(fileIterator); + user.addProperty("files", files.toString()); + users.add(user); + } + } + + private void addFiles(Iterator fileIterator) { + while (fileIterator.hasNext()) { + File currentFile = fileIterator.next(); + JsonObject file = new JsonObject(); + file.addProperty("name", currentFile.getName()); + file.addProperty("size", currentFile.getSize()); + file.addProperty("iv", currentFile.getIv()); + JsonArray storage = new JsonArray(); + Iterator storageIterator = currentFile.getStorageIterator(); + addStorage(storage, storageIterator); + file.addProperty("storage", storage.toString()); + } + } + + private void addStorage(JsonArray storage, Iterator storageIterator) { + while (storageIterator.hasNext()) { + String storageString = storageIterator.next(); + storage.add(storageString); + } + } + + @Override + public AppData fromString(String appDataString) { + return null; + } +} diff --git a/app/src/main/java/lightcontainer/storage/JsonReader.java b/app/src/main/java/lightcontainer/storage/JsonReader.java deleted file mode 100644 index 0b67603..0000000 --- a/app/src/main/java/lightcontainer/storage/JsonReader.java +++ /dev/null @@ -1,9 +0,0 @@ -package lightcontainer.storage; - -public class JsonReader implements FileReader { - - @Override - public AppData readFile(String fileName) { - return null; - } -} diff --git a/app/src/main/java/lightcontainer/storage/JsonRepository.java b/app/src/main/java/lightcontainer/storage/JsonRepository.java deleted file mode 100644 index c2c693d..0000000 --- a/app/src/main/java/lightcontainer/storage/JsonRepository.java +++ /dev/null @@ -1,17 +0,0 @@ -package lightcontainer.storage; - -public class JsonRepository implements Repository { - - - @Override - public void save(FileWriter fileWriter) { - - } - - @Override - public AppData load(FileReader fileReader) { - return null; - } - - -} diff --git a/app/src/main/java/lightcontainer/storage/JsonWriter.java b/app/src/main/java/lightcontainer/storage/JsonWriter.java deleted file mode 100644 index 56fceb9..0000000 --- a/app/src/main/java/lightcontainer/storage/JsonWriter.java +++ /dev/null @@ -1,9 +0,0 @@ -package lightcontainer.storage; - -public class JsonWriter implements FileWriter { - - @Override - public void writeToFile(String fileName, AppData appData) { - - } -} diff --git a/app/src/main/java/lightcontainer/storage/Repository.java b/app/src/main/java/lightcontainer/storage/Repository.java index b688fc7..6757ff5 100644 --- a/app/src/main/java/lightcontainer/storage/Repository.java +++ b/app/src/main/java/lightcontainer/storage/Repository.java @@ -1,8 +1,14 @@ package lightcontainer.storage; -public interface Repository { +public class Repository { - void save(FileWriter fileWriter); + //static final String CONFIG_FILE_PATH = "../../resources/config.json"; - AppData load(FileReader fileReader); + void save(String filePath, Adapter adapter) { + + } + + AppData load(String filePath, Adapter adapter) { + return null; + } } diff --git a/app/src/main/java/lightcontainer/storage/User.java b/app/src/main/java/lightcontainer/storage/User.java index 683fb07..9ba83f2 100644 --- a/app/src/main/java/lightcontainer/storage/User.java +++ b/app/src/main/java/lightcontainer/storage/User.java @@ -1,5 +1,7 @@ package lightcontainer.storage; +import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -36,8 +38,8 @@ public class User { return aesKey; } - public Set> getFilesIterator() { - return files.entrySet(); + public Iterator fileIterator() { + return files.values().iterator(); } public File getFile(String fileName) { @@ -48,13 +50,8 @@ public class User { * @param file The file to add. * @return False if a file with the same name already exists. Otherwise, adds the file and returns true. */ - public boolean addFile(File file) { - if (this.files.containsKey(file.getName())) { - return false; - } else { - this.files.put(file.getName(), file); - return true; - } + public void addFile(File file) { + this.files.put(file.getName(), file); } /** From b10f1edf545918c25a4e00a19f689b0a18f36e5f Mon Sep 17 00:00:00 2001 From: Benjamin Date: Tue, 8 Mar 2022 08:42:34 +0100 Subject: [PATCH 54/64] =?UTF-8?q?Tromp=C3=A9=20en=20allant=20sur=20dev?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domains/client/ClientHandler.java | 4 ++++ .../domains/client/StoreProcessor.java | 5 +++++ .../lightcontainer/interfaces/MulticastSPR.java | 3 +++ .../repository/ClientHandlerRepository.java | 5 ++++- .../lightcontainer/repository/FileFrontEnd.java | 2 ++ .../repository/StoreProcessorRepository.java | 13 +++++++++++++ 6 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java index b75ade2..5cda294 100644 --- a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java +++ b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java @@ -178,4 +178,8 @@ public class ClientHandler implements Runnable, AutoCloseable { } catch (IOException ignored) { } } } + + public String getLogin() { + return this.login; + } } diff --git a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java index 450eb35..b18f7c7 100644 --- a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java @@ -1,5 +1,6 @@ package lightcontainer.domains.client; +import lightcontainer.domains.Task; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.interfaces.StoreProcessorFFE; import lightcontainer.protocol.ProtocolReader; @@ -170,4 +171,8 @@ public class StoreProcessor extends Thread implements AutoCloseable { public int hashCode() { return Objects.hash(domain); } + + public boolean canProcessTask(Task task) { + return this.currentCommand == null; // Vérifier si tâche veut ce SBE + } } diff --git a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java index b2108ec..cdd97dc 100644 --- a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java +++ b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java @@ -1,5 +1,6 @@ package lightcontainer.interfaces; +import lightcontainer.domains.Task; import lightcontainer.domains.client.StoreProcessor; import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.repository.StoreProcessorRepository; @@ -19,4 +20,6 @@ public interface MulticastSPR { * @param store Store processor to add. */ void addStore(StoreProcessor store); + + String findSBE(Task task); } diff --git a/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java index db1462d..416988c 100644 --- a/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java +++ b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java @@ -58,7 +58,10 @@ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR { @Override public void respondToClient(String login, ProtocolWriter.ProtocolResult response) { for (ClientHandler client : handlers) { - client.respond(response); + if (client.getLogin().equals(login)) { + client.respond(response); + break; + } } } diff --git a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java index bcd226e..e29eb18 100644 --- a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java +++ b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java @@ -30,6 +30,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { */ public void alertStoreProcessors(Task task) { // On avertit les stor processors d'une nouvelle tâche + String stor = storeRepository.findSBE(task); } @@ -58,5 +59,6 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { // TODO : Ajouter la tâche - Alerter les StorBackEnds Task task = Task.newInstance(command, client); tasks.add(task); + alertStoreProcessors(task); } } diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java index 7132a74..e0bfea6 100644 --- a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java +++ b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java @@ -1,5 +1,6 @@ package lightcontainer.repository; +import lightcontainer.domains.Task; import lightcontainer.domains.client.StoreProcessor; import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.interfaces.MulticastSPR; @@ -53,6 +54,18 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { this.handlers.add(store); } + @Override + public String findSBE(Task task) { + + for (StoreProcessor handler : handlers) { + if (handler.canProcessTask(task)) { + return handler.getName(); + } + } + + return null; + } + /** * AutoClosable Function * Closes all StoreProcessor stored in this repository and deallocates all resources. From d4cff6de094543f24ebe9d521f345d6c96d06966 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 8 Mar 2022 09:05:03 +0100 Subject: [PATCH 55/64] =?UTF-8?q?Sauvegarde=20et=20lecture=20du=20fichier?= =?UTF-8?q?=20de=20synchronisation=20->=20Json=20vers=20AppData=20termin?= =?UTF-8?q?=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/storage/JsonAdapter.java | 61 ++++++++++++++++++- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/lightcontainer/storage/JsonAdapter.java b/app/src/main/java/lightcontainer/storage/JsonAdapter.java index d055c12..55a4792 100644 --- a/app/src/main/java/lightcontainer/storage/JsonAdapter.java +++ b/app/src/main/java/lightcontainer/storage/JsonAdapter.java @@ -1,9 +1,8 @@ package lightcontainer.storage; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; +import com.google.gson.*; -import java.util.Iterator; +import java.util.*; public class JsonAdapter implements Adapter { @@ -65,6 +64,62 @@ public class JsonAdapter implements Adapter { @Override public AppData fromString(String appDataString) { + try { + JsonElement jsonString = JsonParser.parseString(appDataString); + JsonObject jsonAppData = jsonString.getAsJsonObject(); + AppConfig appConfig = AppConfig.getInstance(); + appConfig.setUnicastPort(jsonAppData.get("unicast_port").getAsInt()); + appConfig.setMulticastIp(jsonAppData.get("multicast_ip").getAsString()); + appConfig.setMulticastPort(jsonAppData.get("multicast_port").getAsInt()); + appConfig.setNetworkInterface(jsonAppData.get("network_interface").getAsString()); + appConfig.setTls(jsonAppData.get("tls").getAsBoolean()); + JsonArray jsonUsers = jsonAppData.getAsJsonArray("users"); + List users = new ArrayList<>(); + getUsers(jsonUsers, users); + AppData appData = AppData.getInstance(); + appData.setAppConfig(appConfig); + for (User user : users) { + appData.addUser(user); + } + return appData; + } catch (JsonParseException parseException) { + System.out.println("[FFE] : Error while loading configuration file"); //TODO - changer en log + } return null; } + + private void getUsers(JsonArray jsonUsers, List users) { + for (JsonElement element : jsonUsers) { + JsonObject jsonUser = element.getAsJsonObject(); + String name = jsonUser.get("username").getAsString(); + String password = jsonUser.get("password").getAsString(); + String aeskey = jsonUser.get("aes_key").getAsString(); + Map userFiles = new HashMap<>(); + JsonArray jsonFiles = jsonUser.getAsJsonArray("files"); + getFiles(userFiles, jsonFiles); + User user = new User(name, password, aeskey, userFiles); + users.add(user); + } + } + + private void getFiles(Map userFiles, JsonArray jsonFiles) { + for (JsonElement fileElement : jsonFiles) { + JsonObject jsonFile = fileElement.getAsJsonObject(); + String fileName = jsonFile.get("name").getAsString(); + int size = jsonFile.get("size").getAsInt(); + String iv = jsonFile.get("iv").getAsString(); + Set storage = new HashSet<>(); + JsonArray jsonStorage = jsonFile.getAsJsonArray("storage"); + getStorage(storage, jsonStorage); + File file = new File(fileName, size, iv, storage); + userFiles.put(file.getName(), file); + } + } + + private void getStorage(Set storage, JsonArray jsonStorage) { + for (JsonElement storageElement : jsonStorage) { + String storageName = storageElement.getAsString(); + storage.add(storageName); + } + } } From 26be3ca8ff4c23590fd74d87a7d55cd4ebefa7da Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 8 Mar 2022 09:32:26 +0100 Subject: [PATCH 56/64] =?UTF-8?q?Sauvegarde=20et=20lecture=20du=20fichier?= =?UTF-8?q?=20de=20synchronisation=20->=20M=C3=A9thodes=20save=20et=20load?= =?UTF-8?q?=20termin=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lightcontainer/storage/Adapter.java | 11 ++---- .../lightcontainer/storage/JsonAdapter.java | 11 ++++-- .../lightcontainer/storage/Repository.java | 34 +++++++++++++++++-- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/lightcontainer/storage/Adapter.java b/app/src/main/java/lightcontainer/storage/Adapter.java index 7ffb90d..30843ab 100644 --- a/app/src/main/java/lightcontainer/storage/Adapter.java +++ b/app/src/main/java/lightcontainer/storage/Adapter.java @@ -2,15 +2,8 @@ package lightcontainer.storage; public interface Adapter { - /** - * @param appData The appData to stringify - * @return The string representation of AppData - */ - String toString(AppData appData); - /** - * @param appDataString The appData string to parse - * @return AppData - */ + String toString(); + AppData fromString(String appDataString); } diff --git a/app/src/main/java/lightcontainer/storage/JsonAdapter.java b/app/src/main/java/lightcontainer/storage/JsonAdapter.java index 55a4792..af6be59 100644 --- a/app/src/main/java/lightcontainer/storage/JsonAdapter.java +++ b/app/src/main/java/lightcontainer/storage/JsonAdapter.java @@ -6,8 +6,14 @@ import java.util.*; public class JsonAdapter implements Adapter { + private AppData appData; + + public JsonAdapter(AppData appData) { + this.appData = appData; + } + @Override - public String toString(AppData appData) { + public String toString() { return addData(appData); } @@ -81,7 +87,8 @@ public class JsonAdapter implements Adapter { for (User user : users) { appData.addUser(user); } - return appData; + this.appData = appData; + return this.appData; } catch (JsonParseException parseException) { System.out.println("[FFE] : Error while loading configuration file"); //TODO - changer en log } diff --git a/app/src/main/java/lightcontainer/storage/Repository.java b/app/src/main/java/lightcontainer/storage/Repository.java index 6757ff5..778b979 100644 --- a/app/src/main/java/lightcontainer/storage/Repository.java +++ b/app/src/main/java/lightcontainer/storage/Repository.java @@ -1,14 +1,44 @@ package lightcontainer.storage; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; + public class Repository { //static final String CONFIG_FILE_PATH = "../../resources/config.json"; void save(String filePath, Adapter adapter) { - + if (filePath != null) { + String jsonAppData = adapter.toString(); + try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(filePath), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { + bufferedWriter.write(jsonAppData); + bufferedWriter.flush(); + } catch (IOException e) { + System.out.println("Error while saving configuration file !"); + } + } } AppData load(String filePath, Adapter adapter) { - return null; + String jsonString = readFile(filePath); + return adapter.fromString(jsonString); + } + + private String readFile(String filePath) { + StringBuilder builder = new StringBuilder(); + try (BufferedReader reader = Files.newBufferedReader(Paths.get(filePath), StandardCharsets.UTF_8)) { + while (reader.ready()) { + builder.append(reader.readLine()); + } + } catch (IOException e) { + System.out.println("Error while reading configuration file"); + builder.setLength(0); + } + return builder.toString(); } } From 2b2bdd346740d4ec02ee9ec7d6cfb40631315e95 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 8 Mar 2022 09:56:17 +0100 Subject: [PATCH 57/64] Regex : modification de fileListResult --- app/src/main/resources/rules.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/resources/rules.txt b/app/src/main/resources/rules.txt index e5d69af..8be9487 100644 --- a/app/src/main/resources/rules.txt +++ b/app/src/main/resources/rules.txt @@ -33,7 +33,7 @@ client_signin = ^SIGNIN ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$ client_signup = ^SIGNUP ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$ ffe_signresult = ^(SIGN_OK|SIGN_ERROR)\r\n$ client_filelist = ^FILELIST\r\n$ -ffe_filelistresult = ^FILES(( [^ !]{1,20})!([0-9]{1,10})){0,50}$ +ffe_filelistresult = ^FILES( ([^ !]{1,20})!([0-9]{1,10})){0,50}$ client_savefile = ^SAVE_FILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$ ffe_savefileresult = ^(SAVEFILE_OK|SAVEFILE_ERROR)\r\n$ client_getfile = ^GETFILE ([^ !]{1,20})\r\n$ From 558e4427fdb5a6c78a5953eb8aff6bf79fa28041 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 8 Mar 2022 11:00:36 +0100 Subject: [PATCH 58/64] =?UTF-8?q?Json=20adapter=20:=20AppData=20vers=20Jso?= =?UTF-8?q?n=20->=20test=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/storage/JsonAdapter.java | 11 ++-- .../protocol/rules/reader/HelloRuleTest.java | 1 - .../storage/JsonAdapterTest.java | 51 +++++++++++++++++++ 3 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 app/src/test/java/lightcontainer/storage/JsonAdapterTest.java diff --git a/app/src/main/java/lightcontainer/storage/JsonAdapter.java b/app/src/main/java/lightcontainer/storage/JsonAdapter.java index af6be59..649bd35 100644 --- a/app/src/main/java/lightcontainer/storage/JsonAdapter.java +++ b/app/src/main/java/lightcontainer/storage/JsonAdapter.java @@ -28,7 +28,7 @@ public class JsonAdapter implements Adapter { JsonArray users = new JsonArray(); Iterator userIterator = appData.usersIterator(); addUsers(users, userIterator); - config.addProperty("users", users.toString()); + config.add("users", users); return config.toString(); } @@ -41,13 +41,13 @@ public class JsonAdapter implements Adapter { user.addProperty("aes_key", current.getAesKey()); JsonArray files = new JsonArray(); Iterator fileIterator = current.fileIterator(); - addFiles(fileIterator); - user.addProperty("files", files.toString()); + addFiles(fileIterator, files); + user.add("files", files); users.add(user); } } - private void addFiles(Iterator fileIterator) { + private void addFiles(Iterator fileIterator, JsonArray files) { while (fileIterator.hasNext()) { File currentFile = fileIterator.next(); JsonObject file = new JsonObject(); @@ -57,7 +57,8 @@ public class JsonAdapter implements Adapter { JsonArray storage = new JsonArray(); Iterator storageIterator = currentFile.getStorageIterator(); addStorage(storage, storageIterator); - file.addProperty("storage", storage.toString()); + file.add("storage", storage); + files.add(file); } } diff --git a/app/src/test/java/lightcontainer/protocol/rules/reader/HelloRuleTest.java b/app/src/test/java/lightcontainer/protocol/rules/reader/HelloRuleTest.java index 7b82f38..a356fb5 100644 --- a/app/src/test/java/lightcontainer/protocol/rules/reader/HelloRuleTest.java +++ b/app/src/test/java/lightcontainer/protocol/rules/reader/HelloRuleTest.java @@ -1,7 +1,6 @@ package lightcontainer.protocol.rules.reader; import lightcontainer.protocol.ProtocolReader; -import lightcontainer.protocol.rules.reader.HelloRule; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; diff --git a/app/src/test/java/lightcontainer/storage/JsonAdapterTest.java b/app/src/test/java/lightcontainer/storage/JsonAdapterTest.java new file mode 100644 index 0000000..34348c0 --- /dev/null +++ b/app/src/test/java/lightcontainer/storage/JsonAdapterTest.java @@ -0,0 +1,51 @@ +package lightcontainer.storage; + +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.*; + + +public class JsonAdapterTest { + + @Test + public void convertAppDataToJson() { + //GIVEN an AppData instance and a Json Adapter + AppData appData = AppData.getInstance(); + AppConfig appConfig = AppConfig.getInstance(); + appConfig.setUnicastPort(32000); + appConfig.setMulticastIp("224.25.0.1"); + appConfig.setMulticastPort(15502); + appConfig.setNetworkInterface("My network interface"); + appConfig.setTls(false); + Map files = new HashMap<>(); + Set storage = new HashSet<>(); + storage.add("StorBackEnd1"); + File file1 = new File("File1", 15, "8d8d8d8d", storage); + files.put(file1.getName(), file1); + User user1 = new User("User1", "Password", "djdjjdj", files); + appData.setAppConfig(appConfig); + appData.addUser(user1); + JsonAdapter jsonAdapter = new JsonAdapter(appData); + //WHEN the adapter converts AppData to Json + String jsonAppData = jsonAdapter.toString(); + System.out.println(jsonAppData); + //THEN + assertTrue(jsonAppData.contains("32000")); + assertTrue(jsonAppData.contains("224.25.0.1")); + assertTrue(jsonAppData.contains("15502")); + assertTrue(jsonAppData.contains("My network interface")); + assertTrue(jsonAppData.contains("false")); + assertTrue(jsonAppData.contains("User1")); + assertTrue(jsonAppData.contains("Password")); + assertTrue(jsonAppData.contains("djdjjdj")); + assertTrue(jsonAppData.contains("File1")); + assertTrue(jsonAppData.contains("15")); + assertTrue(jsonAppData.contains("8d8d8d8d")); + assertTrue(jsonAppData.contains("StorBackEnd1")); + } +} From ac04f86e72c02e4a1b5acba36f4d561d8893dffd Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 8 Mar 2022 11:17:26 +0100 Subject: [PATCH 59/64] =?UTF-8?q?Json=20adapter=20:=20Json=20vers=20AppDat?= =?UTF-8?q?a=20->=20test=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/storage/JsonAdapter.java | 2 +- .../lightcontainer/storage/JsonAdapterTest.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/lightcontainer/storage/JsonAdapter.java b/app/src/main/java/lightcontainer/storage/JsonAdapter.java index 649bd35..076b079 100644 --- a/app/src/main/java/lightcontainer/storage/JsonAdapter.java +++ b/app/src/main/java/lightcontainer/storage/JsonAdapter.java @@ -99,7 +99,7 @@ public class JsonAdapter implements Adapter { private void getUsers(JsonArray jsonUsers, List users) { for (JsonElement element : jsonUsers) { JsonObject jsonUser = element.getAsJsonObject(); - String name = jsonUser.get("username").getAsString(); + String name = jsonUser.get("name").getAsString(); String password = jsonUser.get("password").getAsString(); String aeskey = jsonUser.get("aes_key").getAsString(); Map userFiles = new HashMap<>(); diff --git a/app/src/test/java/lightcontainer/storage/JsonAdapterTest.java b/app/src/test/java/lightcontainer/storage/JsonAdapterTest.java index 34348c0..2bde872 100644 --- a/app/src/test/java/lightcontainer/storage/JsonAdapterTest.java +++ b/app/src/test/java/lightcontainer/storage/JsonAdapterTest.java @@ -33,7 +33,6 @@ public class JsonAdapterTest { JsonAdapter jsonAdapter = new JsonAdapter(appData); //WHEN the adapter converts AppData to Json String jsonAppData = jsonAdapter.toString(); - System.out.println(jsonAppData); //THEN assertTrue(jsonAppData.contains("32000")); assertTrue(jsonAppData.contains("224.25.0.1")); @@ -48,4 +47,20 @@ public class JsonAdapterTest { assertTrue(jsonAppData.contains("8d8d8d8d")); assertTrue(jsonAppData.contains("StorBackEnd1")); } + + @Test + public void convertJsonToAppData() { + //GIVEN a Json string + String json = "{\"unicast_port\":32000,\"multicast_ip\":\"224.25.0.1\",\"multicast_port\":15502,\"network_interface\":\"My network interface\",\"tls\":false,\"users\":[{\"name\":\"User1\",\"password\":\"Password\",\"aes_key\":\"djdjjdj\",\"files\":[{\"name\":\"File1\",\"size\":15,\"iv\":\"8d8d8d8d\",\"storage\":[\"StorBackEnd1\"]}]}]}"; + //WHEN the adapter converts Json to Appdata + JsonAdapter jsonAdapter = new JsonAdapter(null); + AppData appData = jsonAdapter.fromString(json); + //THEN + assertNotNull(appData.getAppConfig()); + assertEquals("My network interface", appData.getAppConfig().getNetworkInterface()); + assertEquals(32000, appData.getAppConfig().getUnicastPort()); + assertEquals("224.25.0.1", appData.getAppConfig().getMulticastIp()); + assertEquals(15502, appData.getAppConfig().getMulticastPort()); + assertFalse(appData.getAppConfig().isTls()); + } } From d979fbd1f3fe4550e771b4e8c4d6a6df8bececef Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 8 Mar 2022 11:45:18 +0100 Subject: [PATCH 60/64] =?UTF-8?q?Repository=20:=20save=20test=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/storage/Repository.java | 8 +-- ...AdapterTest.java => JsonAdapterTests.java} | 2 +- .../storage/RepositoryTests.java | 56 +++++++++++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) rename app/src/test/java/lightcontainer/storage/{JsonAdapterTest.java => JsonAdapterTests.java} (98%) create mode 100644 app/src/test/java/lightcontainer/storage/RepositoryTests.java diff --git a/app/src/main/java/lightcontainer/storage/Repository.java b/app/src/main/java/lightcontainer/storage/Repository.java index 778b979..d6f12bc 100644 --- a/app/src/main/java/lightcontainer/storage/Repository.java +++ b/app/src/main/java/lightcontainer/storage/Repository.java @@ -12,10 +12,10 @@ public class Repository { //static final String CONFIG_FILE_PATH = "../../resources/config.json"; - void save(String filePath, Adapter adapter) { + static void save(String filePath, Adapter adapter) { if (filePath != null) { String jsonAppData = adapter.toString(); - try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(filePath), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { + try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(filePath).toAbsolutePath(), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { bufferedWriter.write(jsonAppData); bufferedWriter.flush(); } catch (IOException e) { @@ -29,9 +29,9 @@ public class Repository { return adapter.fromString(jsonString); } - private String readFile(String filePath) { + static private String readFile(String filePath) { StringBuilder builder = new StringBuilder(); - try (BufferedReader reader = Files.newBufferedReader(Paths.get(filePath), StandardCharsets.UTF_8)) { + try (BufferedReader reader = Files.newBufferedReader(Paths.get(filePath).toAbsolutePath(), StandardCharsets.UTF_8)) { while (reader.ready()) { builder.append(reader.readLine()); } diff --git a/app/src/test/java/lightcontainer/storage/JsonAdapterTest.java b/app/src/test/java/lightcontainer/storage/JsonAdapterTests.java similarity index 98% rename from app/src/test/java/lightcontainer/storage/JsonAdapterTest.java rename to app/src/test/java/lightcontainer/storage/JsonAdapterTests.java index 2bde872..bd9006a 100644 --- a/app/src/test/java/lightcontainer/storage/JsonAdapterTest.java +++ b/app/src/test/java/lightcontainer/storage/JsonAdapterTests.java @@ -10,7 +10,7 @@ import java.util.Set; import static org.junit.jupiter.api.Assertions.*; -public class JsonAdapterTest { +public class JsonAdapterTests { @Test public void convertAppDataToJson() { diff --git a/app/src/test/java/lightcontainer/storage/RepositoryTests.java b/app/src/test/java/lightcontainer/storage/RepositoryTests.java new file mode 100644 index 0000000..0fa557a --- /dev/null +++ b/app/src/test/java/lightcontainer/storage/RepositoryTests.java @@ -0,0 +1,56 @@ +package lightcontainer.storage; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.InvalidPathException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.*; + + +public class RepositoryTests { + + @AfterEach + public void destroyTestFile() { + try { + Files.deleteIfExists(Paths.get("src", "test", "resources", "test.json").toAbsolutePath()); + } catch (IOException e) { + System.out.println("Error while destroying file"); + } + } + + @Test + public void save() { + //GIVEN an AppData instance, a JsonAdapter and a Repository + AppData appData = AppData.getInstance(); + AppConfig appConfig = AppConfig.getInstance(); + appConfig.setUnicastPort(32000); + appConfig.setMulticastIp("224.25.0.1"); + appConfig.setMulticastPort(15502); + appConfig.setNetworkInterface("My network interface"); + appConfig.setTls(false); + Map files = new HashMap<>(); + Set storage = new HashSet<>(); + storage.add("StorBackEnd1"); + File file1 = new File("File1", 15, "8d8d8d8d", storage); + files.put(file1.getName(), file1); + User user1 = new User("User1", "Password", "djdjjdj", files); + appData.setAppConfig(appConfig); + appData.addUser(user1); + JsonAdapter jsonAdapter = new JsonAdapter(appData); + //WHEN Repository calls save method + String filePath = "src/test/resources/test.json"; + Repository.save(filePath, jsonAdapter); + //THEN + assertTrue(Files.exists(Paths.get("src/test/resources/test.json").toAbsolutePath())); + } +} From 429161877466ba608427c4e5fa2be3ac2ce85239 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 8 Mar 2022 12:12:04 +0100 Subject: [PATCH 61/64] =?UTF-8?q?Repository=20:=20load=20test=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/storage/JsonAdapter.java | 2 +- .../lightcontainer/storage/Repository.java | 6 ++--- .../storage/RepositoryTests.java | 17 ++++++++++++- app/src/test/resources/loadTest.json | 24 +++++++++++++++++++ 4 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 app/src/test/resources/loadTest.json diff --git a/app/src/main/java/lightcontainer/storage/JsonAdapter.java b/app/src/main/java/lightcontainer/storage/JsonAdapter.java index 076b079..831b0f1 100644 --- a/app/src/main/java/lightcontainer/storage/JsonAdapter.java +++ b/app/src/main/java/lightcontainer/storage/JsonAdapter.java @@ -92,8 +92,8 @@ public class JsonAdapter implements Adapter { return this.appData; } catch (JsonParseException parseException) { System.out.println("[FFE] : Error while loading configuration file"); //TODO - changer en log + return null; } - return null; } private void getUsers(JsonArray jsonUsers, List users) { diff --git a/app/src/main/java/lightcontainer/storage/Repository.java b/app/src/main/java/lightcontainer/storage/Repository.java index d6f12bc..3ea0ac6 100644 --- a/app/src/main/java/lightcontainer/storage/Repository.java +++ b/app/src/main/java/lightcontainer/storage/Repository.java @@ -10,8 +10,6 @@ import java.nio.file.StandardOpenOption; public class Repository { - //static final String CONFIG_FILE_PATH = "../../resources/config.json"; - static void save(String filePath, Adapter adapter) { if (filePath != null) { String jsonAppData = adapter.toString(); @@ -24,12 +22,12 @@ public class Repository { } } - AppData load(String filePath, Adapter adapter) { + static AppData load(String filePath, Adapter adapter) { String jsonString = readFile(filePath); return adapter.fromString(jsonString); } - static private String readFile(String filePath) { + private static String readFile(String filePath) { StringBuilder builder = new StringBuilder(); try (BufferedReader reader = Files.newBufferedReader(Paths.get(filePath).toAbsolutePath(), StandardCharsets.UTF_8)) { while (reader.ready()) { diff --git a/app/src/test/java/lightcontainer/storage/RepositoryTests.java b/app/src/test/java/lightcontainer/storage/RepositoryTests.java index 0fa557a..ed90a68 100644 --- a/app/src/test/java/lightcontainer/storage/RepositoryTests.java +++ b/app/src/test/java/lightcontainer/storage/RepositoryTests.java @@ -30,7 +30,7 @@ public class RepositoryTests { @Test public void save() { - //GIVEN an AppData instance, a JsonAdapter and a Repository + //GIVEN an AppData instance and a Json Adapter AppData appData = AppData.getInstance(); AppConfig appConfig = AppConfig.getInstance(); appConfig.setUnicastPort(32000); @@ -53,4 +53,19 @@ public class RepositoryTests { //THEN assertTrue(Files.exists(Paths.get("src/test/resources/test.json").toAbsolutePath())); } + + @Test + public void load() { + //GIVEN a test json file loadTest.json + JsonAdapter jsonAdapter = new JsonAdapter(null); + //WHEN repository calls load method + AppData appData = Repository.load("src/test/resources/loadTest.json", jsonAdapter); + //THEN + assertNotNull(appData.getAppConfig()); + assertEquals("My network interface", appData.getAppConfig().getNetworkInterface()); + assertEquals(32000, appData.getAppConfig().getUnicastPort()); + assertEquals("224.25.0.1", appData.getAppConfig().getMulticastIp()); + assertEquals(15502, appData.getAppConfig().getMulticastPort()); + assertFalse(appData.getAppConfig().isTls()); + } } diff --git a/app/src/test/resources/loadTest.json b/app/src/test/resources/loadTest.json new file mode 100644 index 0000000..f06f3af --- /dev/null +++ b/app/src/test/resources/loadTest.json @@ -0,0 +1,24 @@ +{ + "unicast_port": 32000, + "multicast_ip": "224.25.0.1", + "multicast_port": 15502, + "network_interface": "My network interface", + "tls": false, + "users": [ + { + "name": "User1", + "password": "Password", + "aes_key": "djdjjdj", + "files": [ + { + "name": "File1", + "size": 15, + "iv": "8d8d8d8d", + "storage": [ + "StorBackEnd1" + ] + } + ] + } + ] +} \ No newline at end of file From 4fbe6bb88c380662eda58918a40c3c8c887b6353 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 8 Mar 2022 14:34:09 +0100 Subject: [PATCH 62/64] Storage : suppresion de 2 interfaces inutiles --- app/src/main/java/lightcontainer/storage/FileReader.java | 6 ------ app/src/main/java/lightcontainer/storage/FileWriter.java | 6 ------ 2 files changed, 12 deletions(-) delete mode 100644 app/src/main/java/lightcontainer/storage/FileReader.java delete mode 100644 app/src/main/java/lightcontainer/storage/FileWriter.java diff --git a/app/src/main/java/lightcontainer/storage/FileReader.java b/app/src/main/java/lightcontainer/storage/FileReader.java deleted file mode 100644 index 4e79a0b..0000000 --- a/app/src/main/java/lightcontainer/storage/FileReader.java +++ /dev/null @@ -1,6 +0,0 @@ -package lightcontainer.storage; - -public interface FileReader { - - AppData readFile(String fileName); -} diff --git a/app/src/main/java/lightcontainer/storage/FileWriter.java b/app/src/main/java/lightcontainer/storage/FileWriter.java deleted file mode 100644 index 3cef3aa..0000000 --- a/app/src/main/java/lightcontainer/storage/FileWriter.java +++ /dev/null @@ -1,6 +0,0 @@ -package lightcontainer.storage; - -public interface FileWriter { - - void writeToFile(String fileName, AppData appData); -} From f9c4ee71b202c1e309c3fad75de05228f2a484f3 Mon Sep 17 00:00:00 2001 From: Maximilien LEDOUX Date: Tue, 8 Mar 2022 14:43:40 +0100 Subject: [PATCH 63/64] Storage : optimisation des imports et ajout de commentaires --- .../main/java/lightcontainer/storage/Adapter.java | 3 +-- app/src/main/java/lightcontainer/storage/File.java | 3 +++ .../java/lightcontainer/storage/JsonAdapter.java | 12 ++++++++++++ .../main/java/lightcontainer/storage/Repository.java | 9 +++++++++ app/src/main/java/lightcontainer/storage/User.java | 2 -- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/lightcontainer/storage/Adapter.java b/app/src/main/java/lightcontainer/storage/Adapter.java index 30843ab..29d5dc3 100644 --- a/app/src/main/java/lightcontainer/storage/Adapter.java +++ b/app/src/main/java/lightcontainer/storage/Adapter.java @@ -1,8 +1,7 @@ package lightcontainer.storage; public interface Adapter { - - + String toString(); AppData fromString(String appDataString); diff --git a/app/src/main/java/lightcontainer/storage/File.java b/app/src/main/java/lightcontainer/storage/File.java index dcee5cc..e7d5d5f 100644 --- a/app/src/main/java/lightcontainer/storage/File.java +++ b/app/src/main/java/lightcontainer/storage/File.java @@ -3,6 +3,9 @@ package lightcontainer.storage; import java.util.Iterator; import java.util.Set; +/** + * File represents all information related to a file + */ public class File { private final String name; diff --git a/app/src/main/java/lightcontainer/storage/JsonAdapter.java b/app/src/main/java/lightcontainer/storage/JsonAdapter.java index 831b0f1..aaecc55 100644 --- a/app/src/main/java/lightcontainer/storage/JsonAdapter.java +++ b/app/src/main/java/lightcontainer/storage/JsonAdapter.java @@ -4,6 +4,9 @@ import com.google.gson.*; import java.util.*; +/** + * Specific implementation of Adapter that converts AppData to Json and vice-versa + */ public class JsonAdapter implements Adapter { private AppData appData; @@ -12,6 +15,10 @@ public class JsonAdapter implements Adapter { this.appData = appData; } + /** + * + * @return A Json String containing AppData properties + */ @Override public String toString() { return addData(appData); @@ -69,6 +76,11 @@ public class JsonAdapter implements Adapter { } } + /** + * + * @param appDataString The Json String to convert + * @return An AppData instance + */ @Override public AppData fromString(String appDataString) { try { diff --git a/app/src/main/java/lightcontainer/storage/Repository.java b/app/src/main/java/lightcontainer/storage/Repository.java index 3ea0ac6..1f085a6 100644 --- a/app/src/main/java/lightcontainer/storage/Repository.java +++ b/app/src/main/java/lightcontainer/storage/Repository.java @@ -10,6 +10,10 @@ import java.nio.file.StandardOpenOption; public class Repository { + /** + * @param filePath The path where the file must be saved + * @param adapter The service that converts Objects to Strings + */ static void save(String filePath, Adapter adapter) { if (filePath != null) { String jsonAppData = adapter.toString(); @@ -22,6 +26,11 @@ public class Repository { } } + /** + * @param filePath The path where the file is stored + * @param adapter The service that converts Strings to objects + * @return + */ static AppData load(String filePath, Adapter adapter) { String jsonString = readFile(filePath); return adapter.fromString(jsonString); diff --git a/app/src/main/java/lightcontainer/storage/User.java b/app/src/main/java/lightcontainer/storage/User.java index 9ba83f2..47a65f9 100644 --- a/app/src/main/java/lightcontainer/storage/User.java +++ b/app/src/main/java/lightcontainer/storage/User.java @@ -1,9 +1,7 @@ package lightcontainer.storage; -import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import java.util.Set; /** * User represents a user of the system. From 45851865fdd5a1d5507793d041d833c36500c9c1 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Tue, 8 Mar 2022 14:50:16 +0100 Subject: [PATCH 64/64] =?UTF-8?q?Envoie=20de=20fichier=20fonctionnelle=20:?= =?UTF-8?q?=20-=20Le=20client=20re=C3=A7oit=20d=C3=A9sormais=20la=20r?= =?UTF-8?q?=C3=A9ponse=20(ne=20recevais=20pas=20car=20ne=20poss=C3=A8dait?= =?UTF-8?q?=20pas=20le=20bon=20login=20dans=20les=20t=C3=A2ches)=20-=20D'a?= =?UTF-8?q?utre=20probl=C3=A8mes=20mineur=20qui=20emp=C3=AAchait=20la=20tr?= =?UTF-8?q?ansimission=20d'une=20r=C3=A9ponse=20au=20client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/App.java | 22 ++++----- .../java/lightcontainer/domains/Task.java | 22 +++++++-- .../domains/client/ClientHandler.java | 6 ++- .../domains/client/StoreProcessor.java | 35 +++++++------ .../server/MulticastServerListener.java | 11 +++-- .../domains/server/UnicastServerListener.java | 16 ++++-- .../interfaces/ClientHandlerFFE.java | 3 +- .../interfaces/MulticastSPR.java | 4 +- .../protocol/ProtocolReader.java | 4 +- .../protocol/ProtocolWriter.java | 12 +++-- .../protocol/rules/reader/SavefileRule.java | 5 +- .../protocol/rules/reader/SendOkRule.java | 29 +++++++++++ .../protocol/rules/writer/FilesRule.java | 2 +- .../protocol/rules/writer/SendfileRule.java | 49 +++++++++++++++++++ .../repository/ClientHandlerRepository.java | 2 +- .../repository/FileFrontEnd.java | 34 ++++++++++--- .../repository/StoreProcessorRepository.java | 17 +++++-- app/src/main/resources/rules.txt | 2 +- 18 files changed, 211 insertions(+), 64 deletions(-) create mode 100644 app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java create mode 100644 app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java index 58584a3..2379664 100644 --- a/app/src/main/java/lightcontainer/App.java +++ b/app/src/main/java/lightcontainer/App.java @@ -6,10 +6,7 @@ package lightcontainer; import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.domains.server.UnicastServerListener; import lightcontainer.interfaces.ProtocolRepository; -import lightcontainer.protocol.rules.reader.FilelistRule; -import lightcontainer.protocol.rules.reader.HelloRule; -import lightcontainer.protocol.rules.reader.SavefileRule; -import lightcontainer.protocol.rules.reader.SigninRule; +import lightcontainer.protocol.rules.reader.*; import lightcontainer.protocol.rules.writer.*; import lightcontainer.repository.ClientHandlerRepository; import lightcontainer.repository.FileFrontEnd; @@ -19,10 +16,10 @@ import lightcontainer.repository.StoreProcessorRepository; public class App { // Constant config server // -- Unicast client port - private static final int UNICAST_PORT = 8500; + private static final int UNICAST_PORT = 8000; // -- Multicast listener ip, port private static final String MULTICAST_IP = "226.66.66.1"; - private static final int MULTICAST_PORT = 42500; + private static final int MULTICAST_PORT = 15502; /* @@ -64,23 +61,26 @@ public class App { protocolRep.addReader(new SigninRule(protocolRep)); protocolRep.addReader(new FilelistRule(protocolRep)); protocolRep.addReader(new SavefileRule(protocolRep)); + protocolRep.addReader(new SendOkRule(protocolRep)); protocolRep.addWriter(new SignOkRule()); protocolRep.addWriter(new SignErrorRule()); + protocolRep.addWriter(new SignoutRule()); protocolRep.addWriter(new FilesRule()); protocolRep.addWriter(new SaveFileOkRule()); protocolRep.addWriter(new SaveFileErrorRule()); + protocolRep.addWriter(new SendfileRule()); - new UnicastServerListener(clientRep, protocolRep, UNICAST_PORT); - new MulticastServerListener(storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT); FileFrontEnd ffe = new FileFrontEnd(clientRep, storeRep, protocolRep); + new UnicastServerListener(ffe, clientRep, protocolRep, UNICAST_PORT); + new MulticastServerListener(ffe, storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT); // close repo et client et server. - Thread.sleep(60000); + // Thread.sleep(60000); - clientRep.close(); - storeRep.close(); + // clientRep.close(); + // storeRep.close(); } } diff --git a/app/src/main/java/lightcontainer/domains/Task.java b/app/src/main/java/lightcontainer/domains/Task.java index 556b339..6bce8eb 100644 --- a/app/src/main/java/lightcontainer/domains/Task.java +++ b/app/src/main/java/lightcontainer/domains/Task.java @@ -2,21 +2,22 @@ package lightcontainer.domains; import lightcontainer.enumerations.TaskStatus; import lightcontainer.enumerations.TaskType; +import lightcontainer.protocol.ProtocolWriter; public class Task { // Variables private TaskStatus status; - private String command; + private ProtocolWriter.ProtocolResult command; private String client; private String storeDomain; - public Task(TaskStatus pending, String command, String client) { - status = pending; + public Task(TaskStatus status, ProtocolWriter.ProtocolResult command, String client) { + this.status = status; this.command = command; this.client = client; } - public static Task newInstance(String command, String client) { + public static Task newInstance(ProtocolWriter.ProtocolResult command, String client) { Task task = new Task(TaskStatus.PENDING, command, client); return task; } @@ -27,7 +28,7 @@ public class Task { * @return TRUE si le client doit recevoir cette réponse. */ public boolean isResponseOfClient(String storeDomain) { - return (this.storeDomain == storeDomain && status == TaskStatus.PENDING); + return (status == TaskStatus.PROCESSING && this.storeDomain.equals(storeDomain)); } /** @@ -37,4 +38,15 @@ public class Task { public String getClient() { return client; } + + public ProtocolWriter.ProtocolResult getCommand() { + return this.command; + } + + public void setDomain(String storeDomain) { + this.storeDomain = storeDomain; + if (storeDomain != null) { + this.status = TaskStatus.PROCESSING; + } + } } diff --git a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java index 5cda294..15f1ed5 100644 --- a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java +++ b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java @@ -92,13 +92,15 @@ public class ClientHandler implements Runnable, AutoCloseable { ProtocolReader.ProtocolResult ruleResult = protocolRep.executeReader(command + "\r\n"); if (isConnected()) { - ProtocolWriter.ProtocolResult writerCommand = ruleResult.getResultCommand(); ruleResult.read( this.client.getInputStream() ); + ProtocolWriter.ProtocolResult writerCommand = ruleResult.getResultCommand(); if (ruleResult.getReceiver() == ProtocolReader.ResultCmdReceiver.STOREBACKEND) { - fileFrontEnd.newCommand(command, writerCommand.getCommand()); // Envoie dans la file de tâche FileFrontEnd en attente d'un traitement d'un StorBackEnd + fileFrontEnd.newCommand( + writerCommand, + getLogin()); // Envoie dans la file de tâche FileFrontEnd en attente d'un traitement d'un StorBackEnd // Attend la fin de la réalisation de la tâche waitTaskResponse(); diff --git a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java index b18f7c7..642cdd8 100644 --- a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java @@ -34,7 +34,7 @@ public class StoreProcessor extends Thread implements AutoCloseable { private BufferedReader reader; private PrintWriter writer; - private String currentCommand; + private ProtocolWriter.ProtocolResult protocolResult; private ProtocolRepository protocolRep; // Constructor @@ -64,6 +64,8 @@ public class StoreProcessor extends Thread implements AutoCloseable { this.store.getOutputStream(), StandardCharsets.UTF_8 ), true); + + this.start(); } catch (IOException e) { e.printStackTrace(); } @@ -81,23 +83,25 @@ public class StoreProcessor extends Thread implements AutoCloseable { while (this.client_run) { try { waitAction(); + System.out.println("[SBE] Envoie commande : " + protocolResult.getCommand()); // Request - ProtocolWriter.ProtocolResult requestResult = protocolRep.executeWriter(this.currentCommand); - this.writer.write(requestResult.getCommand()); - requestResult.write(this.store.getOutputStream()); + this.writer.write(protocolResult.getCommand()); + this.writer.flush(); + protocolResult.write(this.store.getOutputStream()); // Response - String responseCommand = this.reader.readLine(); + String responseCommand = this.reader.readLine() + "\r\n"; if (responseCommand != null) System.out.println("StoreBackEnd: " + responseCommand); ProtocolReader.ProtocolResult responseResult = protocolRep.executeReader(responseCommand); - responseResult.read(this.store.getInputStream()); + responseResult.read( + this.store.getInputStream() + ); System.out.println("StoreBackEnd response to client: " + responseResult.getResultCommand()); alertAvalaible(responseResult.getResultCommand()); - // TODO : Faire en sorte que getResultCommand retourne un ProtocolWriter } catch (IOException ignore) { } } @@ -105,11 +109,11 @@ public class StoreProcessor extends Thread implements AutoCloseable { /** * Permet de demander au StoreBackEnd d'effectuer une commande - * @param command La commande à effectuer + * @param protocolResult La commande à effectuer */ - public void executeCommand(String command) { + public void executeCommand(ProtocolWriter.ProtocolResult protocolResult) { synchronized (this) { - this.currentCommand = command; + this.protocolResult = protocolResult; this.notify(); } } @@ -119,10 +123,9 @@ public class StoreProcessor extends Thread implements AutoCloseable { */ private void alertAvalaible(ProtocolWriter.ProtocolResult responseCommand) { synchronized (this) { - waitAction(); - this.currentCommand = null; - + this.protocolResult = null; fileFrontEnd.onStoreAvailable(this, responseCommand); + waitAction(); } } @@ -173,6 +176,10 @@ public class StoreProcessor extends Thread implements AutoCloseable { } public boolean canProcessTask(Task task) { - return this.currentCommand == null; // Vérifier si tâche veut ce SBE + return this.protocolResult == null; // Vérifier si tâche veut ce SBE + } + + public String getDomain() { + return this.domain; } } diff --git a/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java index f88fa56..868ada1 100644 --- a/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java +++ b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java @@ -5,6 +5,7 @@ import lightcontainer.interfaces.MulticastSPR; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.reader.HelloRule; +import lightcontainer.repository.FileFrontEnd; import java.io.IOException; import java.net.*; @@ -24,6 +25,7 @@ public class MulticastServerListener implements Runnable { // Variable private final String multicast_address; private final int multicast_port; + private FileFrontEnd ffe; private final MulticastSPR repository; private final ProtocolRepository protocolRep; @@ -31,7 +33,8 @@ public class MulticastServerListener implements Runnable { private MulticastSocket listener; // Constructor - public MulticastServerListener(MulticastSPR repository, ProtocolRepository protocolRep, String multicast_address, int multicast_port) { + public MulticastServerListener(FileFrontEnd ffe, MulticastSPR repository, ProtocolRepository protocolRep, String multicast_address, int multicast_port) { + this.ffe = ffe; this.repository = repository; this.protocolRep = protocolRep; this.multicast_address = multicast_address; @@ -65,11 +68,13 @@ public class MulticastServerListener implements Runnable { try { // TODO Récupérer le port du message du packet et le setup (add description of the line). HelloRule.Result readerResult = protocolRep.executeReader(data); - System.out.printf("Réception en multicast : Domain=%s | Port=%d\n", readerResult.getDomain(), readerResult.getPort()); + System.out.printf("Nouveau SBE : Domain=%s | Port=%d\n", readerResult.getDomain(), readerResult.getPort()); Socket socket = new Socket(packet.getAddress(), readerResult.getPort()); + // Create the store processor - StoreProcessor storeProcessor = new StoreProcessor(socket, readerResult.getDomain(), null, protocolRep); // TODO : Voir comment on procède get via repo ou ici ?! + StoreProcessor storeProcessor = new StoreProcessor(socket, readerResult.getDomain(), ffe, protocolRep); // TODO : Voir comment on procède get via repo ou ici ?! + // Add the store processor to its repository this.repository.addStore(storeProcessor); } catch (IOException ignore) { diff --git a/app/src/main/java/lightcontainer/domains/server/UnicastServerListener.java b/app/src/main/java/lightcontainer/domains/server/UnicastServerListener.java index c604dee..5970d61 100644 --- a/app/src/main/java/lightcontainer/domains/server/UnicastServerListener.java +++ b/app/src/main/java/lightcontainer/domains/server/UnicastServerListener.java @@ -3,21 +3,24 @@ package lightcontainer.domains.server; import lightcontainer.domains.client.ClientHandler; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.interfaces.UnicastCHR; +import lightcontainer.repository.FileFrontEnd; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; -public class UnicastServerListener { +public class UnicastServerListener implements Runnable { // Variables private ServerSocket server; + private FileFrontEnd ffe; private final UnicastCHR repository; private ProtocolRepository protocolRep; private final int server_port; private boolean server_run; // Constructor - public UnicastServerListener(UnicastCHR repository, ProtocolRepository protocolRep, int port) { + public UnicastServerListener(FileFrontEnd ffe, UnicastCHR repository, ProtocolRepository protocolRep, int port) { + this.ffe = ffe; this.repository = repository; this.protocolRep = protocolRep; this.server_port = port; @@ -33,7 +36,8 @@ public class UnicastServerListener { * @see Thread#start() * @see ClientHandler */ - public void start() { + @Override + public void run() { try { // Allow looping in the loop and create a socket server this.server_run = true; @@ -41,10 +45,11 @@ public class UnicastServerListener { while (this.server_run) { // Accepting connection requests (blocking) Socket client = this.server.accept(); + System.out.println("New Client"); // Create a new Handler client by passing these dependencies to it - ClientHandler clientHandler = new ClientHandler(client, null, protocolRep); // TODO passer FileFrontEnd ou faire ca dans le repository ?! + ClientHandler clientHandler = new ClientHandler(client, ffe, protocolRep); // TODO passer FileFrontEnd ou faire ca dans le repository ?! // Add the client handler to its repository (clienthandlerrepository) - // this.repository.add(clientHandler); TODO REPOSITORY + this.repository.addClient(clientHandler); // Start the thread (new Thread(clientHandler)).start(); } @@ -66,4 +71,5 @@ public class UnicastServerListener { } catch (IOException ignored) { } } } + } diff --git a/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java b/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java index 99536f1..3f1ca8c 100644 --- a/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java +++ b/app/src/main/java/lightcontainer/interfaces/ClientHandlerFFE.java @@ -1,6 +1,7 @@ package lightcontainer.interfaces; import lightcontainer.domains.client.ClientHandler; +import lightcontainer.protocol.ProtocolWriter; import lightcontainer.repository.FileFrontEnd; /** @@ -14,6 +15,6 @@ public interface ClientHandlerFFE { * @param command Commande à traiter * @param client identifiant du client à qui est affilié cette commande */ - void newCommand(String command, String client); + void newCommand(ProtocolWriter.ProtocolResult command, String client); } diff --git a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java index cdd97dc..1d634c4 100644 --- a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java +++ b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java @@ -21,5 +21,7 @@ public interface MulticastSPR { */ void addStore(StoreProcessor store); - String findSBE(Task task); + String findDomain(Task task); + + void assignTask(String stor, Task task); } diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java index 54e3a9e..6d37951 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java @@ -23,7 +23,7 @@ public abstract class ProtocolReader { * Lorsqu'il retourne son résultat, on vérifie si il y a une demande de lecture/écriture de fichier depuis le réseau. Si oui on appel ces méthodes, sinon on ne fait rien. * Ensuite on regarde après l'exécution de ces méthode ou non si il y a une commande de retour ou non et l'envoyons au receiver spécifié par la commande. */ - public abstract class ProtocolResult { + public class ProtocolResult { /** * Command qui sera renvoyée par exemple au client */ @@ -45,7 +45,7 @@ public abstract class ProtocolReader { * @return Commande */ public ProtocolWriter.ProtocolResult getResultCommand() { - return resultCommand; + return this.resultCommand; } /** diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java index 665609a..87f6682 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java @@ -25,7 +25,7 @@ public abstract class ProtocolWriter { return cmdName; } - public class ProtocolResult { + public static class ProtocolResult { private String command; @@ -52,11 +52,12 @@ public abstract class ProtocolWriter { */ public final T execute(String... data) { // Concatatène le nom de la commande avec les données (trim), avec un espace entre chaque - StringJoiner builder = new StringJoiner(" ", this.cmdName, "\r\n"); - for (String param : data) - builder.add(param); + StringBuilder builder = new StringBuilder(this.cmdName); - String command = builder.toString(); + for (String param : data) + builder.append(" " + param); + + String command = builder + "\r\n"; Matcher ruleMatcher = this.rulePattern.matcher(command); // Vérifie que tout match (cf. Matcher). Si match alors on retourne la commande build, sinon on retourne NULL if (ruleMatcher.matches()) { @@ -64,6 +65,7 @@ public abstract class ProtocolWriter { result.setCommand(command); return (T) result; } + return null; } diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java index a2565f1..444a916 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java @@ -4,6 +4,7 @@ import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.SaveFileErrorRule; import lightcontainer.protocol.rules.writer.SaveFileOkRule; +import lightcontainer.protocol.rules.writer.SendfileRule; import lightcontainer.utils.FileReceiver; import java.io.IOException; @@ -40,11 +41,11 @@ public class SavefileRule extends ProtocolReader { System.out.printf("Sauvegarde du fichier : %s %d\n", filename, size); try { - FileReceiver fileReceiver = new FileReceiver("D:\\"); + FileReceiver fileReceiver = new FileReceiver("/home/benjamin/ffe"); // "D:\\"); if (!fileReceiver.receiveFile(reader, this.filename, this.size)) throw new IOException(); - this.setResultCommand(protocolRep.executeWriter(SaveFileOkRule.NAME), ResultCmdReceiver.CLIENT); + this.setResultCommand(protocolRep.executeWriter(SendfileRule.NAME, this.filename, String.valueOf(this.size), "EMPREINTEBLBLBLBLBLABLABLBALBALBALBALBALBALBALBALBALABLBALBALBALABLABLABLABLABLABLABALBLABALABLABLABLABKJABKAHBHKBHJbhjvgkh"), ResultCmdReceiver.STOREBACKEND); } catch (IOException e) { this.setResultCommand(protocolRep.executeWriter(SaveFileErrorRule.NAME), ResultCmdReceiver.CLIENT); e.printStackTrace(); diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java new file mode 100644 index 0000000..8243e43 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java @@ -0,0 +1,29 @@ +package lightcontainer.protocol.rules.reader; + +import lightcontainer.interfaces.ProtocolRepository; +import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.ProtocolWriter; +import lightcontainer.protocol.rules.writer.SaveFileOkRule; + +public class SendOkRule extends ProtocolReader { + + + // Constants + private static final String PATTERN = "^SEND_OK\r\n$"; + + private ProtocolRepository protocolRep; + + // Constructor + public SendOkRule(ProtocolRepository protocolRep) { + super(PATTERN); + this.protocolRep = protocolRep; + } + + + @Override + protected ProtocolReader.ProtocolResult onExecuted(String... data) { + ProtocolReader.ProtocolResult result = new ProtocolReader.ProtocolResult(); + result.setResultCommand(protocolRep.executeWriter(SaveFileOkRule.NAME), ResultCmdReceiver.CLIENT); + return result; + } +} diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java index 7436141..a611163 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java @@ -4,7 +4,7 @@ import lightcontainer.protocol.ProtocolWriter; public class FilesRule extends ProtocolWriter { - private static final String PATTERN = "^FILES(( [^ !]{1,20})!([0-9]{1,10})){0,50}\r\n$"; + private static final String PATTERN = "^FILES( ([^ !]{1,20})!([0-9]{1,10})){0,50}\r\n$"; public static final String NAME = "FILES"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java new file mode 100644 index 0000000..be51736 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java @@ -0,0 +1,49 @@ +package lightcontainer.protocol.rules.writer; + +import lightcontainer.protocol.ProtocolWriter; +import lightcontainer.utils.FileReceiver; +import lightcontainer.utils.FileSender; + +import java.io.OutputStream; + +public class SendfileRule extends ProtocolWriter { + + private static final String PATTERN = "^SENDFILE [A-Za-z0-9.]{0,200} [0-9]{1,10} [A-Za-z0-9.]{50,200}\r\n$"; + + public static final String NAME = "SENDFILE"; + + private static final int HASHED_FILE_NAME = 0; // Index file name hashed. + private static final int FILE_SIZE = 1; // Index file size. + private static final int HASHED_FILE_CONTENT = 2; // Index file content hashed. + + public SendfileRule() { + super(NAME, PATTERN); + } + + public class Result extends ProtocolWriter.ProtocolResult { + + private final String hashedFileName; + private final int fileSize; + private final String hashedFileContent; + + public Result(String hashedFileName, int fileSize, String hashedFileContent) { + this.hashedFileName = hashedFileName; + this.fileSize = fileSize; + this.hashedFileContent = hashedFileContent; + } + + @Override + public void write(OutputStream writer) { + super.write(writer); + System.out.println("Envoie du fichier au SBE"); + FileSender fileSender = new FileSender("/home/benjamin/ffe"); + fileSender.sendFile(hashedFileName, writer); + } + } + + + @Override + protected SendfileRule.Result onExecuted(String... data) { + return new SendfileRule.Result(data[HASHED_FILE_NAME], Integer.parseInt(data[FILE_SIZE]), data[HASHED_FILE_CONTENT]); + } +} diff --git a/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java index 416988c..1f288ea 100644 --- a/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java +++ b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java @@ -41,7 +41,7 @@ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR { @Override public void setServerListener(UnicastServerListener server) { this.server = server; - server.start(); + new Thread(server).start(); } /** diff --git a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java index e29eb18..db6ec0c 100644 --- a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java +++ b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java @@ -2,6 +2,7 @@ package lightcontainer.repository; import lightcontainer.domains.client.StoreProcessor; import lightcontainer.domains.Task; +import lightcontainer.enumerations.TaskStatus; import lightcontainer.interfaces.ClientHandlerFFE; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.interfaces.StoreProcessorFFE; @@ -30,8 +31,11 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { */ public void alertStoreProcessors(Task task) { // On avertit les stor processors d'une nouvelle tâche - String stor = storeRepository.findSBE(task); - + String stor = storeRepository.findDomain(task); + if (stor != null) { + storeRepository.assignTask(stor, task); + task.setDomain(stor); + } } /** @@ -43,20 +47,36 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { @Override public void onStoreAvailable(StoreProcessor store, ProtocolWriter.ProtocolResult response) { // TODO : Chercher une tâche appropriée + if (response != null) { + Iterator it = tasks.iterator(); + while (it.hasNext()) { + Task task = it.next(); + if (task.isResponseOfClient(store.getDomain())) { + clientRepository.respondToClient(task.getClient(), response); + it.remove(); // Suppression de la tâche + break; + } + } + } + + assignOtherTask(store); + } + + private void assignOtherTask(StoreProcessor store) { Iterator it = tasks.iterator(); while (it.hasNext()) { Task task = it.next(); - if (task.isResponseOfClient(store.getName())) { - clientRepository.respondToClient(task.getClient(), response); - it.remove(); // Suppression de la tâche + if (store.canProcessTask(task)) { + storeRepository.assignTask(store.getDomain(), task); + task.setDomain(store.getDomain()); } } } + @Override - public void newCommand(String command, String client) { - // TODO : Ajouter la tâche - Alerter les StorBackEnds + public void newCommand(ProtocolWriter.ProtocolResult command, String client) { Task task = Task.newInstance(command, client); tasks.add(task); alertStoreProcessors(task); diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java index e0bfea6..fd6bd4d 100644 --- a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java +++ b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java @@ -40,7 +40,7 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { @Override public void setServerListener(MulticastServerListener server) { this.server = server; - server.run(); + new Thread(server).start(); } /** @@ -52,20 +52,31 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { @Override public void addStore(StoreProcessor store) { this.handlers.add(store); + } @Override - public String findSBE(Task task) { + public String findDomain(Task task) { + StoreProcessor handler = findSBE(task); + return handler == null ? null : handler.getDomain(); + } + private StoreProcessor findSBE(Task task) { for (StoreProcessor handler : handlers) { if (handler.canProcessTask(task)) { - return handler.getName(); + return handler; } } return null; } + @Override + public void assignTask(String stor, Task task) { + StoreProcessor handler = findSBE(task); + handler.executeCommand(task.getCommand()); + } + /** * AutoClosable Function * Closes all StoreProcessor stored in this repository and deallocates all resources. diff --git a/app/src/main/resources/rules.txt b/app/src/main/resources/rules.txt index e5d69af..5c800fd 100644 --- a/app/src/main/resources/rules.txt +++ b/app/src/main/resources/rules.txt @@ -33,7 +33,7 @@ client_signin = ^SIGNIN ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$ client_signup = ^SIGNUP ([A-Za-z0-9]{2,20}) ([^ !]{5,50})\r\n$ ffe_signresult = ^(SIGN_OK|SIGN_ERROR)\r\n$ client_filelist = ^FILELIST\r\n$ -ffe_filelistresult = ^FILES(( [^ !]{1,20})!([0-9]{1,10})){0,50}$ +ffe_filelistresult = ^FILES (([^ !]{1,20})!([0-9]{1,10})){0,50}$ client_savefile = ^SAVE_FILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$ ffe_savefileresult = ^(SAVEFILE_OK|SAVEFILE_ERROR)\r\n$ client_getfile = ^GETFILE ([^ !]{1,20})\r\n$