Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pylons-grpc-relay/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/

# Go workspace file
go.work

# IDE specific files
.idea/
.vscode/
*.swp
*.swo

# OS specific files
.DS_Store
Thumbs.db

# Log files
*.log
123 changes: 123 additions & 0 deletions pylons-grpc-relay/INCIDENT_REPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# gRPC Communication Issue: Flutter Mobile App to Pylons Node

## Current Situation

### 1. The Problem
Flutter app fails to communicate with Pylons node:
```
[ERROR] 2024-03-21T10:15:23Z /pylons.pylons.Query/ListItemByOwner
Status: 501 Not Implemented
Server: nginx/1.18.0
```

### 2. The Key Difference
**App sends (fails):**
```
{
"owner": "pylo1fhvaknqx2ngyltz2qzychlm75cyp4tkh09d539",
"pagination": {
"key": "",
"offset": "0",
"limit": "10",
"count_total": true
}
}
```

**Node expects (works):**
```
{
"type_url": "type.googleapis.com/pylons.pylons.QueryListItemByOwnerRequest",
"value": "Cg5weWxvMXNoZnZha25xeDJuZ3lsdHoycXp5Y2hsbTc1Y3lwNHRraDA5ZDUzOQ=="
}
```

The node requires all messages to be wrapped in an `Any` type with:
- `type_url`: Message type identifier
- `value`: Binary-encoded message data

### 3. Solution
Relay server that:
1. Receives raw messages
2. Wraps them in `Any` type
3. Forwards to node

Success response:
```
[REQUEST] 2024-03-21T10:20:15Z /pylons.pylons.Query/ListItemByOwner
[CONNECTED] Successfully connected
Response: {
"items": [{
"id": "item1",
"owner": "pylo1fhvaknqx2ngyltz2qzychlm75cyp4tkh09d539",
"cookbook_id": "cookbook1",
"transferable": true
}]
}
```

### 4. Implementation & Testing
```bash
# Start relay with logging
go run relay.go pylons.api.m.stavr.tech:443 :50051 > relay.log 2>&1
```

Key files to modify in Dart code:
- `lib/modules/Pylonstech.pylons.pylons/module/client/pylons/query.pbgrpc.dart`
- `QueryClient` class needs message wrapping
- Methods: `listItemByOwner`, `listCookbooksByCreator`

Data Contract:
1. Request Format:
```
Input:
{
"owner": string,
"pagination": {
"key": bytes,
"offset": int64,
"limit": int64,
"count_total": bool
}
}

Expected Wrapped Format:
{
"type_url": "type.googleapis.com/pylons.pylons.QueryListItemByOwnerRequest",
"value": bytes // Binary encoded request
}
```

2. Response Format:
```
Expected Wrapped Format:
{
"type_url": "type.googleapis.com/pylons.pylons.QueryListItemByOwnerResponse",
"value": bytes // Binary encoded response
}

Unwrapped Response:
{
"items": [{
"id": string,
"owner": string,
"cookbook_id": string,
"transferable": bool
}],
"pagination": {
"next_key": bytes,
"total": string
}
}
```

Test flow:
1. Validate request wrapping matches contract
2. Start relay
3. Run app through relay
4. Verify message wrapping in logs
5. Check successful responses

## References
- [gRPC Documentation](https://grpc.io/docs/)
- [Pylons Node API](https://docs.pylons.tech)
42 changes: 42 additions & 0 deletions pylons-grpc-relay/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Pylons gRPC Relay Server

A relay server that handles message wrapping for the Pylons mobile app's gRPC communication.

## Purpose
The relay server acts as a man-in-the-middle to properly wrap messages in the `Any` type format required by the Pylons node. This fixes the HTTP 501 errors encountered by the mobile app.

## Usage
```bash
# Start the relay server
go run relay.go pylons.api.m.stavr.tech:443 :50051

# Monitor the logs
tail -f grpc_relay.log
```

## Message Format
The relay server handles the conversion between:

1. Mobile App Format:
```json
{
"owner": "pylo1...",
"pagination": {
"key": "",
"offset": 0,
"limit": 10,
"count_total": true
}
}
```

2. Node Expected Format:
```json
{
"type_url": "type.googleapis.com/pylons.pylons.QueryListItemByOwnerRequest",
"value": "base64_encoded_data"
}
```

## Testing
See [INCIDENT_REPORT.md](INCIDENT_REPORT.md) for detailed testing procedures and data contracts.
12 changes: 12 additions & 0 deletions pylons-grpc-relay/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module pylons-relay

go 1.23.3

require (
golang.org/x/net v0.35.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a // indirect
google.golang.org/grpc v1.72.0 // indirect
google.golang.org/protobuf v1.36.5 // indirect
)
12 changes: 12 additions & 0 deletions pylons-grpc-relay/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a h1:51aaUVRocpvUOSQKM6Q7VuoaktNIaMCLuhZB6DKksq4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a/go.mod h1:uRxBH1mhmO8PGhU89cMcHaXKZqO+OfakD8QQO0oYwlQ=
google.golang.org/grpc v1.72.0 h1:S7UkcVa60b5AAQTaO6ZKamFp1zMZSU0fGDK2WZLbBnM=
google.golang.org/grpc v1.72.0/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM=
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
Loading
Loading