刘嘉昕 | 88d3f7d | 2025-06-04 11:54:09 +0800 | [diff] [blame] | 1 | package com.pt5.pthouduan.entity; |
| 2 | |
| 3 | import com.pt5.pthouduan.service.PasskeyValidator; |
| 4 | import com.pt5.pthouduan.service.UserService; |
| 5 | import com.turn.ttorrent.tracker.Tracker; |
| 6 | import com.turn.ttorrent.tracker.TorrentsRepository; |
| 7 | import com.turn.ttorrent.tracker.TrackerRequestProcessor; |
| 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | import org.springframework.stereotype.Service; |
| 10 | |
| 11 | import java.io.IOException; |
| 12 | |
| 13 | @Service |
| 14 | public class TrackerInitializer { |
| 15 | |
| 16 | @Autowired |
| 17 | private PasskeyValidator passkeyValidator; |
| 18 | |
| 19 | public Tracker createTracker() throws IOException { |
| 20 | TorrentsRepository repository = new TorrentsRepository(1000); |
| 21 | |
| 22 | // 1. 创建自定义的Processor |
| 23 | TrackerRequestProcessor processor = new PasskeyTrackerProcessor( |
| 24 | repository, |
| 25 | passkeyValidator |
| 26 | ); |
| 27 | |
| 28 | // 2. 使用四参数构造器 |
| 29 | Tracker tracker = new Tracker( |
| 30 | 6969, // 端口(与Nginx配置一致) |
| 31 | "http://127.0.0.1/announce", // 对外公告地址 |
| 32 | processor, // 自定义的Processor |
| 33 | repository // Torrent仓库 |
| 34 | ); |
| 35 | tracker.setAnnounceInterval(100); |
| 36 | |
| 37 | tracker.setAcceptForeignTorrents(false); // 禁止未注册的种子 |
| 38 | return tracker; |
| 39 | } |
| 40 | } |