-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's now possible to have clients for the turtle service. This is implemented in a generic way (services can have "slave services"). This is needed to be able to provide turtle support for various services (chat, gxs tunnels, file transfers, ...).
- Loading branch information
Showing
9 changed files
with
320 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
app/src/main/java/io/xeres/app/xrs/service/RsServiceMaster.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2024 by David Gerber - https://zapek.com | ||
* | ||
* This file is part of Xeres. | ||
* | ||
* Xeres is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Xeres is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Xeres. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.xeres.app.xrs.service; | ||
|
||
/** | ||
* This interface allows to implement dependencies between services, that is, one master service | ||
* has a list of clients that it can handle. Each master service or client needs to implement this interface | ||
* which can of course be extended. | ||
* | ||
* @see RsServiceSlave | ||
*/ | ||
public interface RsServiceMaster<T> | ||
{ | ||
/** | ||
* Adds a slave service to a master service. The master service is responsible to handle them. | ||
* | ||
* @param slave the slave service to add to the master | ||
*/ | ||
void addRsSlave(T slave); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/src/main/java/io/xeres/app/xrs/service/RsServiceSlave.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2024 by David Gerber - https://zapek.com | ||
* | ||
* This file is part of Xeres. | ||
* | ||
* Xeres is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Xeres is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Xeres. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.xeres.app.xrs.service; | ||
|
||
/** | ||
* This interface allows to mark a service as a slave of some master. | ||
* | ||
* @see RsServiceMaster | ||
*/ | ||
public interface RsServiceSlave | ||
{ | ||
/** | ||
* Registers this service as a slave of another service. | ||
* | ||
* @return the master service this service is slave of | ||
*/ | ||
RsService isRsSlaveOf(); | ||
} |
105 changes: 105 additions & 0 deletions
105
app/src/main/java/io/xeres/app/xrs/service/filetransfer/FileTransferRsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (c) 2024 by David Gerber - https://zapek.com | ||
* | ||
* This file is part of Xeres. | ||
* | ||
* Xeres is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Xeres is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Xeres. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.xeres.app.xrs.service.filetransfer; | ||
|
||
import io.xeres.app.net.peer.PeerConnection; | ||
import io.xeres.app.service.file.FileService; | ||
import io.xeres.app.xrs.item.Item; | ||
import io.xeres.app.xrs.service.RsService; | ||
import io.xeres.app.xrs.service.RsServiceRegistry; | ||
import io.xeres.app.xrs.service.RsServiceType; | ||
import io.xeres.app.xrs.service.turtle.TurtleRsClient; | ||
import io.xeres.common.id.Sha1Sum; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static io.xeres.app.xrs.service.RsServiceType.FILE_TRANSFER; | ||
|
||
@Component | ||
public class FileTransferRsService extends RsService implements TurtleRsClient | ||
{ | ||
private final FileService fileService; | ||
|
||
public FileTransferRsService(RsServiceRegistry rsServiceRegistry, FileService fileService) | ||
{ | ||
super(rsServiceRegistry); | ||
this.fileService = fileService; | ||
} | ||
|
||
@Override | ||
public RsServiceType getServiceType() | ||
{ | ||
return FILE_TRANSFER; | ||
} | ||
|
||
@Override | ||
public RsService isRsSlaveOf() | ||
{ | ||
return this; | ||
} | ||
|
||
@Override | ||
public void handleItem(PeerConnection sender, Item item) | ||
{ | ||
// XXX | ||
} | ||
|
||
@Override | ||
public boolean handleTunnelRequest(PeerConnection sender, Sha1Sum hash) | ||
{ | ||
var file = fileService.findFile(hash); | ||
if (file.isPresent()) | ||
{ | ||
// XXX: don't forget to handle encrypted hashes, files currently being swarmed and tons of other things | ||
// XXX: sender might not necessarily be needed (it's for the permissions) | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void receiveTurtleData() | ||
{ | ||
|
||
} | ||
|
||
@Override | ||
public boolean receiveSearchRequest() | ||
{ | ||
return false; | ||
} | ||
|
||
@Override | ||
public void receiveSearchResult() | ||
{ | ||
|
||
} | ||
|
||
@Override | ||
public void addVirtualPeer() | ||
{ | ||
|
||
} | ||
|
||
@Override | ||
public void removeVirtualPeer() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,4 +86,9 @@ private short incrementDepth(int id, short depth) | |
} | ||
return depth; | ||
} | ||
|
||
public int getBias() | ||
{ | ||
return bias; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
app/src/main/java/io/xeres/app/xrs/service/turtle/TurtleRsClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2024 by David Gerber - https://zapek.com | ||
* | ||
* This file is part of Xeres. | ||
* | ||
* Xeres is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Xeres is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Xeres. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.xeres.app.xrs.service.turtle; | ||
|
||
import io.xeres.app.net.peer.PeerConnection; | ||
import io.xeres.app.xrs.service.RsServiceSlave; | ||
import io.xeres.common.id.Sha1Sum; | ||
|
||
public interface TurtleRsClient extends RsServiceSlave | ||
{ | ||
/** | ||
* @param sender | ||
* @param hash | ||
* @return true if found | ||
*/ | ||
boolean handleTunnelRequest(PeerConnection sender, Sha1Sum hash); | ||
|
||
void receiveTurtleData(); // XXX: args | ||
|
||
boolean receiveSearchRequest(); // XXX: args | ||
|
||
void receiveSearchResult(); // XXX: args | ||
|
||
void addVirtualPeer(); // XXX: args | ||
|
||
void removeVirtualPeer(); // XXX: args | ||
} |
Oops, something went wrong.