forked from cloudreve/Cloudreve
-
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.
Feat: aria2 download and transfer in slave node (cloudreve#1040)
* Feat: retrieve nodes from data table * Feat: master node ping slave node in REST API * Feat: master send scheduled ping request * Feat: inactive nodes recover loop * Modify: remove database operations from aria2 RPC caller implementation * Feat: init aria2 client in master node * Feat: Round Robin load balancer * Feat: create and monitor aria2 task in master node * Feat: salve receive and handle heartbeat * Fix: Node ID will be 0 in download record generated in older version * Feat: sign request headers with all `X-` prefix * Feat: API call to slave node will carry meta data in headers * Feat: call slave aria2 rpc method from master * Feat: get slave aria2 task status Feat: encode slave response data using gob * Feat: aria2 callback to master node / cancel or select task to slave node * Fix: use dummy aria2 client when caller initialize failed in master node * Feat: slave aria2 status event callback / salve RPC auth * Feat: prototype for slave driven filesystem * Feat: retry for init aria2 client in master node * Feat: init request client with global options * Feat: slave receive async task from master * Fix: competition write in request header * Refactor: dependency initialize order * Feat: generic message queue implementation * Feat: message queue implementation * Feat: master waiting slave transfer result * Feat: slave transfer file in stateless policy * Feat: slave transfer file in slave policy * Feat: slave transfer file in local policy * Feat: slave transfer file in OneDrive policy * Fix: failed to initialize update checker http client * Feat: list slave nodes for dashboard * Feat: test aria2 rpc connection in slave * Feat: add and save node * Feat: add and delete node in node pool * Fix: temp file cannot be removed when aria2 task fails * Fix: delete node in admin panel * Feat: edit node and get node info * Modify: delete unused settings
- Loading branch information
Showing
74 changed files
with
3,642 additions
and
710 deletions.
There are no files selected for viewing
Submodule assets
updated
16 files
+1 −1 | package.json | |
+15 −5 | src/Admin.js | |
+7 −6 | src/component/Admin/Dashboard.js | |
+27 −0 | src/component/Admin/Node/AddNode.js | |
+55 −0 | src/component/Admin/Node/EditNode.js | |
+444 −0 | src/component/Admin/Node/Guide/Aria2RPC.js | |
+276 −0 | src/component/Admin/Node/Guide/Communication.js | |
+104 −0 | src/component/Admin/Node/Guide/Completed.js | |
+157 −0 | src/component/Admin/Node/Guide/Metainfo.js | |
+179 −0 | src/component/Admin/Node/Guide/NodeGuide.js | |
+334 −0 | src/component/Admin/Node/Node.js | |
+0 −305 | src/component/Admin/Setting/Aria2.js | |
+134 −231 | src/component/Admin/Setting/UploadDownload.js | |
+68 −0 | src/component/Admin/Task/Aria2Helper.js | |
+41 −3 | src/component/Admin/Task/Download.js | |
+3,825 −3,650 | yarn.lock |
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
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
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
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
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
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
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,62 @@ | ||
package middleware | ||
|
||
import ( | ||
"github.com/cloudreve/Cloudreve/v3/pkg/cluster" | ||
"github.com/cloudreve/Cloudreve/v3/pkg/serializer" | ||
"github.com/cloudreve/Cloudreve/v3/pkg/slave" | ||
"github.com/gin-gonic/gin" | ||
"strconv" | ||
) | ||
|
||
// MasterMetadata 解析主机节点发来请求的包含主机节点信息的元数据 | ||
func MasterMetadata() gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
c.Set("MasterSiteID", c.GetHeader("X-Site-Id")) | ||
c.Set("MasterSiteURL", c.GetHeader("X-Site-Url")) | ||
c.Set("MasterVersion", c.GetHeader("X-Cloudreve-Version")) | ||
c.Next() | ||
} | ||
} | ||
|
||
// UseSlaveAria2Instance 从机用于获取对应主机节点的Aria2实例 | ||
func UseSlaveAria2Instance() gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
if siteID, exist := c.Get("MasterSiteID"); exist { | ||
// 获取对应主机节点的从机Aria2实例 | ||
caller, err := slave.DefaultController.GetAria2Instance(siteID.(string)) | ||
if err != nil { | ||
c.JSON(200, serializer.Err(serializer.CodeNotSet, "无法获取 Aria2 实例", err)) | ||
c.Abort() | ||
return | ||
} | ||
|
||
c.Set("MasterAria2Instance", caller) | ||
c.Next() | ||
return | ||
} | ||
|
||
c.JSON(200, serializer.ParamErr("未知的主机节点ID", nil)) | ||
c.Abort() | ||
} | ||
} | ||
|
||
func SlaveRPCSignRequired() gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
nodeID, err := strconv.ParseUint(c.GetHeader("X-Node-Id"), 10, 64) | ||
if err != nil { | ||
c.JSON(200, serializer.ParamErr("未知的主机节点ID", err)) | ||
c.Abort() | ||
return | ||
} | ||
|
||
slaveNode := cluster.Default.GetNodeByID(uint(nodeID)) | ||
if slaveNode == nil { | ||
c.JSON(200, serializer.ParamErr("未知的主机节点ID", err)) | ||
c.Abort() | ||
return | ||
} | ||
|
||
SignRequired(slaveNode.MasterAuthInstance())(c) | ||
|
||
} | ||
} |
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
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"github.com/cloudreve/Cloudreve/v3/pkg/conf" | ||
"github.com/cloudreve/Cloudreve/v3/pkg/util" | ||
"github.com/fatih/color" | ||
"github.com/gofrs/uuid" | ||
"github.com/jinzhu/gorm" | ||
) | ||
|
||
|
@@ -34,8 +35,9 @@ func migration() { | |
if conf.DatabaseConfig.Type == "mysql" { | ||
DB = DB.Set("gorm:table_options", "ENGINE=InnoDB") | ||
} | ||
|
||
DB.AutoMigrate(&User{}, &Setting{}, &Group{}, &Policy{}, &Folder{}, &File{}, &Share{}, | ||
&Task{}, &Download{}, &Tag{}, &Webdav{}) | ||
&Task{}, &Download{}, &Tag{}, &Webdav{}, &Node{}) | ||
|
||
// 创建初始存储策略 | ||
addDefaultPolicy() | ||
|
@@ -73,6 +75,8 @@ func addDefaultPolicy() { | |
} | ||
|
||
func addDefaultSettings() { | ||
siteID, _ := uuid.NewV4() | ||
|
||
defaultSettings := []Setting{ | ||
{Name: "siteURL", Value: `http://localhost`, Type: "basic"}, | ||
{Name: "siteName", Value: `Cloudreve`, Type: "basic"}, | ||
|
@@ -83,6 +87,7 @@ func addDefaultSettings() { | |
{Name: "siteDes", Value: `Cloudreve`, Type: "basic"}, | ||
{Name: "siteTitle", Value: `平步云端`, Type: "basic"}, | ||
{Name: "siteScript", Value: ``, Type: "basic"}, | ||
{Name: "siteID", Value: siteID.String(), Type: "basic"}, | ||
{Name: "fromName", Value: `Cloudreve`, Type: "mail"}, | ||
{Name: "mail_keepalive", Value: `30`, Type: "mail"}, | ||
{Name: "fromAdress", Value: `[email protected]`, Type: "mail"}, | ||
|
@@ -100,10 +105,13 @@ func addDefaultSettings() { | |
{Name: "upload_credential_timeout", Value: `1800`, Type: "timeout"}, | ||
{Name: "upload_session_timeout", Value: `86400`, Type: "timeout"}, | ||
{Name: "slave_api_timeout", Value: `60`, Type: "timeout"}, | ||
{Name: "slave_node_retry", Value: `3`, Type: "slave"}, | ||
{Name: "slave_ping_interval", Value: `60`, Type: "slave"}, | ||
{Name: "slave_recover_interval", Value: `120`, Type: "slave"}, | ||
{Name: "slave_transfer_timeout", Value: `172800`, Type: "timeout"}, | ||
{Name: "onedrive_monitor_timeout", Value: `600`, Type: "timeout"}, | ||
{Name: "share_download_session_timeout", Value: `2073600`, Type: "timeout"}, | ||
{Name: "onedrive_callback_check", Value: `20`, Type: "timeout"}, | ||
{Name: "aria2_call_timeout", Value: `5`, Type: "timeout"}, | ||
{Name: "folder_props_timeout", Value: `300`, Type: "timeout"}, | ||
{Name: "onedrive_chunk_retries", Value: `1`, Type: "retry"}, | ||
{Name: "onedrive_source_timeout", Value: `1800`, Type: "timeout"}, | ||
|
@@ -131,11 +139,6 @@ Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; verti | |
{Name: "gravatar_server", Value: `https://www.gravatar.com/`, Type: "avatar"}, | ||
{Name: "defaultTheme", Value: `#3f51b5`, Type: "basic"}, | ||
{Name: "themes", Value: `{"#3f51b5":{"palette":{"primary":{"main":"#3f51b5"},"secondary":{"main":"#f50057"}}},"#2196f3":{"palette":{"primary":{"main":"#2196f3"},"secondary":{"main":"#FFC107"}}},"#673AB7":{"palette":{"primary":{"main":"#673AB7"},"secondary":{"main":"#2196F3"}}},"#E91E63":{"palette":{"primary":{"main":"#E91E63"},"secondary":{"main":"#42A5F5","contrastText":"#fff"}}},"#FF5722":{"palette":{"primary":{"main":"#FF5722"},"secondary":{"main":"#3F51B5"}}},"#FFC107":{"palette":{"primary":{"main":"#FFC107"},"secondary":{"main":"#26C6DA"}}},"#8BC34A":{"palette":{"primary":{"main":"#8BC34A","contrastText":"#fff"},"secondary":{"main":"#FF8A65","contrastText":"#fff"}}},"#009688":{"palette":{"primary":{"main":"#009688"},"secondary":{"main":"#4DD0E1","contrastText":"#fff"}}},"#607D8B":{"palette":{"primary":{"main":"#607D8B"},"secondary":{"main":"#F06292"}}},"#795548":{"palette":{"primary":{"main":"#795548"},"secondary":{"main":"#4CAF50","contrastText":"#fff"}}}}`, Type: "basic"}, | ||
{Name: "aria2_token", Value: ``, Type: "aria2"}, | ||
{Name: "aria2_rpcurl", Value: ``, Type: "aria2"}, | ||
{Name: "aria2_temp_path", Value: ``, Type: "aria2"}, | ||
{Name: "aria2_options", Value: `{}`, Type: "aria2"}, | ||
{Name: "aria2_interval", Value: `60`, Type: "aria2"}, | ||
{Name: "max_worker_num", Value: `10`, Type: "task"}, | ||
{Name: "max_parallel_transfer", Value: `4`, Type: "task"}, | ||
{Name: "secret_key", Value: util.RandStringRunes(256), Type: "auth"}, | ||
|
Oops, something went wrong.