Refactored JSON entities to better reflect the actual JSON structure
added README
This commit is contained in:
parent
3df853734c
commit
ca2bb89cee
41
README.md
Normal file
41
README.md
Normal file
@ -0,0 +1,41 @@
|
||||
Jabit Server
|
||||
============
|
||||
|
||||
This is the server node using the Jabit library. You can run it by calling
|
||||
```
|
||||
java -jar jabit-server.jar
|
||||
```
|
||||
The interface will be available on port 9000, Bitmessage as usual on Port 8444.
|
||||
|
||||
There are still a few problems with the interface (the idea is to allow collecting
|
||||
and displaying broadcasts).
|
||||
|
||||
On first startup it will create a config file (allowing you to configure the
|
||||
Bitmessage port), a whitelist, a blacklist and a shortlist. If the whitelist isn't
|
||||
empty, the blacklist will be irrelevant. You can disable the feature by simply
|
||||
adding a valid Bitmessage address to the whitelist. For shortlisted addresses, only
|
||||
the last five broadcasts are displayed and stored (useful e.g. for time services or
|
||||
Q's Aktivlist).
|
||||
|
||||
Building / Development
|
||||
----------------------
|
||||
|
||||
You can build the jar file with
|
||||
```
|
||||
./gradlew build
|
||||
```
|
||||
As there is a problem with the build order, you'll need to do this twice.
|
||||
|
||||
To deploy on a Ubuntu server (might work on other Linuxes as well), create a file
|
||||
`/etc/init/jabit.conf` with the following contents:
|
||||
```
|
||||
chdir /srv/jabit
|
||||
|
||||
exec su -s /bin/sh -c 'exec "$0" "$@"' jabit -- /usr/bin/java -jar jabit-server.jar --server.port=9000 > /dev/null
|
||||
|
||||
start on runlevel [2345]
|
||||
stop on runlevel [^2345]
|
||||
|
||||
```
|
||||
there must be a user jabit and a folder `/srv/jabit` where this user has write
|
||||
permission containing `jabit-server.jar`.
|
56
src/main/java/ch/dissem/bitmessage/server/Converter.java
Normal file
56
src/main/java/ch/dissem/bitmessage/server/Converter.java
Normal file
@ -0,0 +1,56 @@
|
||||
package ch.dissem.bitmessage.server;
|
||||
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||
import ch.dissem.bitmessage.entity.Plaintext;
|
||||
import ch.dissem.bitmessage.server.entities.Broadcasts;
|
||||
import ch.dissem.bitmessage.server.entities.Message;
|
||||
import ch.dissem.bitmessage.server.entities.Sender;
|
||||
import ch.dissem.bitmessage.utils.UnixTime;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class Converter {
|
||||
public static Broadcasts broadcasts(BitmessageAddress sender, Collection<Plaintext> messages) {
|
||||
Broadcasts result = new Broadcasts();
|
||||
result.sender = sender(sender);
|
||||
result.messages = new Message[messages.size()];
|
||||
int i = 0;
|
||||
for (Plaintext msg : messages) {
|
||||
result.messages[i] = message(msg);
|
||||
i++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Broadcasts broadcasts(BitmessageAddress sender, Message... messages) {
|
||||
Broadcasts result = new Broadcasts();
|
||||
result.sender = sender(sender);
|
||||
result.messages = messages;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Sender sender(BitmessageAddress sender) {
|
||||
Sender result = new Sender();
|
||||
result.address = sender.getAddress();
|
||||
result.alias = sender.toString();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Message message(String subject, String body) {
|
||||
Message result = new Message();
|
||||
result.id = 0;
|
||||
result.received = UnixTime.now();
|
||||
result.subject = subject;
|
||||
result.body = body;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Message message(Plaintext plaintext) {
|
||||
Message result = new Message();
|
||||
result.id = plaintext.getId();
|
||||
result.received = plaintext.getReceived();
|
||||
result.subject = plaintext.getSubject();
|
||||
result.body = plaintext.getText();
|
||||
return result;
|
||||
}
|
||||
}
|
@ -27,7 +27,6 @@ import ch.dissem.bitmessage.repository.JdbcInventory;
|
||||
import ch.dissem.bitmessage.repository.JdbcMessageRepository;
|
||||
import ch.dissem.bitmessage.security.bc.BouncySecurity;
|
||||
import ch.dissem.bitmessage.server.entities.Broadcasts;
|
||||
import ch.dissem.bitmessage.server.entities.Message;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@ -46,6 +45,9 @@ import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.Timer;
|
||||
|
||||
import static ch.dissem.bitmessage.server.Converter.broadcasts;
|
||||
import static ch.dissem.bitmessage.server.Converter.message;
|
||||
|
||||
@CrossOrigin
|
||||
@RestController
|
||||
@EnableAutoConfiguration
|
||||
@ -77,11 +79,11 @@ public class JabitServerApplication {
|
||||
}
|
||||
|
||||
if (!whitelist.isEmpty() && !whitelist.contains(broadcaster.getAddress())) {
|
||||
return new Broadcasts(broadcaster, new Message("Not Whitelisted", "Messages for " + broadcaster +
|
||||
return broadcasts(broadcaster, message("Not Whitelisted", "Messages for " + broadcaster +
|
||||
" can't be shown, as the sender isn't on the whitelist."));
|
||||
}
|
||||
if (blacklist.contains(broadcaster.getAddress())) {
|
||||
return new Broadcasts(broadcaster, new Message("Blacklisted", "Unfortunately, " + broadcaster +
|
||||
return broadcasts(broadcaster, message("Blacklisted", "Unfortunately, " + broadcaster +
|
||||
" is on the blacklist, so it's messages can't be shown."));
|
||||
}
|
||||
|
||||
@ -95,7 +97,7 @@ public class JabitServerApplication {
|
||||
messages.remove(messages.size() - 1);
|
||||
}
|
||||
}
|
||||
return new Broadcasts(broadcaster, messages);
|
||||
return broadcasts(broadcaster, messages);
|
||||
}
|
||||
|
||||
public JabitServerApplication() {
|
||||
@ -138,7 +140,7 @@ public class JabitServerApplication {
|
||||
LOG.error("Couldn't read port property - is it a number?", e);
|
||||
}
|
||||
|
||||
JdbcConfig config = new JdbcConfig();
|
||||
JdbcConfig config = new JdbcConfig("jdbc:h2:file:jabit;AUTO_SERVER=TRUE", "sa", null);
|
||||
ctx = new BitmessageContext.Builder()
|
||||
.addressRepo(new JdbcAddressRepository(config))
|
||||
.inventory(new JdbcInventory(config))
|
||||
|
@ -22,32 +22,9 @@ import ch.dissem.bitmessage.entity.Plaintext;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Created by chrigu on 30.09.15.
|
||||
* JSON representation for the broadcasts of a specific sender
|
||||
*/
|
||||
public class Broadcasts {
|
||||
private final Sender sender;
|
||||
private final Message[] messages;
|
||||
|
||||
public Broadcasts(BitmessageAddress sender, Collection<Plaintext> messages) {
|
||||
this.sender = new Sender(sender);
|
||||
this.messages = new Message[messages.size()];
|
||||
int i = 0;
|
||||
for (Plaintext msg : messages) {
|
||||
this.messages[i] = new Message(msg);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public Broadcasts(BitmessageAddress sender, Message... messages) {
|
||||
this.sender = new Sender(sender);
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
public Sender getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public Message[] getMessages() {
|
||||
return messages;
|
||||
}
|
||||
public Sender sender;
|
||||
public Message[] messages;
|
||||
}
|
||||
|
@ -23,44 +23,11 @@ import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
/**
|
||||
* Created by chrigu on 30.09.15.
|
||||
* JSON representation for plaintext messages
|
||||
*/
|
||||
public class Message {
|
||||
private Object id;
|
||||
private Long received;
|
||||
private String subject;
|
||||
private String body;
|
||||
|
||||
public Message() {
|
||||
}
|
||||
|
||||
public Message(String subject, String body) {
|
||||
this.id = 0;
|
||||
this.received = UnixTime.now();
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public Message(Plaintext plaintext) {
|
||||
this.id = plaintext.getId();
|
||||
this.received = plaintext.getReceived();
|
||||
this.subject = plaintext.getSubject();
|
||||
this.body = plaintext.getText();
|
||||
}
|
||||
|
||||
public Object getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public Long getReceived() {
|
||||
return received;
|
||||
}
|
||||
public Object id;
|
||||
public Long received;
|
||||
public String subject;
|
||||
public String body;
|
||||
}
|
||||
|
@ -19,22 +19,9 @@ package ch.dissem.bitmessage.server.entities;
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||
|
||||
/**
|
||||
* Created by chrigu on 30.09.15.
|
||||
* JSON representation for a BitmessageAddress
|
||||
*/
|
||||
public class Sender {
|
||||
private final String address;
|
||||
private final String alias;
|
||||
|
||||
public Sender(BitmessageAddress address) {
|
||||
this.address = address.getAddress();
|
||||
this.alias = address.toString();
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
public String address;
|
||||
public String alias;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user