Merge pull request #27 from informatik-ag-ngl/f/reject_handshake
Produce HandshakeRejectionEvents
This commit is contained in:
commit
e4c72c83f5
@ -1,4 +1,13 @@
|
|||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
@ -6,10 +15,101 @@ org.eclipse.jdt.core.compiler.compliance=1.8
|
|||||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.APILeak=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.deadCode=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.deprecation=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.emptyStatement=info
|
||||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.nullReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
|
||||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
|
||||||
|
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedParameter=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||||
org.eclipse.jdt.core.compiler.release=disabled
|
org.eclipse.jdt.core.compiler.release=disabled
|
||||||
org.eclipse.jdt.core.compiler.source=1.8
|
org.eclipse.jdt.core.compiler.source=1.8
|
||||||
|
29
pom.xml
29
pom.xml
@ -28,12 +28,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.informatik-ag-ngl</groupId>
|
<groupId>com.github.informatik-ag-ngl</groupId>
|
||||||
<artifactId>envoy-common</artifactId>
|
<artifactId>envoy-common</artifactId>
|
||||||
<version>develop-SNAPSHOT</version>
|
<version>v0.2-alpha</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.informatik-ag-ngl</groupId>
|
<groupId>com.github.informatik-ag-ngl</groupId>
|
||||||
<artifactId>java-nio-server</artifactId>
|
<artifactId>java-nio-server</artifactId>
|
||||||
<version>master-SNAPSHOT</version>
|
<version>v0.1-alpha</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate</groupId>
|
||||||
@ -54,5 +54,30 @@
|
|||||||
<directory>src/main/resources</directory>
|
<directory>src/main/resources</directory>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<version>2.4.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>envoy.server.Startup</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
@ -8,6 +8,7 @@ import com.jenkov.nioserver.Server;
|
|||||||
|
|
||||||
import envoy.server.data.ConfigItem;
|
import envoy.server.data.ConfigItem;
|
||||||
import envoy.server.database.PersistenceManager;
|
import envoy.server.database.PersistenceManager;
|
||||||
|
import envoy.server.net.ConnectionManager;
|
||||||
import envoy.server.net.ObjectMessageProcessor;
|
import envoy.server.net.ObjectMessageProcessor;
|
||||||
import envoy.server.net.ObjectMessageReader;
|
import envoy.server.net.ObjectMessageReader;
|
||||||
import envoy.server.processors.*;
|
import envoy.server.processors.*;
|
||||||
@ -53,7 +54,7 @@ public class Startup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void initializeCurrentMessageId() {
|
private static void initializeCurrentMessageId() {
|
||||||
PersistenceManager persMan = PersistenceManager.getPersistenceManager();
|
PersistenceManager persMan = PersistenceManager.getInstance();
|
||||||
if (persMan.getConfigItemById("currentMessageId") == null) persMan.addConfigItem(new ConfigItem("currentMessageId", "0"));
|
if (persMan.getConfigItemById("currentMessageId") == null) persMan.addConfigItem(new ConfigItem("currentMessageId", "0"));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -66,7 +66,7 @@ public class Message {
|
|||||||
* @since Envoy Server Standalone v0.1-alpha
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public Message(envoy.data.Message message) {
|
public Message(envoy.data.Message message) {
|
||||||
PersistenceManager persMan = PersistenceManager.getPersistenceManager();
|
PersistenceManager persMan = PersistenceManager.getInstance();
|
||||||
id = message.getId();
|
id = message.getId();
|
||||||
status = message.getStatus();
|
status = message.getStatus();
|
||||||
text = message.getText();
|
text = message.getText();
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
package envoy.server.database;
|
package envoy.server.database;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityTransaction;
|
import javax.persistence.EntityTransaction;
|
||||||
import javax.persistence.Persistence;
|
import javax.persistence.Persistence;
|
||||||
|
|
||||||
|
import envoy.data.User.UserStatus;
|
||||||
import envoy.server.data.ConfigItem;
|
import envoy.server.data.ConfigItem;
|
||||||
import envoy.server.data.Message;
|
import envoy.server.data.Message;
|
||||||
import envoy.server.data.User;
|
import envoy.server.data.User;
|
||||||
|
import envoy.server.net.ConnectionManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Project: <strong>envoy-server-standalone</strong><br>
|
* Project: <strong>envoy-server-standalone</strong><br>
|
||||||
@ -32,14 +35,21 @@ public class PersistenceManager {
|
|||||||
*/
|
*/
|
||||||
private PersistenceManager() {
|
private PersistenceManager() {
|
||||||
transaction.begin();
|
transaction.begin();
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> transaction.commit()));
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
|
ConnectionManager.getInstance()
|
||||||
|
.getOnlineUsers()
|
||||||
|
.stream()
|
||||||
|
.map(this::getUserById)
|
||||||
|
.forEach(user -> { user.setStatus(UserStatus.OFFLINE); user.setLastSeen(new Date()); updateUser(user); });
|
||||||
|
transaction.commit();
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the {@link PersistenceManager} singleton
|
* @return the {@link PersistenceManager} singleton
|
||||||
* @since Envoy Server Standalone v0.1-alpha
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public static PersistenceManager getPersistenceManager() { return persistenceManager; }
|
public static PersistenceManager getInstance() { return persistenceManager; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a {@link User} to the database.
|
* Adds a {@link User} to the database.
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
package envoy.server;
|
package envoy.server.net;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.jenkov.nioserver.ISocketIdListener;
|
import com.jenkov.nioserver.ISocketIdListener;
|
||||||
|
|
||||||
@ -50,14 +46,14 @@ public class ConnectionManager implements ISocketIdListener {
|
|||||||
@Override
|
@Override
|
||||||
public void socketCancelled(long socketId) {
|
public void socketCancelled(long socketId) {
|
||||||
if (!pendingSockets.remove(socketId)) {
|
if (!pendingSockets.remove(socketId)) {
|
||||||
// notifying contacts of this users offline-going
|
// Notify contacts of this users offline-going
|
||||||
envoy.server.data.User user = PersistenceManager.getPersistenceManager().getUserById(getUserIdBySocketId(socketId));
|
envoy.server.data.User user = PersistenceManager.getInstance().getUserById(getUserIdBySocketId(socketId));
|
||||||
user.setStatus(UserStatus.OFFLINE);
|
user.setStatus(UserStatus.OFFLINE);
|
||||||
user.setLastSeen(new Date());
|
user.setLastSeen(new Date());
|
||||||
UserStatusChangeProcessor.updateUserStatus(user);
|
UserStatusChangeProcessor.updateUserStatus(user);
|
||||||
|
|
||||||
// removing the socket
|
// Remove the socket
|
||||||
sockets.entrySet().stream().filter(e -> e.getValue() == socketId).forEach(e -> sockets.remove(e.getValue()));
|
sockets.entrySet().removeIf(e -> e.getValue() == socketId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,4 +94,10 @@ public class ConnectionManager implements ISocketIdListener {
|
|||||||
* @since Envoy Server Standalone v0.1-alpha
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public boolean isOnline(long userId) { return sockets.containsKey(userId); }
|
public boolean isOnline(long userId) { return sockets.containsKey(userId); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the userId of all users who are currently online
|
||||||
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
|
*/
|
||||||
|
public Set<Long> getOnlineUsers() { return sockets.keySet(); }
|
||||||
}
|
}
|
@ -5,9 +5,9 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
import envoy.data.Contacts;
|
import envoy.data.Contacts;
|
||||||
import envoy.event.ContactOperationEvent;
|
import envoy.event.ContactOperationEvent;
|
||||||
import envoy.server.ConnectionManager;
|
|
||||||
import envoy.server.ObjectProcessor;
|
import envoy.server.ObjectProcessor;
|
||||||
import envoy.server.database.PersistenceManager;
|
import envoy.server.database.PersistenceManager;
|
||||||
|
import envoy.server.net.ConnectionManager;
|
||||||
import envoy.server.net.ObjectWriteProxy;
|
import envoy.server.net.ObjectWriteProxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,11 +30,11 @@ public class ContactOperationProcessor implements ObjectProcessor<ContactOperati
|
|||||||
final long contactId = evt.get().getId();
|
final long contactId = evt.get().getId();
|
||||||
|
|
||||||
System.out.printf("Adding user %s to the contact list of user %d.%n", evt.get(), userId);
|
System.out.printf("Adding user %s to the contact list of user %d.%n", evt.get(), userId);
|
||||||
PersistenceManager.getPersistenceManager().addContact(userId, contactId);
|
PersistenceManager.getInstance().addContact(userId, contactId);
|
||||||
|
|
||||||
// Notify the contact if online
|
// Notify the contact if online
|
||||||
if (ConnectionManager.getInstance().isOnline(contactId)) writeProxy.write(connectionManager.getSocketId(contactId),
|
if (ConnectionManager.getInstance().isOnline(contactId)) writeProxy.write(connectionManager.getSocketId(contactId),
|
||||||
new Contacts(Arrays.asList(PersistenceManager.getPersistenceManager().getUserById(userId).toCommonUser())));
|
new Contacts(Arrays.asList(PersistenceManager.getInstance().getUserById(userId).toCommonUser())));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
System.err.printf("Received %s with an unsupported operation.%n", evt);
|
System.err.printf("Received %s with an unsupported operation.%n", evt);
|
||||||
|
@ -6,10 +6,10 @@ import java.util.stream.Collectors;
|
|||||||
import envoy.data.Contacts;
|
import envoy.data.Contacts;
|
||||||
import envoy.event.ContactSearchRequest;
|
import envoy.event.ContactSearchRequest;
|
||||||
import envoy.event.ContactSearchResult;
|
import envoy.event.ContactSearchResult;
|
||||||
import envoy.server.ConnectionManager;
|
|
||||||
import envoy.server.ObjectProcessor;
|
import envoy.server.ObjectProcessor;
|
||||||
import envoy.server.data.User;
|
import envoy.server.data.User;
|
||||||
import envoy.server.database.PersistenceManager;
|
import envoy.server.database.PersistenceManager;
|
||||||
|
import envoy.server.net.ConnectionManager;
|
||||||
import envoy.server.net.ObjectWriteProxy;
|
import envoy.server.net.ObjectWriteProxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,7 +33,7 @@ public class ContactsRequestEventProcessor implements ObjectProcessor<ContactSea
|
|||||||
@Override
|
@Override
|
||||||
public void process(ContactSearchRequest request, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
public void process(ContactSearchRequest request, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
||||||
writeProxy.write(socketId,
|
writeProxy.write(socketId,
|
||||||
new ContactSearchResult(PersistenceManager.getPersistenceManager()
|
new ContactSearchResult(PersistenceManager.getInstance()
|
||||||
.searchUsers(request.get(), ConnectionManager.getInstance().getUserIdBySocketId(socketId))
|
.searchUsers(request.get(), ConnectionManager.getInstance().getUserIdBySocketId(socketId))
|
||||||
.stream()
|
.stream()
|
||||||
.map(User::toCommonUser)
|
.map(User::toCommonUser)
|
||||||
|
@ -19,7 +19,7 @@ import envoy.server.net.ObjectWriteProxy;
|
|||||||
*/
|
*/
|
||||||
public class IdGeneratorRequestProcessor implements ObjectProcessor<IdGeneratorRequest> {
|
public class IdGeneratorRequestProcessor implements ObjectProcessor<IdGeneratorRequest> {
|
||||||
|
|
||||||
private static final long ID_RANGE = 2;
|
private static final long ID_RANGE = 200;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<IdGeneratorRequest> getInputClass() { return IdGeneratorRequest.class; }
|
public Class<IdGeneratorRequest> getInputClass() { return IdGeneratorRequest.class; }
|
||||||
@ -28,10 +28,10 @@ public class IdGeneratorRequestProcessor implements ObjectProcessor<IdGeneratorR
|
|||||||
public void process(IdGeneratorRequest input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
public void process(IdGeneratorRequest input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
||||||
System.out.println("Received id generation request.");
|
System.out.println("Received id generation request.");
|
||||||
|
|
||||||
ConfigItem currentId = PersistenceManager.getPersistenceManager().getConfigItemById("currentMessageId");
|
ConfigItem currentId = PersistenceManager.getInstance().getConfigItemById("currentMessageId");
|
||||||
IdGenerator generator = new IdGenerator(Integer.parseInt(currentId.getValue()), ID_RANGE);
|
IdGenerator generator = new IdGenerator(Integer.parseInt(currentId.getValue()), ID_RANGE);
|
||||||
currentId.setValue(String.valueOf(Integer.parseInt(currentId.getValue()) + ID_RANGE));
|
currentId.setValue(String.valueOf(Integer.parseInt(currentId.getValue()) + ID_RANGE));
|
||||||
PersistenceManager.getPersistenceManager().updateConfigItem(currentId);
|
PersistenceManager.getInstance().updateConfigItem(currentId);
|
||||||
|
|
||||||
System.out.println("Sending new id generator " + generator);
|
System.out.println("Sending new id generator " + generator);
|
||||||
writeProxy.write(socketId, generator);
|
writeProxy.write(socketId, generator);
|
||||||
|
@ -4,15 +4,18 @@ import java.io.IOException;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
|
|
||||||
import envoy.data.Contacts;
|
import envoy.data.Contacts;
|
||||||
import envoy.data.LoginCredentials;
|
import envoy.data.LoginCredentials;
|
||||||
import envoy.data.Message.MessageStatus;
|
import envoy.data.Message.MessageStatus;
|
||||||
import envoy.data.User;
|
import envoy.data.User;
|
||||||
import envoy.data.User.UserStatus;
|
import envoy.data.User.UserStatus;
|
||||||
import envoy.server.ConnectionManager;
|
import envoy.event.HandshakeRejectionEvent;
|
||||||
import envoy.server.ObjectProcessor;
|
import envoy.server.ObjectProcessor;
|
||||||
import envoy.server.data.Message;
|
import envoy.server.data.Message;
|
||||||
import envoy.server.database.PersistenceManager;
|
import envoy.server.database.PersistenceManager;
|
||||||
|
import envoy.server.net.ConnectionManager;
|
||||||
import envoy.server.net.ObjectWriteProxy;
|
import envoy.server.net.ObjectWriteProxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,23 +31,24 @@ import envoy.server.net.ObjectWriteProxy;
|
|||||||
*/
|
*/
|
||||||
public class LoginCredentialProcessor implements ObjectProcessor<LoginCredentials> {
|
public class LoginCredentialProcessor implements ObjectProcessor<LoginCredentials> {
|
||||||
|
|
||||||
private PersistenceManager persistenceManager = PersistenceManager.getPersistenceManager();
|
private final PersistenceManager persistenceManager = PersistenceManager.getInstance();
|
||||||
|
private final ConnectionManager connectionManager = ConnectionManager.getInstance();
|
||||||
@Override
|
|
||||||
public Class<LoginCredentials> getInputClass() { return LoginCredentials.class; }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(LoginCredentials input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
public void process(LoginCredentials input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
||||||
UserStatusChangeProcessor.setWriteProxy(writeProxy);
|
UserStatusChangeProcessor.setWriteProxy(writeProxy);
|
||||||
System.out.println(String.format("Received login credentials %s from socket ID %d", input, socketId));
|
System.out.println(String.format("Received login credentials %s from socket ID %d", input, socketId));
|
||||||
|
|
||||||
envoy.server.data.User user = getUser(input);
|
envoy.server.data.User user = getUser(input, socketId, writeProxy);
|
||||||
|
|
||||||
// Not logged in successfully
|
// Not logged in successfully
|
||||||
if (user == null) return;
|
if (user == null) {
|
||||||
ConnectionManager.getInstance().registerUser(user.getId(), socketId);
|
System.out.println("Rejecting handshake on socket " + socketId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
connectionManager.registerUser(user.getId(), socketId);
|
||||||
|
|
||||||
// notifies contacts of this users online-going and updates his status in the
|
// Notifies contacts of this users online-going and updates his status in the
|
||||||
// database
|
// database
|
||||||
user.setStatus(UserStatus.ONLINE);
|
user.setStatus(UserStatus.ONLINE);
|
||||||
UserStatusChangeProcessor.updateUserStatus(user);
|
UserStatusChangeProcessor.updateUserStatus(user);
|
||||||
@ -59,33 +63,86 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
|
|||||||
System.out.println("Sending contacts...");
|
System.out.println("Sending contacts...");
|
||||||
writeProxy.write(socketId, contacts);
|
writeProxy.write(socketId, contacts);
|
||||||
System.out.println("Acquiring pending messages for the client...");
|
System.out.println("Acquiring pending messages for the client...");
|
||||||
List<Message> pendingMessages = PersistenceManager.getPersistenceManager().getUnreadMessages(user);
|
List<Message> pendingMessages = PersistenceManager.getInstance().getUnreadMessages(user);
|
||||||
for (Message msg : pendingMessages) {
|
for (Message msg : pendingMessages) {
|
||||||
System.out.println("Sending message " + msg.toCommonMessage().toString());
|
System.out.println("Sending message " + msg.toCommonMessage());
|
||||||
writeProxy.write(socketId, msg.toCommonMessage());
|
writeProxy.write(socketId, msg.toCommonMessage());
|
||||||
msg.setReceivedDate(new Date());
|
msg.setReceivedDate(new Date());
|
||||||
msg.setStatus(MessageStatus.RECEIVED);
|
msg.setStatus(MessageStatus.RECEIVED);
|
||||||
PersistenceManager.getPersistenceManager().updateMessage(msg);
|
PersistenceManager.getInstance().updateMessage(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private envoy.server.data.User getUser(LoginCredentials credentials) {
|
@Override
|
||||||
envoy.server.data.User user;
|
public Class<LoginCredentials> getInputClass() { return LoginCredentials.class; }
|
||||||
|
|
||||||
if (credentials.isRegistration()) {
|
private envoy.server.data.User getUser(LoginCredentials credentials, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
||||||
user = new envoy.server.data.User();
|
return credentials.isRegistration() ? newUser(credentials, socketId, writeProxy) : checkForExistingUser(credentials, socketId, writeProxy);
|
||||||
user.setName(credentials.getName());
|
}
|
||||||
user.setLastSeen(new Date());
|
|
||||||
user.setStatus(User.UserStatus.ONLINE);
|
/**
|
||||||
user.setPasswordHash(credentials.getPasswordHash());
|
* @param credentials the input to evaluate
|
||||||
persistenceManager.addUser(user);
|
* @param socketId the socket ID at which the client performing the handshake
|
||||||
user.setContacts(new ArrayList<>());
|
* is connected
|
||||||
} else {
|
* @param writeProxy the {@link ObjectWriteProxy} to use if login was not
|
||||||
user = persistenceManager.getUserByName(credentials.getName());
|
* successful
|
||||||
// TODO: Implement error when user does not exist
|
* @return the database user matching the login credentials
|
||||||
if (!Arrays.equals(credentials.getPasswordHash(), user.getPasswordHash())) // TODO: Wrong Password Response
|
* @throws IOException if sending the failed login back to the client failed
|
||||||
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
|
*/
|
||||||
|
private envoy.server.data.User checkForExistingUser(LoginCredentials credentials, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
||||||
|
try {
|
||||||
|
envoy.server.data.User user = persistenceManager.getUserByName(credentials.getIdentifier());
|
||||||
|
|
||||||
|
// Checking if user is already online
|
||||||
|
if (connectionManager.isOnline(user.getId())) {
|
||||||
|
writeProxy.write(socketId, new HandshakeRejectionEvent(HandshakeRejectionEvent.ALREADY_ONLINE));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Evaluating the correctness of the password hash
|
||||||
|
if (!Arrays.equals(credentials.getPasswordHash(), user.getPasswordHash())) {
|
||||||
|
writeProxy.write(socketId, new HandshakeRejectionEvent(HandshakeRejectionEvent.WRONG_PASSWORD));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return user;
|
return user;
|
||||||
|
} catch (NoResultException e) {
|
||||||
|
// Checking if user exists
|
||||||
|
writeProxy.write(socketId, new HandshakeRejectionEvent(HandshakeRejectionEvent.USER_DOES_NOT_EXIST));
|
||||||
|
} catch (InputMismatchException e) {
|
||||||
|
// Checking if the given password hash is correct
|
||||||
|
writeProxy.write(socketId, new HandshakeRejectionEvent(HandshakeRejectionEvent.WRONG_PASSWORD));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param credentials the credentials upon which to create the new {@link User}
|
||||||
|
* @param socketId the socketID at which the client performing the handshake
|
||||||
|
* is connected
|
||||||
|
* @param writeProxy the write proxy used to notify the client about handshake
|
||||||
|
* rejection
|
||||||
|
* @return the newly created {@link User}
|
||||||
|
* @throws IOException if sending the failed login back to the client failed
|
||||||
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
|
*/
|
||||||
|
private envoy.server.data.User newUser(LoginCredentials credentials, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
||||||
|
try {
|
||||||
|
// Checking that no user already has this identifier
|
||||||
|
PersistenceManager.getInstance().getUserByName(credentials.getIdentifier());
|
||||||
|
// this code only gets executed if this user already exists
|
||||||
|
writeProxy.write(socketId, new HandshakeRejectionEvent(HandshakeRejectionEvent.USER_EXISTS_ALREADY));
|
||||||
|
return null;
|
||||||
|
} catch (NoResultException e) {
|
||||||
|
// Creation of a new user
|
||||||
|
envoy.server.data.User user;
|
||||||
|
user = new envoy.server.data.User();
|
||||||
|
user.setName(credentials.getIdentifier());
|
||||||
|
user.setLastSeen(new Date());
|
||||||
|
user.setStatus(User.UserStatus.ONLINE);
|
||||||
|
user.setPasswordHash(credentials.getPasswordHash());
|
||||||
|
user.setContacts(new ArrayList<>());
|
||||||
|
persistenceManager.addUser(user);
|
||||||
|
return user;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,9 @@ import java.util.Date;
|
|||||||
|
|
||||||
import envoy.data.Message;
|
import envoy.data.Message;
|
||||||
import envoy.event.MessageStatusChangeEvent;
|
import envoy.event.MessageStatusChangeEvent;
|
||||||
import envoy.server.ConnectionManager;
|
|
||||||
import envoy.server.ObjectProcessor;
|
import envoy.server.ObjectProcessor;
|
||||||
import envoy.server.database.PersistenceManager;
|
import envoy.server.database.PersistenceManager;
|
||||||
|
import envoy.server.net.ConnectionManager;
|
||||||
import envoy.server.net.ObjectWriteProxy;
|
import envoy.server.net.ObjectWriteProxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,11 +37,11 @@ public class MessageProcessor implements ObjectProcessor<Message> {
|
|||||||
// Update the message status to RECEIVED
|
// Update the message status to RECEIVED
|
||||||
message.setReceivedDate(new Date());
|
message.setReceivedDate(new Date());
|
||||||
message.nextStatus();
|
message.nextStatus();
|
||||||
writeProxy.write(connectionManager.getSocketId(message.getSenderId()), new MessageStatusChangeEvent(message));
|
writeProxy.write(socketId, new MessageStatusChangeEvent(message));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Recipient online. Failed to send message" + message.getId());
|
System.err.println("Recipient online. Failed to send message" + message.getId());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
PersistenceManager.getPersistenceManager().addMessage(new envoy.server.data.Message(message));
|
PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,9 @@ import java.io.IOException;
|
|||||||
import envoy.data.Message.MessageStatus;
|
import envoy.data.Message.MessageStatus;
|
||||||
import envoy.event.MessageStatusChangeEvent;
|
import envoy.event.MessageStatusChangeEvent;
|
||||||
import envoy.exception.EnvoyException;
|
import envoy.exception.EnvoyException;
|
||||||
import envoy.server.ConnectionManager;
|
|
||||||
import envoy.server.ObjectProcessor;
|
import envoy.server.ObjectProcessor;
|
||||||
import envoy.server.database.PersistenceManager;
|
import envoy.server.database.PersistenceManager;
|
||||||
|
import envoy.server.net.ConnectionManager;
|
||||||
import envoy.server.net.ObjectWriteProxy;
|
import envoy.server.net.ObjectWriteProxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,7 +32,7 @@ public class MessageStatusChangeProcessor implements ObjectProcessor<MessageStat
|
|||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
ConnectionManager conMan = ConnectionManager.getInstance();
|
ConnectionManager conMan = ConnectionManager.getInstance();
|
||||||
PersistenceManager perMan = PersistenceManager.getPersistenceManager();
|
PersistenceManager perMan = PersistenceManager.getInstance();
|
||||||
|
|
||||||
envoy.server.data.Message msg = perMan.getMessageById(input.getId());
|
envoy.server.data.Message msg = perMan.getMessageById(input.getId());
|
||||||
msg.setStatus(input.get());
|
msg.setStatus(input.get());
|
||||||
|
@ -4,10 +4,10 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import envoy.data.User.UserStatus;
|
import envoy.data.User.UserStatus;
|
||||||
import envoy.event.UserStatusChangeEvent;
|
import envoy.event.UserStatusChangeEvent;
|
||||||
import envoy.server.ConnectionManager;
|
|
||||||
import envoy.server.ObjectProcessor;
|
import envoy.server.ObjectProcessor;
|
||||||
import envoy.server.data.User;
|
import envoy.server.data.User;
|
||||||
import envoy.server.database.PersistenceManager;
|
import envoy.server.database.PersistenceManager;
|
||||||
|
import envoy.server.net.ConnectionManager;
|
||||||
import envoy.server.net.ObjectWriteProxy;
|
import envoy.server.net.ObjectWriteProxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +23,7 @@ import envoy.server.net.ObjectWriteProxy;
|
|||||||
public class UserStatusChangeProcessor implements ObjectProcessor<UserStatusChangeEvent> {
|
public class UserStatusChangeProcessor implements ObjectProcessor<UserStatusChangeEvent> {
|
||||||
|
|
||||||
private static ObjectWriteProxy writeProxy;
|
private static ObjectWriteProxy writeProxy;
|
||||||
private static PersistenceManager persistenceManager = PersistenceManager.getPersistenceManager();
|
private static PersistenceManager persistenceManager = PersistenceManager.getInstance();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<UserStatusChangeEvent> getInputClass() { return UserStatusChangeEvent.class; }
|
public Class<UserStatusChangeEvent> getInputClass() { return UserStatusChangeEvent.class; }
|
||||||
|
@ -20,8 +20,6 @@
|
|||||||
value="org.hibernate.dialect.PostgreSQL95Dialect" /> <!-- DB Dialect -->
|
value="org.hibernate.dialect.PostgreSQL95Dialect" /> <!-- DB Dialect -->
|
||||||
<property name="hibernate.hbm2ddl.auto" value="update" /> <!-- create / create-drop / update -->
|
<property name="hibernate.hbm2ddl.auto" value="update" /> <!-- create / create-drop / update -->
|
||||||
|
|
||||||
<property name="hibernate.show_sql" value="true" /> <!-- Show SQL in console -->
|
|
||||||
<property name="hibernate.format_sql" value="true" /> <!-- Show SQL formatted -->
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
Reference in New Issue
Block a user