Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Fix mobile inbox requests (#870)
Browse files Browse the repository at this point in the history
* fix: mobile inbox request does not take session

Signed-off-by: Sander Pick <sanderpick@gmail.com>

* ipfs: permanently add bootstap peers to peer table on start

Signed-off-by: Sander Pick <sanderpick@gmail.com>

* service: update message handlign to latest libp2p

Signed-off-by: Sander Pick <sanderpick@gmail.com>

* service: properly inc attempts from failed unstore requests

Signed-off-by: Sander Pick <sanderpick@gmail.com>

* chore: remove nodejs dependency

This is a golang project. As such, requiring users to install nodejs is not idiomatic.

Signed-off-by: Sander Pick <sanderpick@gmail.com>

* test: revert removal of add peer to store

Signed-off-by: Sander Pick <sanderpick@gmail.com>

* cmd: add publish command

Signed-off-by: Sander Pick <sanderpick@gmail.com>

* docs: update swagger docs

Signed-off-by: Sander Pick <sanderpick@gmail.com>

* chore: replace main files with named versions

Signed-off-by: Sander Pick <sanderpick@gmail.com>
  • Loading branch information
sanderpick committed Jul 24, 2019
1 parent 8cee3ce commit 0a9eb98
Show file tree
Hide file tree
Showing 39 changed files with 312 additions and 143 deletions.
34 changes: 0 additions & 34 deletions .editorconfig

This file was deleted.

8 changes: 0 additions & 8 deletions .prettierignore

This file was deleted.

1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
setup:
go mod download
go get github.com/ahmetb/govvv
npm install

test:
./test_compile
Expand Down
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Made by Textile](https://img.shields.io/badge/made%20by-Textile-informational.svg?style=popout-square)](https://textile.io)
[![Chat on Slack](https://img.shields.io/badge/slack-slack.textile.io-informational.svg?style=popout-square)](https://slack.textile.io)
[![GitHub license](https://img.shields.io/github/license/textileio/photos-desktop.svg?style=popout-square)](./LICENSE)
[![GitHub license](https://img.shields.io/github/license/textileio/go-textile.svg?style=popout-square)](./LICENSE)
[![Go Report Card](https://goreportcard.com/badge/github.com/textileio/go-textile?style=flat-square)](https://goreportcard.com/report/github.com/textileio/go-textile?style=flat-square)
[![CircleCI branch](https://img.shields.io/circleci/project/github/textileio/go-textile/master.svg?style=popout-square)](https://circleci.com/gh/textileio/go-textile)
[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=popout-square)](https://github.com/RichardLitt/standard-readme)
Expand All @@ -23,8 +23,7 @@ Join us on our [public Slack channel](https://slack.textile.io/) for news, discu
- [Background](#background)
- [Install](#install)
- [Usage](#usage)
- [Develop](#develop)
- [Contribute](#contribute)
- [Contributing](#contributing)
- [Changelog](#changelog)
- [License](#license)

Expand All @@ -46,20 +45,19 @@ With good encryption defaults and anonymous, disposable application services lik

## Install

[Installation instructions](https://docs.textile.io/install/the-daemon/) for the command-line tool and daemon are in [the docs](https://docs.textile.io).
go get github.com/textileio/go-textile

## Usage
[Installation instructions](https://docs.textile.io/install/the-daemon/) for pre-built binaries are in [the docs](https://docs.textile.io).

The [Tour of Textile](https://docs.textile.io/a-tour-of-textile/) goes through many examples and use cases. `textile --help` provides a quick look at the available APIs. For a full overview of every CLI command available, refer to our [Command Line Documentation](https://docs.textile.io/develop/clients/command-line/).
## Usage

## Develop
Go to https://godoc.org/github.com/textileio/go-textile-core.

git clone git@github.com:textileio/go-textile.git
The [Tour of Textile](https://docs.textile.io/a-tour-of-textile/) goes through many examples and use cases. `textile --help` provides a quick look at the available APIs. For a full overview of every CLI command available, refer to our [Command Line Documentation](https://docs.textile.io/develop/clients/command-line/).

### Requirements

- go >= 1.12
- node >= 10.0

Extra setup steps are needed to build the bindings for iOS or Android, as `gomobile` does not yet support [go modules](https://github.com/golang/go/wiki/Modules). You'll need to **move the go-textile source** into your `GOPATH` (like pre-go1.11 development), before installing and initializing the `gomobile` tools:

Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions cmd/main.go → cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,13 @@ There are two types of invites, direct account-to-account and external:
return Ping(*pingAddress)
}

// publish
publishCmd := appCmd.Command("publish", "Publishes stdin to a topic on the network")
publishTopic := publishCmd.Arg("topic", "The topic to publish to").Required().String()
cmds[publishCmd.FullCommand()] = func() error {
return Publish(*publishTopic)
}

// ================================

// profile
Expand Down
4 changes: 1 addition & 3 deletions cmd/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ func (m millOpts) setUse(v string) {

func FileAdd(path string, threadID string, caption string, group bool, verbose bool) error {
var pth string
var fi os.FileInfo
var err error
fi, err = os.Stdin.Stat()
fi, err := os.Stdin.Stat()
if err != nil {
return err
}
Expand Down
18 changes: 18 additions & 0 deletions cmd/publish.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"net/http"
"os"
)

func Publish(topic string) error {
res, err := executeStringCmd(http.MethodPost, "publish", params{
args: []string{topic},
payload: os.Stdin,
})
if err != nil {
return err
}
output(res)
return nil
}
1 change: 1 addition & 0 deletions core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (a *api) Start() {
v0.GET("/summary", a.nodeSummary)

v0.GET("/ping", a.ping)
v0.POST("/publish", a.publish)

account := v0.Group("/account")
{
Expand Down
45 changes: 45 additions & 0 deletions core/api_publish.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package core

import (
"io/ioutil"
"net/http"

"github.com/gin-gonic/gin"
)

// publish godoc
// @Summary Publish payload to topic
// @Description Publishes payload bytes to a topic on the network.
// @Tags utils
// @Accept application/octet-stream
// @Produce text/plain
// @Param X-Textile-Args header string true "topic"
// @Success 204 {string} string "ok"
// @Failure 500 {string} string "Internal Server Error"
// @Router /publish [post]
func (a *api) publish(g *gin.Context) {
args, err := a.readArgs(g)
if err != nil {
a.abort500(g, err)
return
}

if len(args) == 0 {
g.String(http.StatusBadRequest, "missing topic")
return
}

payload, err := ioutil.ReadAll(g.Request.Body)
if err != nil {
g.String(http.StatusBadRequest, err.Error())
return
}

err = a.node.Publish(payload, args[0])
if err != nil {
a.abort500(g, err)
return
}

g.Status(http.StatusNoContent)
}
8 changes: 4 additions & 4 deletions core/cafe_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1576,8 +1576,8 @@ func (h *CafeService) handleRequests(reqs []*pb.CafeRequest, rtype pb.CafeReques
if err != nil {
log.Errorf("cafe %s request to %s failed: %s", rtype.String(), cafeId, err)
herr = err
for _, req := range reqs {
failed = append(failed, req.Target)
for _, r := range reqs {
failed = append(failed, r.Id)
}
}

Expand All @@ -1598,8 +1598,8 @@ func (h *CafeService) handleRequests(reqs []*pb.CafeRequest, rtype pb.CafeReques
if err != nil {
log.Errorf("cafe %s request to %s failed: %s", rtype.String(), cafeId, err)
herr = err
for _, req := range reqs {
failed = append(failed, req.Target)
for _, r := range reqs {
failed = append(failed, r.Id)
}
}

Expand Down
6 changes: 2 additions & 4 deletions core/cafes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

icid "github.com/ipfs/go-cid"
peerstore "github.com/libp2p/go-libp2p-core/peerstore"
"github.com/libp2p/go-libp2p-core/peerstore"
"github.com/segmentio/ksuid"
"github.com/textileio/go-textile/ipfs"
"github.com/textileio/go-textile/pb"
Expand Down Expand Up @@ -102,12 +102,10 @@ func TestCore_RegisterCafe(t *testing.T) {
t.Fatal(err)
}

// because local discovery almost _always_ fails initially, a backoff is
// set and we fail to register until it's removed... this cheats around that.
// register with cafe
cafeID := cafeVars.cafe.Ipfs().Identity
cafeVars.node.Ipfs().Peerstore.AddAddrs(
cafeID, cafeVars.cafe.Ipfs().PeerHost.Addrs(), peerstore.PermanentAddrTTL)

_, err = cafeVars.node.RegisterCafe(cafeID.Pretty(), token)
if err != nil {
t.Fatalf("register node1 w/ node2 failed: %s", err)
Expand Down
17 changes: 16 additions & 1 deletion core/main.go → core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (
"github.com/ipfs/go-ipfs/repo/fsrepo"
ipld "github.com/ipfs/go-ipld-format"
logging "github.com/ipfs/go-log"
peer "github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/peerstore"
"github.com/textileio/go-textile/broadcast"
"github.com/textileio/go-textile/ipfs"
"github.com/textileio/go-textile/keypair"
Expand Down Expand Up @@ -376,6 +377,15 @@ func (t *Textile) Start() error {
}
log.Info("node is online")

// ensure the peer table is not empty by adding our bootstraps
boots, err := config.TextileBootstrapPeers()
if err != nil {
log.Errorf(err.Error())
}
for _, p := range boots {
t.node.Peerstore.AddAddrs(p.ID, p.Addrs, peerstore.PermanentAddrTTL)
}

go t.cafeOutbox.Flush()
}()

Expand Down Expand Up @@ -505,6 +515,11 @@ func (t *Textile) Ping(pid peer.ID) (service.PeerStatus, error) {
return t.cafe.Ping(pid)
}

// Publish sends 'data' to 'topic'
func (t *Textile) Publish(payload []byte, topic string) error {
return ipfs.Publish(t.node, topic, payload)
}

// UpdateCh returns the account update channel
func (t *Textile) UpdateCh() <-chan *pb.AccountUpdate {
return t.updates
Expand Down
1 change: 1 addition & 0 deletions core/main_test.go → core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func TestSetLogLevel(t *testing.T) {
logLevel := &pb.LogLevel{Systems: map[string]pb.LogLevel_Level{
"tex-core": pb.LogLevel_DEBUG,
"tex-datastore": pb.LogLevel_INFO,
"tex-service": pb.LogLevel_DEBUG,
}}
if err := vars.node.SetLogLevel(logLevel); err != nil {
t.Fatalf("set log levels failed: %s", err)
Expand Down
File renamed without changes.
52 changes: 49 additions & 3 deletions docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2019-07-05 03:14:13.257773 +0800 +08 m=+81.786058338
// 2019-07-23 16:13:30.86042 -0700 PDT m=+0.239072254

package docs

import (
"bytes"
"encoding/json"

"github.com/alecthomas/template"
"github.com/swaggo/swag"
)

var doc = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "Textile's HTTP REST API Documentation",
Expand Down Expand Up @@ -2198,6 +2200,44 @@ var doc = `{
}
}
},
"/publish": {
"post": {
"description": "Publishes payload bytes to a topic on the network.",
"consumes": [
"application/octet-stream"
],
"produces": [
"text/plain"
],
"tags": [
"utils"
],
"summary": "Publish payload to topic",
"parameters": [
{
"type": "string",
"description": "topic",
"name": "X-Textile-Args",
"in": "header",
"required": true
}
],
"responses": {
"204": {
"description": "ok",
"schema": {
"type": "string"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "string"
}
}
}
}
},
"/snapshots": {
"post": {
"description": "Snapshots all threads and pushes to registered cafes",
Expand Down Expand Up @@ -3624,17 +3664,23 @@ type swaggerInfo struct {
Version string
Host string
BasePath string
Schemes []string
Title string
Description string
}

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo swaggerInfo
var SwaggerInfo = swaggerInfo{ Schemes: []string{}}

type s struct{}

func (s *s) ReadDoc() string {
t, err := template.New("swagger_info").Parse(doc)
t, err := template.New("swagger_info").Funcs(template.FuncMap{
"marshal": func(v interface {}) string {
a, _ := json.Marshal(v)
return string(a)
},
}).Parse(doc)
if err != nil {
return doc
}
Expand Down
Loading

0 comments on commit 0a9eb98

Please sign in to comment.