Skip to content

Commit

Permalink
Update core (#2408)
Browse files Browse the repository at this point in the history
* Update go-libipni to get leak fix

- Remove unnecessary calls to set header for status ok.
- Remove unsupported admin api endpoints.
* Remove unsupported admin import command
* Remove unused function
* update version
  • Loading branch information
gammazero authored Nov 21, 2023
1 parent 6867bb7 commit c7b33cb
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 217 deletions.
82 changes: 1 addition & 81 deletions admin/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"io"
"net/http"
"net/url"
"os"
"strconv"
"strings"

Expand Down Expand Up @@ -86,58 +85,6 @@ func (c *Client) Freeze(ctx context.Context) error {
return nil
}

// ImportFromManifest processes entries from manifest and imports them into the
// indexer.
func (c *Client) ImportFromManifest(ctx context.Context, fileName string, provID peer.ID, contextID, metadata []byte) error {
u := c.baseURL.JoinPath(importPath, "manifest", provID.String())
req, err := c.newUploadRequest(ctx, u.String(), fileName, contextID, metadata)
if err != nil {
return err
}
resp, err := c.c.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()

// Handle failed requests
if resp.StatusCode != http.StatusOK {
var errMsg string
body, err := io.ReadAll(resp.Body)
if err == nil && len(body) != 0 {
errMsg = ": " + string(body)
}
return fmt.Errorf("importing from manifest failed: %v%s", http.StatusText(resp.StatusCode), errMsg)
}
return nil
}

// ImportFromCidList process entries from a cidlist and imprts it into the
// indexer.
func (c *Client) ImportFromCidList(ctx context.Context, fileName string, provID peer.ID, contextID, metadata []byte) error {
u := c.baseURL.JoinPath(importPath, "cidlist", provID.String())
req, err := c.newUploadRequest(ctx, u.String(), fileName, contextID, metadata)
if err != nil {
return err
}
resp, err := c.c.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()

// Handle failed requests
if resp.StatusCode != http.StatusOK {
var errMsg string
body, err := io.ReadAll(resp.Body)
if err == nil && len(body) != 0 {
errMsg = ": " + string(body)
}
return fmt.Errorf("importing from cidlist failed: %v%s", http.StatusText(resp.StatusCode), errMsg)
}
return nil
}

func (c *Client) GetPendingSyncs(ctx context.Context) ([]string, error) {
u := c.baseURL.JoinPath(ingestPath, "sync")
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil)
Expand Down Expand Up @@ -439,6 +386,7 @@ func (c *Client) SetLogLevels(ctx context.Context, sysLvl map[string]string) err
}
return apierror.FromResponse(resp.StatusCode, body)
}

return nil
}

Expand Down Expand Up @@ -584,31 +532,3 @@ func (c *Client) ingestRequest(ctx context.Context, peerID peer.ID, action, meth

return nil
}

func (c *Client) newUploadRequest(ctx context.Context, uri, fileName string, contextID, metadata []byte) (*http.Request, error) {
file, err := os.Open(fileName)
if err != nil {
return nil, err
}
defer file.Close()

params := map[string][]byte{
"file": []byte(fileName),
"context_id": contextID,
"metadata": metadata,
}

bodyData, err := json.Marshal(&params)
if err != nil {
return nil, err
}

body := bytes.NewBuffer(bodyData)

req, err := http.NewRequestWithContext(ctx, http.MethodPost, uri, body)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
return req, nil
}
115 changes: 0 additions & 115 deletions command/import.go

This file was deleted.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ require (
github.com/ipld/go-ipld-adl-hamt v0.0.0-20220616142416-9004dbd839e0
github.com/ipld/go-ipld-prime v0.21.0
github.com/ipld/go-ipld-prime/storage/dsadapter v0.0.0-20230102063945-1a409dc236dd
github.com/ipni/go-indexer-core v0.8.2
github.com/ipni/go-libipni v0.5.6
github.com/ipni/go-indexer-core v0.8.3
github.com/ipni/go-libipni v0.5.7
github.com/libp2p/go-libp2p v0.32.1
github.com/libp2p/go-msgio v0.3.0
github.com/mitchellh/go-homedir v1.1.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,10 @@ github.com/ipld/go-ipld-prime v0.21.0/go.mod h1:3RLqy//ERg/y5oShXXdx5YIp50cFGOan
github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20230102063945-1a409dc236dd h1:gMlw/MhNr2Wtp5RwGdsW23cs+yCuj9k2ON7i9MiJlRo=
github.com/ipld/go-ipld-prime/storage/dsadapter v0.0.0-20230102063945-1a409dc236dd h1:qdjo1CRvAQhOMoyYjPnbdZ5rYFFmqztweQ9KAsuWpO0=
github.com/ipld/go-ipld-prime/storage/dsadapter v0.0.0-20230102063945-1a409dc236dd/go.mod h1:9DD/GM0JNPoisgR09F62kbBi7kHa4eDIea4XshXYOVc=
github.com/ipni/go-indexer-core v0.8.2 h1:Vq13NIUDRJQLOTr9WSa9nXBtLjyOd7Ti3rggWpaiF6Y=
github.com/ipni/go-indexer-core v0.8.2/go.mod h1:28d+2YqNoWM8H8vNeFTUaW2hGqeJoqE7daK1EPvw0bE=
github.com/ipni/go-libipni v0.5.6 h1:dg71WdPyUj25z7dR2EW/7hYO+8i+ZG/sBpYzWj4sy8s=
github.com/ipni/go-libipni v0.5.6/go.mod h1:+S7MXdUoYyrKK37clglSJyzIV8AkQYG5TuMZhLIgJek=
github.com/ipni/go-indexer-core v0.8.3 h1:JorImuezGK30Ehz7t7QfqJ9Xaf6fSLVmoaIRoUbEZ8M=
github.com/ipni/go-indexer-core v0.8.3/go.mod h1:As741p4QNdbV+5OpM1/Arw5Usj2HLzoz7l2Og7LEMSY=
github.com/ipni/go-libipni v0.5.7 h1:6/JLZGfv3I54ArBKfS+k/ywOCntXtxMcD7qIf8+uexY=
github.com/ipni/go-libipni v0.5.7/go.mod h1:+S7MXdUoYyrKK37clglSJyzIV8AkQYG5TuMZhLIgJek=
github.com/iris-contrib/blackfriday v2.0.0+incompatible/go.mod h1:UzZ2bDEoaSGPbkg6SAB4att1aAwTmVIx/5gCVqeyUdI=
github.com/iris-contrib/go.uuid v2.0.0+incompatible/go.mod h1:iz2lgM/1UnEf1kP0L/+fafWORmlnuysV2EMP8MW+qe0=
github.com/iris-contrib/i18n v0.0.0-20171121225848-987a633949d0/go.mod h1:pMCz62A0xJL6I+umB2YTlFRwWXaDFA0jy+5HzGiJjqI=
Expand Down
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func main() {
command.AdminCmd,
command.AssignerCmd,
command.DaemonCmd,
command.ImportCmd,
command.InitCmd,
command.LoadtestCmd,
command.LogCmd,
Expand Down
1 change: 0 additions & 1 deletion server/admin/config_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func setLogLevel(w http.ResponseWriter, r *http.Request) {
}
log.Infow("Log level changed", "subsystem", ss, "level", l)
}
w.WriteHeader(http.StatusOK)
}

// listLogSubSystems prints current logging subsystems one at a line.
Expand Down
12 changes: 0 additions & 12 deletions server/admin/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ func (h *adminHandler) handoffPeer(w http.ResponseWriter, r *http.Request) {
assignError(w, err)
return
}

w.WriteHeader(http.StatusOK)
}

func (h *adminHandler) assignPeer(w http.ResponseWriter, r *http.Request) {
Expand All @@ -170,8 +168,6 @@ func (h *adminHandler) assignPeer(w http.ResponseWriter, r *http.Request) {
assignError(w, err)
return
}

w.WriteHeader(http.StatusOK)
}

func assignError(w http.ResponseWriter, err error) {
Expand Down Expand Up @@ -213,7 +209,6 @@ func (h *adminHandler) unassignPeer(w http.ResponseWriter, r *http.Request) {
}

log.Infow("Unassigned publisher from indexer", "publisher", peerID)
w.WriteHeader(http.StatusOK)
}

// ----- ingest handlers -----
Expand All @@ -231,7 +226,6 @@ func (h *adminHandler) allowPeer(w http.ResponseWriter, r *http.Request) {
if h.reg.AllowPeer(peerID) {
log.Infow("Update config to persist allowing peer", "peerr", peerID)
}
w.WriteHeader(http.StatusOK)
}

func (h *adminHandler) blockPeer(w http.ResponseWriter, r *http.Request) {
Expand All @@ -247,7 +241,6 @@ func (h *adminHandler) blockPeer(w http.ResponseWriter, r *http.Request) {
if h.reg.BlockPeer(peerID) {
log.Infow("Update config to persist blocking peer", "provider", peerID)
}
w.WriteHeader(http.StatusOK)
}

func (h *adminHandler) handlePostSyncs(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -418,8 +411,6 @@ func (h *adminHandler) importProviders(w http.ResponseWriter, r *http.Request) {
http.Error(w, msg, http.StatusBadGateway)
return
}

w.WriteHeader(http.StatusOK)
}

func (h *adminHandler) reloadConfig(w http.ResponseWriter, r *http.Request) {
Expand All @@ -434,7 +425,6 @@ func (h *adminHandler) reloadConfig(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
}

// ----- admin handlers -----
Expand All @@ -455,8 +445,6 @@ func (h *adminHandler) freeze(w http.ResponseWriter, r *http.Request) {
http.Error(w, "", http.StatusInternalServerError)
return
}

w.WriteHeader(http.StatusOK)
}

func (h *adminHandler) status(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "v0.8.8"
"version": "v0.8.9"
}

0 comments on commit c7b33cb

Please sign in to comment.