Skip to content

Commit

Permalink
update sdk, put handler (CESSProject#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
AstaFrode authored Jun 18, 2024
1 parent 52297b6 commit 8aa310c
Show file tree
Hide file tree
Showing 8 changed files with 692 additions and 610 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/CESSProject/DeOSS
go 1.20

require (
github.com/CESSProject/cess-go-sdk v0.5.1-0.20240606160027-88d65ea0c5dc
github.com/CESSProject/cess-go-sdk v0.5.1-0.20240614092611-fe08925e7f1f
github.com/CESSProject/cess-go-tools v0.2.6
github.com/CESSProject/go-keyring v0.0.0-20220614131247-ee3a8da30fde
github.com/CESSProject/p2p-go v0.3.14
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/CESSProject/cess-go-sdk v0.5.1-0.20240606160027-88d65ea0c5dc h1:hiA+tnhOihnUkFNHZGfBoC2ypGj/zLSdnZN3g1Mce6w=
github.com/CESSProject/cess-go-sdk v0.5.1-0.20240606160027-88d65ea0c5dc/go.mod h1:9BGRFkU3Zc5CYqK9EIz3DY14MjDg6a0bA1DWgMk3qFc=
github.com/CESSProject/cess-go-sdk v0.5.1-0.20240614092611-fe08925e7f1f h1:Xfx1NoG5leBISX2ClV9blm3wtbfgPgNKs8h5YG9RKQ8=
github.com/CESSProject/cess-go-sdk v0.5.1-0.20240614092611-fe08925e7f1f/go.mod h1:9BGRFkU3Zc5CYqK9EIz3DY14MjDg6a0bA1DWgMk3qFc=
github.com/CESSProject/cess-go-tools v0.2.6 h1:kZjqHN8uIyExTu8EEQApLN4qsmpWaWQfgBQD/0wF2+A=
github.com/CESSProject/cess-go-tools v0.2.6/go.mod h1:g86Xkq1+FZHg1srAvkwGqD3WoG+EIdeA2JHQAhhtKqQ=
github.com/CESSProject/go-keyring v0.0.0-20220614131247-ee3a8da30fde h1:5MDRjjtg6PEhqyVjupwaapN96cOZiddOGAYwKQeaTu0=
Expand Down
19 changes: 5 additions & 14 deletions node/discoverMgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,20 @@ func Subscribe(ctx context.Context, h host.Host, bootnode string, callback func(
findpeer peer.AddrInfo
)

fmt.Println("start subscribe...")
out.Ok("start subscribe...")

gossipSub, err := pubsub.NewGossipSub(ctx, h)
if err != nil {
return
}

if strings.Contains(bootnode, "12D3KooWRm2sQg65y2ZgCUksLsjWmKbBtZ4HRRsGLxbN76XTtC8T") {
room = fmt.Sprintf("%s-12D3KooWRm2sQg65y2ZgCUksLsjWmKbBtZ4HRRsGLxbN76XTtC8T", core.NetworkRoom)
} else if strings.Contains(bootnode, "12D3KooWEGeAp1MvvUrBYQtb31FE1LPg7aHsd1LtTXn6cerZTBBd") {
room = fmt.Sprintf("%s-12D3KooWEGeAp1MvvUrBYQtb31FE1LPg7aHsd1LtTXn6cerZTBBd", core.NetworkRoom)
} else if strings.Contains(bootnode, "12D3KooWGDk9JJ5F6UPNuutEKSbHrTXnF5eSn3zKaR27amgU6o9S") {
room = fmt.Sprintf("%s-12D3KooWGDk9JJ5F6UPNuutEKSbHrTXnF5eSn3zKaR27amgU6o9S", core.NetworkRoom)
} else if strings.Contains(bootnode, "12D3KooWS8a18xoBzwkmUsgGBctNo6QCr6XCpUDR946mTBBUTe83") {
room = fmt.Sprintf("%s-12D3KooWS8a18xoBzwkmUsgGBctNo6QCr6XCpUDR946mTBBUTe83", core.NetworkRoom)
} else if strings.Contains(bootnode, "12D3KooWDWeiiqbpNGAqA5QbDTdKgTtwX8LCShWkTpcyxpRf2jA9") {
room = fmt.Sprintf("%s-12D3KooWDWeiiqbpNGAqA5QbDTdKgTtwX8LCShWkTpcyxpRf2jA9", core.NetworkRoom)
} else if strings.Contains(bootnode, "12D3KooWNcTWWuUWKhjTVDF1xZ38yCoHXoF4aDjnbjsNpeVwj33U") {
room = fmt.Sprintf("%s-12D3KooWNcTWWuUWKhjTVDF1xZ38yCoHXoF4aDjnbjsNpeVwj33U", core.NetworkRoom)
data := strings.Split(bootnode, "/p2p/")
if len(data) > 1 {
room = fmt.Sprintf("%s-%s", core.NetworkRoom, data[len(data)-1])
} else {
room = core.NetworkRoom
}
fmt.Println("room: ", room)

// setup local mDNS discovery
if err := setupDiscovery(h); err != nil {
return
Expand Down
3 changes: 3 additions & 0 deletions node/getHandle.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func (n *Node) getHandle(c *gin.Context) {
defer func() { max_concurrent_get_ch <- true }()

clientIp := c.Request.Header.Get("X-Forwarded-For")
if clientIp == "" || clientIp == " " {
clientIp = c.ClientIP()
}
n.Query("info", fmt.Sprintf("[%s] %s", clientIp, INFO_GetRequest))

cipher := c.Request.Header.Get(HTTPHeader_Cipher)
Expand Down
3 changes: 3 additions & 0 deletions node/getRestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func (n *Node) getRestoreHandle(c *gin.Context) {
)

clientIp = c.Request.Header.Get("X-Forwarded-For")
if clientIp == "" || clientIp == " " {
clientIp = c.ClientIP()
}
n.Query("info", fmt.Sprintf("[%s] %s", clientIp, INFO_GetRestoreRequest))

account := c.Request.Header.Get(HTTPHeader_Account)
Expand Down
3 changes: 3 additions & 0 deletions node/postRestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ type RestoreList struct {
// getHandle
func (n *Node) postRestoreHandle(c *gin.Context) {
clientIp := c.Request.Header.Get("X-Forwarded-For")
if clientIp == "" || clientIp == " " {
clientIp = c.ClientIP()
}
n.Query("info", fmt.Sprintf("[%s] %s", clientIp, INFO_PostRestoreRequest))
var err error
var pkey []byte
Expand Down
Loading

0 comments on commit 8aa310c

Please sign in to comment.