Package anbxj
Class Channel_Abstraction
java.lang.Object
anbxj.Channel_Abstraction
- Direct Known Subclasses:
Channel_Client,Channel_ExistingSocket,Channel_Protobuf,Channel_ProtoServer,Channel_Server
Channel Abstraction: a class abstracting TCP/IP channel
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Channel_PropertiesProperties specific to the channel. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for Channel Abstraction. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidChecks if the provided port is within the valid range.voidClose()Close channel streamsGets the role of the channel.Retrieves the channel settings associated with this communication channel.voidOpen()Opens the channel, by invoking the checkPort method.protected voidOpens input and output streams for the specified socket.Receive()Receives an object from the input stream.<T> TReceives an object of a specified type with additional safety checks.static <T> TsafeReadObject(Class<?> type, List<Class<?>> safeClasses, long maxObjects, long maxBytes, InputStream in) A method to replace the unsafe ObjectInputStream.readObject() method built into Java.voidSends an object through the output stream.voidsetStep(int step) Informs the channel about the current protocol step.
-
Field Details
-
cp
Properties specific to the channel.
-
-
Constructor Details
-
Channel_Abstraction
Constructor for Channel Abstraction.- Parameters:
cp- Channel properties for the abstraction.
-
-
Method Details
-
Close
public void Close()Close channel streams -
getChannelRole
Gets the role of the channel.- Returns:
- Channel role.
-
checkPort
protected void checkPort()Checks if the provided port is within the valid range. -
Open
public void Open()Opens the channel, by invoking the checkPort method. -
OpenStreams
Opens input and output streams for the specified socket.- Parameters:
s- Socket for which to open streams.
-
Receive
Receives an object from the input stream.- Returns:
- Received object.
-
Receive
Receives an object of a specified type with additional safety checks.- Type Parameters:
T- Parametric type.- Parameters:
type- Class representing the object type expected to be returned.safeClasses- List of Classes allowed in the serialized object being read.maxObjects- Maximum number of objects allowed inside the serialized object being read.maxBytes- Maximum number of bytes allowed to be read from the InputStream.- Returns:
- Received object of the specified type.
-
safeReadObject
public static <T> T safeReadObject(Class<?> type, List<Class<?>> safeClasses, long maxObjects, long maxBytes, InputStream in) throws IOException, ClassNotFoundException A method to replace the unsafe ObjectInputStream.readObject() method built into Java. This method checks to be sure the classes referenced are safe, the number of objects is limited to something sane, and the number of bytes is limited to a reasonable number. The returned Object is also cast to the specified type.- Type Parameters:
T- Parametric type- Parameters:
type- Class representing the object type expected to be returnedsafeClasses- List of Classes allowed in serialized object being readmaxObjects- long representing the maximum number of objects allowed inside the serialized object being readmaxBytes- long representing the maximum number of bytes allowed to be read from the InputStreamin- InputStream containing an untrusted serialized object- Returns:
- Object read from the stream (cast to the Class of the type parameter)
- Throws:
IOException- I/O error exceptionClassNotFoundException- Class not found exception
-
Send
Sends an object through the output stream.- Parameters:
obj- Object to be sent.
-
getChannelSettings
Retrieves the channel settings associated with this communication channel.The settings encapsulate the configuration parameters of the channel, including the channel type (e.g., plain, SSL), the role (client/server), the remote host and port, and the SSL context algorithm. These settings are originally provided when the channel was created.
- Returns:
- the
Channel_Settingsobject containing the channel's configuration.
-
setStep
public void setStep(int step) Informs the channel about the current protocol step. This is a hint used by serializers (e.g., Protobuf) to select the correct message schema. The default implementation does nothing.- Parameters:
step- the protocol step number
-