Skip to content

Commit cf80205

Browse files
committed
增加成员控制
1 parent 1c0544e commit cf80205

File tree

9 files changed

+53
-12
lines changed

9 files changed

+53
-12
lines changed

conf/nbs-conf.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ nbs.client.merkle.add.log.name=.merkle
55
nbs.client.profile.root=profile
66
nbs.client.files.root=nbs
77
nbs.client.im.topic.subworld =disabled
8+
nbs.client.heart.monitor.seconds=300
89
nbs.client.i18n.home=zh_cn
10+
#nbs server config
911
nbs.server.address=/ip4/127.0.0.1/tcp/5001
1012
nbs.server.address.gateway-url=http://127.0.0.1:8080
1113
nbs.server.address.host=127.0.0.1
1214
nbs.server.address.api-port=5001
1315
nbs.server.address.gateway-port=8080
16+

conf/nbs.db

0 Bytes
Binary file not shown.

profile/.merkle

Whitespace-only changes.

profile/avatars/lambor64.png

-8.4 KB
Binary file not shown.

profile/avatars/logo.png

-8.17 KB
Binary file not shown.

src/main/java/com/nbs/ui/panels/ContactsPanel.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.alibaba.fastjson.JSON;
66
import com.nbs.biz.model.ContactsEntity;
77
import com.nbs.biz.service.ContactsService;
8+
import io.nbs.client.services.IpfsMessageSender;
89
import io.nbs.client.vo.ContactsItem;
910
import com.nbs.entity.PeerBoradcastInfo;
1011
import com.nbs.entity.PeerInfoBase;
@@ -142,8 +143,6 @@ private void getPeerAvatar(){
142143
private List<ContactsEntity> getContacts(){
143144
List<ContactsEntity> contacts = service.findAll();
144145
if(contacts==null)contacts = new ArrayList<>();
145-
RadomCharactersHelper charactersHelper = RadomCharactersHelper.getInstance();
146-
String hashPre = "hash.";
147146
if(AppMainWindow.currentPeerInfo()!=null){
148147
PeerInfoBase base = AppMainWindow.currentPeerInfo();
149148
ContactsEntity selfModel = new ContactsEntity(base.getPeerID(),base.getNick());
@@ -154,10 +153,15 @@ private List<ContactsEntity> getContacts(){
154153

155154
IPFS ipfs = IPFSHelper.getInstance().getIpfs();
156155

156+
157157
try {
158158
Object obj = null;
159+
if(ConfigurationHelper.getInstance().subWorldPeers()){
160+
obj = ipfs.pubsub.peers(IpfsMessageSender.NBSWORLD_IMS_TOPIC);
161+
}else {
162+
obj = ipfs.pubsub.peers();
163+
}
159164

160-
obj = ipfs.pubsub.peers();
161165
if(obj==null)return contacts;
162166
List<String> peers = (List<String>)JSONParser.getValue(obj,"Strings");
163167
if(peers!=null&&peers.size()>0){
@@ -195,6 +199,7 @@ private List<ContactsEntity> getContacts(){
195199
private void subWorld(long sleeps){
196200
List<Map<String, Object>> resList = Collections.synchronizedList(new ArrayList<>());
197201
AtomicInteger size = new AtomicInteger(0);
202+
198203
new Thread(()->{
199204
logger.warn(DateHelper.currentTime()+">>>>>>>启动订阅 NBSWorld..."+IPFSHelper.NBSWORLD_IMS_TOPIC);
200205
IPFS ipfs = new IPFS(ConfigurationHelper.getInstance().getIPFSAddress());

src/main/java/io/nbs/client/services/IpfsMessageReceiver.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class IpfsMessageReceiver{
4747
boolean ctrlSign = true;
4848
private static boolean runing = false;
4949

50+
5051
public IpfsMessageReceiver() {
5152
worldTopic = IpfsMessageSender.NBSWORLD_IMS_TOPIC;
5253
ipfs = new IPFS(ConfigurationHelper.getInstance().getIPFSAddress());

src/main/java/io/nbs/client/ui/frames/MainFrame.java

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.nbs.client.cnsts.OSUtil;
99
import io.nbs.client.services.IpfsMessageSender;
1010
import io.nbs.client.services.MessageSendService;
11+
import io.nbs.commons.helper.ConfigurationHelper;
1112
import io.nbs.sdk.beans.OnlineMessage;
1213
import io.nbs.sdk.beans.PeerInfo;
1314
import io.nbs.client.ui.panels.MainContentPanel;
@@ -22,6 +23,7 @@
2223
import javax.swing.*;
2324
import javax.swing.border.Border;
2425
import java.awt.*;
26+
import java.util.concurrent.TimeUnit;
2527

2628
/**
2729
* @Package : io.ipfs.nbs.ui.frames
@@ -47,6 +49,7 @@ public class MainFrame extends JFrame {
4749
public int currentWindowWidth = W_SIZE;
4850
public int currentWindowHeight = H_SIZE;
4951
public static int RIGHT_EIDTH = 540;
52+
private static boolean heartMonitor = true;
5053

5154
public static final int TOOLBAR_WIDTH = 52;
5255

@@ -219,22 +222,42 @@ public void refreshAvatar(){
219222
private void notifyWorldOnline(){
220223
PeerInfo info = Launcher.currentPeer;
221224
if(info==null)return;
225+
OnlineMessage message = convertByPeerInfo(info);
226+
//IP 解析
227+
//nbs.client.heart.monitor.seconds
228+
final int seconds = ConfigurationHelper.getInstance().getHeartMonitorSleep();
229+
new Thread(()->{
230+
while (heartMonitor){
231+
try {
232+
if(message!=null)messageSender.sendOnline(message);
233+
logger.info("heart monitor {}",System.currentTimeMillis());
234+
} catch (Exception e) {
235+
logger.warn(e.getMessage(),e.getCause());
236+
}
237+
try {
238+
TimeUnit.SECONDS.sleep(seconds);
239+
} catch (InterruptedException e) {
240+
}
241+
}
242+
}).start();
243+
244+
//刷新数据库登录
245+
peerLoginService.refreshLoginInfo(info);
246+
}
247+
248+
/**
249+
*
250+
* @return
251+
*/
252+
private OnlineMessage convertByPeerInfo(PeerInfo info){
222253
OnlineMessage message = new OnlineMessage(info.getId(),info.getNick(),info.getFrom());
223254
if(StringUtils.isNotBlank(info.getAvatar())){
224255
message.setAvatar(info.getAvatar());
225256
message.setAvatarFile(info.getAvatarName());
226257
message.setAvatarSuffix(info.getAvatarSuffix());
227258
message.setLocations("中国*北京");
228259
}
229-
//IP 解析
230-
try {
231-
messageSender.sendOnline(message);
232-
} catch (Exception e) {
233-
logger.warn(e.getMessage(),e.getCause());
234-
}
235-
236-
//刷新数据库登录
237-
peerLoginService.refreshLoginInfo(info);
260+
return message;
238261
}
239262

240263

src/main/java/io/nbs/commons/helper/ConfigurationHelper.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ public static ConfigurationHelper getInstance(){
9191
return instance;
9292
}
9393

94+
/**
95+
*
96+
* @return
97+
*/
98+
public int getHeartMonitorSleep(){
99+
String sec = cfgProps.getProperty("nbs.client.heart.monitor.seconds","300");
100+
return Integer.parseInt(sec);
101+
}
102+
94103

95104
/**
96105
* 获取IPFS服务地址

0 commit comments

Comments
 (0)