All Projects → ailabstw → go-pttai

ailabstw / go-pttai

Licence: LGPL-3.0 license
⛔️ [DEPRECATED] Current development in https://github.com/ailabstw/pttai-next

Programming Languages

go
31211 projects - #10 most used programming language
NSIS
403 projects
shell
77523 projects
javascript
184084 projects - #8 most used programming language
Makefile
30231 projects
python
139335 projects - #7 most used programming language

This repository is deprecated. Current development happen in PTT.ai-next.

gptt

Official golang implementation of the PTT.ai Framework.

API Reference Travis

The architecture of PTT.ai can be found in the link (中文版)

More documents can be found in PIPs

Install

go get github.com/ailabstw/go-pttai
go install github.com/ailabstw/go-pttai/cmd/gptt
${GOPATH}/bin/gptt

License

All License can be found in docs/

Docker Environment

./scripts/docker_build.sh
./scripts/docker.sh
./scripts/docker_stop.sh
./scripts/docker_push.sh

Docker with customized storage / ports

./scripts/docker_with_storage.sh -p [http-port in local-machine] -a [api-port in local-machine] -q [p2p-port in local-machine] -e [optional external http/https addr] -b [optional external api addr] -s [dir]

Unit-Test

make test

Testing for specific dir:

./scripts/test.sh [dir]
(ex: ./scripts/test.sh common)

E2E-Test

Testing for specific e2e-test

./scripts/e2e.sh [any test in the e2e dir]

ex: ./scripts/e2e.sh friend_basic

Running Godoc

./scripts/doc.sh

Development

The code-structure is based on go-ethereum. The following is the general guide for the development.

go get github.com/ailabstw/go-pttai; cd ${GOPATH}/src/github.com/ailabstw/go-pttai; ./scripts/init_cookiecutter.sh; source __/bin/activate

./scripts/gptt-testnet.sh
  • follow gofmt / goimports
  • follow gotests
  • coding style (in-general):
    1. Each struct file (generated from ./scripts/dev_struct.sh) represents 1 struct
    2. Each module file (generated from ./scripts/dev_module.sh) represents 1 public function
    3. Struct is always CapitalizedCamelCase
    4. Public constants / variables / functions / member variables / member functions are CapitalizedCamelCase
    5. local constants / variables / functions / member variables / member functions are lowerCamelCase
    6. Global variables are in globals.go
    7. Global test variables are in globals_test.go
    8. Errors are in errors.go
  • Naming:
    • Full name: PTTai, pttai, PTT.ai
    • cmd: gptt, Gptt (go-ptt)
  • Default ports:
    • http-connection: 9774
    • api-connection: 14779
    • p2p-connection: 9487

SSH Tunnel

  1. ssh -L [rpcport-for-localhost]:localhost:[rpcport-for-remote-host] [username]@[remote-host]
  2. ssh -L [httpport-for-localhost]:localhost:[httpport-for-remote-host] [username]@[remote-host]
  3. ./build/bin/gptt --testwebrtc --rpcport [port-for-remote-host] --httpaddr 127.0.0.1:[http-port] --exthttpaddr http://localhost:[httpport-for-localhost] --extrpcaddr http://localhost:[rpcport-for-localhost]
  4. (in browser) http://localhost:[httpport-for-localhost]

Linode

  1. Create Linode with Stackscript ID: 399252 (hsiaochuanheng / p.me-docker (go-pttai))

  2. Launch the console and ensure that the new linode is created successfully.

  3. ssh -L 14779:localhost:14779 admin@[IP]

  4. ssh -L 9774:localhost:9774 admin@[IP]

  5. open browser and connect to http://localhost:9774

  6. Update (in admin@[IP]):

    sudo -s
    docker pull ailabstw/go-pttai:latest
    HTTPPORT=9774
    APIPORT=14779
    docker run -e HTTPPORT=${HTTPPORT} -e APIPORT=${APIPORT} -itd --restart=always -p 9487:9487 -p 127.0.0.1:9774:9774 -p 127.0.0.1:14779:14779 -v /home/admin/pttai.docker:/root/.pttai --name go-pttai ailabstw/go-pttai:latest gptt "--testwebrtc" "--httpdir" "/static" "--httpaddr" "0.0.0.0:9774" "--rpcaddr" "0.0.0.0" "--exthttpaddr" "http://localhost:${HTTPPORT}" "--extrpcaddr" "http://localhost:${APIPORT}"
    

Digital Ocean

  1. Create docker-with-ubuntu in One-click Applications.

  2. Install / Update (in root@[IP]):

    sudo -s
    docker pull ailabstw/go-pttai:latest
    HTTPPORT=9774
    APIPORT=14779
    docker run -e HTTPPORT=${HTTPPORT} -e APIPORT=${APIPORT} -itd --restart=always -p 9487:9487 -p 127.0.0.1:9774:9774 -p 127.0.0.1:14779:14779 -v /home/admin/pttai.docker:/root/.pttai --name go-pttai ailabstw/go-pttai:latest gptt "--testwebrtc" "--httpdir" "/static" "--httpaddr" "0.0.0.0:9774" "--rpcaddr" "0.0.0.0" "--exthttpaddr" "http://localhost:${HTTPPORT}" "--extrpcaddr" "http://localhost:${APIPORT}"
    
  3. ssh -L 14779:localhost:14779 root@[IP]

  4. ssh -L 9774:localhost:9774 root@[IP]

  5. open browser and connect to http://localhost:9774

AWS

  1. Setup Key Pair in AWS ec2 console. (for SSH use)

  2. Setup Security Group in AWS ec2 console

    • Be sure to have port 22, 9487, 9774, 14779 open to 0.0.0.0/0
  3. Create an ECS cluster with the correpsonding Key Pair and Security Group.

  4. Install / Update (in ec2-user@[IP]):

    sudo -s
    docker pull ailabstw/go-pttai:latest
    HTTPPORT=9774
    APIPORT=14779
    docker run -e HTTPPORT=${HTTPPORT} -e APIPORT=${APIPORT} -itd --restart=always -p 9487:9487 -p 127.0.0.1:9774:9774 -p 127.0.0.1:14779:14779 -v /home/admin/pttai.docker:/root/.pttai --name go-pttai ailabstw/go-pttai:latest gptt "--testwebrtc" "--httpdir" "/static" "--httpaddr" "0.0.0.0:9774" "--rpcaddr" "0.0.0.0" "--exthttpaddr" "http://localhost:${HTTPPORT}" "--extrpcaddr" "http://localhost:${APIPORT}"
    
  5. ssh -L 14779:localhost:14779 ec2-user@[IP]

  6. ssh -L 9774:localhost:9774 ec2-user@[IP]

  7. open browser and connect to http://localhost:9774

AWS Elastic Beanstalk (On-click deploy)

  1. Setup Key Pair in AWS ec2 console. (for SSH use)

    Please remeber where you save the private key in your computer, you will need it at the last step.

  2. Click this link

    This will deploy the pre-build p.me docker image for you

  3. Click choice option Upload your code

    (Note: the code is already uploaded for you, you only have to click this option. This seems to be a bug of AWS.)

  1. Click button Review and Launch

  2. Click Modify in the Security section

  3. Chose the key pair you just setup in EC2 key pair,then Save

  4. Click button Create app

  5. ssh -L 14779:localhost:14779 ec2-user@[IP]

  6. ssh -L 9774:localhost:9774 ec2-user@[IP]

  7. open browser and connect to http://localhost:9774

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].