-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/main/java/com/ghostchu/peerbanhelper/downloaderplug/biglybt/PBHClientIDGenerator.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,52 @@ | ||
package com.ghostchu.peerbanhelper.downloaderplug.biglybt; | ||
|
||
import com.biglybt.pif.clientid.ClientIDException; | ||
import com.biglybt.pif.clientid.ClientIDGenerator; | ||
import lombok.Getter; | ||
|
||
import java.util.Objects; | ||
import java.util.Properties; | ||
@Getter | ||
public class PBHClientIDGenerator implements ClientIDGenerator { | ||
private final static String APPEND_USER_AGENT_TEMPLATE = ";%s/%s (%s)"; | ||
private final static String APPEND_CLIENT_NAME_TEMPLATE = " (🛡%s/%s)"; | ||
private final ClientIDGenerator parent; | ||
private final Plugin plugin; | ||
|
||
public PBHClientIDGenerator(Plugin plugin, ClientIDGenerator parent) { | ||
this.plugin = plugin; | ||
this.parent = parent; | ||
} | ||
|
||
@Override | ||
public byte[] generatePeerID(byte[] hash, boolean for_tracker) throws ClientIDException { | ||
return parent.generatePeerID(hash, for_tracker); | ||
} | ||
|
||
@Override | ||
public void generateHTTPProperties(byte[] hash, Properties properties) throws ClientIDException { | ||
parent.generateHTTPProperties(hash, properties); | ||
var userAgent = properties.get(ClientIDGenerator.PR_USER_AGENT); | ||
var connectorData = plugin.getConnectorData(); | ||
if(connectorData == null) return; | ||
var ourUserAgent = String.format(APPEND_USER_AGENT_TEMPLATE, connectorData.getSoftware(), connectorData.getVersion(), connectorData.getAbbrev()); | ||
userAgent += ourUserAgent; | ||
properties.put(ClientIDGenerator.PR_USER_AGENT, userAgent); | ||
} | ||
|
||
@Override | ||
public String[] filterHTTP(byte[] hash, String[] lines_in) { | ||
return lines_in; | ||
} | ||
|
||
@Override | ||
public Object getProperty(byte[] hash, String property_name) { | ||
var def = parent.getProperty(hash, property_name); | ||
if (Objects.equals(property_name, ClientIDGenerator.PR_CLIENT_NAME)) { | ||
var connectorData = plugin.getConnectorData(); | ||
if(connectorData == null) return def; | ||
return def + String.format(APPEND_CLIENT_NAME_TEMPLATE, connectorData.getSoftware(), connectorData.getVersion()); | ||
} | ||
return def; | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/main/java/com/ghostchu/peerbanhelper/downloaderplug/biglybt/network/ConnectorData.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,14 @@ | ||
package com.ghostchu.peerbanhelper.downloaderplug.biglybt.network; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ConnectorData { | ||
private String software; | ||
private String version; | ||
private String abbrev; | ||
} |
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