Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/skychat: basic p2p and group chat implementation #1494

Merged
merged 86 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
f2f626a
add skychat rework ; begin to fix make format check errors
0pcom Aug 3, 2022
203bbc7
fix some make check errors
0pcom Aug 5, 2022
d7d3a49
merge devlop & fix merge conflicts
0pcom Sep 10, 2022
4ef2041
Merge branch 'develop' into feature/skychat
ersonp Oct 26, 2022
298a4cd
Fix linting and naming in package notification
ersonp Oct 27, 2022
235fdd2
comment unused server package
ersonp Oct 27, 2022
650a2f9
Fix Fprint linting
ersonp Oct 27, 2022
d9008ee
Fix return error lint and add todo
ersonp Oct 27, 2022
3f17561
Fix error check linting in New() of ClientRepo
ersonp Oct 27, 2022
4fc1228
Fix Global comments in package memory
ersonp Oct 27, 2022
8a7efab
Minor fix
ersonp Oct 27, 2022
756606e
Fix spelling of method IsEmtpy of Client
ersonp Oct 27, 2022
7471179
Cleanup package memory
ersonp Oct 27, 2022
be79122
Remove unnecessary print line
ersonp Oct 27, 2022
77dddba
Add package-comments and fix global comments
ersonp Oct 27, 2022
278aa43
Minor fix
ersonp Oct 27, 2022
59867a9
Fix linting in cli commands
ersonp Oct 27, 2022
032718d
Fix linting in cli visor tp
ersonp Oct 27, 2022
1ed4a52
Fixed and added comments in message package of domain
ersonp Oct 27, 2022
4795c35
Minor Fix
ersonp Oct 27, 2022
04f96d5
Fix linting
ersonp Oct 27, 2022
c36b4cb
Minor update
ersonp Oct 27, 2022
1cfd253
handle some errors in a temporary fashion
0pcom Nov 6, 2022
2cb3022
commit
4rchim3d3s Dec 16, 2022
6b3aae6
Merge remote-tracking branch 'origin/develop' into feature/skychat
4rchim3d3s Dec 16, 2022
82953dd
commit
4rchim3d3s Jan 31, 2023
8d82fc9
Merge branch 'develop' into feature/skychat
4rchim3d3s Jan 31, 2023
ae4488f
commit
4rchim3d3s Feb 5, 2023
5320454
Merge branch 'feature/skychat' of https://github.com/skycoin/skywire …
4rchim3d3s Feb 5, 2023
b39897f
Merge branch 'develop' into feature/skychat
4rchim3d3s Feb 5, 2023
d4abfa4
small changes
4rchim3d3s Feb 13, 2023
4289624
Merge branch 'develop' into feature/skychat
4rchim3d3s Feb 13, 2023
6448efe
Merge branch 'develop' into feature/skychat
4rchim3d3s Feb 18, 2023
474ae35
next commit
4rchim3d3s Feb 18, 2023
ffc2be5
[backend] add un/mute peer functionality
4rchim3d3s Feb 18, 2023
81a56dc
fix check-windows output
4rchim3d3s Feb 19, 2023
5171600
Merge remote-tracking branch 'origin/develop' into feature/skychat
4rchim3d3s Mar 26, 2023
330eda7
fix build path in windows
4rchim3d3s Mar 30, 2023
3a8edc8
fix to stop hangups
4rchim3d3s Mar 30, 2023
fc02d3a
export User attributes
4rchim3d3s Apr 1, 2023
86c8d37
remove unused exported Interface function
4rchim3d3s Apr 1, 2023
846c075
add boltdb for user repository
4rchim3d3s Apr 2, 2023
40ed125
add RejectMessage to P2P
4rchim3d3s Apr 2, 2023
9c9052d
fix make-check errs
4rchim3d3s Apr 6, 2023
1128393
turn function call into go routine
4rchim3d3s Apr 17, 2023
373b37b
fix darwin make format errs
4rchim3d3s Apr 20, 2023
53e00c8
add usecases to hire and fire moderator
4rchim3d3s Apr 20, 2023
281535a
add cli functionality
4rchim3d3s Apr 20, 2023
496b958
improve cli functionality with rpc
4rchim3d3s Apr 22, 2023
9d26591
fix make-check errs
4rchim3d3s Apr 22, 2023
96f7183
small rpc fix
4rchim3d3s Apr 30, 2023
341b4a0
fix sending large info
4rchim3d3s Apr 30, 2023
35e12c4
fix make-check errs
4rchim3d3s May 1, 2023
97ddb71
visor repository with boltdb
4rchim3d3s Jun 6, 2023
46398bc
relocate todos
4rchim3d3s Jun 6, 2023
c833286
first refactoring for more readability
4rchim3d3s Jun 6, 2023
81bb6a0
refactoring for better readability
4rchim3d3s Jun 10, 2023
fab723e
Merge remote-tracking branch 'upstream/develop' into feature/skychat
4rchim3d3s Jun 10, 2023
a314f05
refactor delete to only delete local instances of chats and groups
4rchim3d3s Jun 20, 2023
542f28f
refactoring for better readability
4rchim3d3s Jun 20, 2023
da85a39
Merge remote-tracking branch 'upstream/develop' into feature/skychat
4rchim3d3s Jun 20, 2023
7d2fb40
further refactoring and bufixing
4rchim3d3s Jul 5, 2023
1f75d5d
fix make check errs
4rchim3d3s Jul 5, 2023
edadf7e
fix make check errs
4rchim3d3s Jul 26, 2023
ad5892e
fix make check errs
4rchim3d3s Jul 31, 2023
c47fc26
Merge remote-tracking branch 'upstream/develop' into feature/skychat
4rchim3d3s Aug 29, 2023
6b92e52
fix ipc client naming
4rchim3d3s Aug 30, 2023
026efb6
fix build path for autodetection of config gen
4rchim3d3s Aug 30, 2023
1f2f1a3
fix skychat default flag
4rchim3d3s Aug 30, 2023
70a2c8c
add dependencies for skychat
4rchim3d3s Aug 30, 2023
e8d9810
fix skywire.conf for latest commits
4rchim3d3s Aug 30, 2023
73c40a0
fix build path in Readme
4rchim3d3s Aug 30, 2023
bdf0453
Add new Skychat Readme [WIP]
4rchim3d3s Aug 31, 2023
828a5f6
first try to implement plantuml rendering into skychat readme
4rchim3d3s Aug 31, 2023
356d2f1
skychat: next try rendering plantuml inside readme
4rchim3d3s Aug 31, 2023
e176874
skychat: fix file ending for plantuml rendering inside readme
4rchim3d3s Aug 31, 2023
1bf62e4
Merge branch 'develop' into feature/skychat
4rchim3d3s Feb 3, 2024
1080855
websockets for notifications & refactoring for future implementation …
4rchim3d3s Mar 11, 2024
f22f09a
Update go mod
4rchim3d3s Mar 11, 2024
0d651b5
Merge branch 'develop' into feature/skychat
4rchim3d3s Mar 11, 2024
5ff6f78
fix cli skychat banner, and merge problem
4rchim3d3s Mar 11, 2024
4d09f46
change .db files in gitignore
4rchim3d3s Mar 11, 2024
97d125d
fix import link for skychat in skywire
4rchim3d3s Mar 11, 2024
473d40b
export skychat RootCmd for cobra
4rchim3d3s Mar 11, 2024
e7fe942
fix skychat import link in skywire-deployment
4rchim3d3s Mar 11, 2024
dadd325
move cli out of internal and fix imports
4rchim3d3s Mar 12, 2024
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pkg/visor/foo/

/bin
/node
/users.db
/*.db
/hypervisor
/*-node
/*-visor
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,12 @@ example-apps: ## Build example apps
${OPTS} go build ${BUILD_OPTS} -o $(BUILD_PATH)apps/ ./example/...

host-apps-windows: ## build apps on windows
powershell -Command new-item $(BUILD_PATH)apps -itemtype directory -force
powershell 'Get-ChildItem .\cmd\apps | % { ${OPTS} go build ${BUILD_OPTS} -o $(BUILD_PATH)apps $$_.FullName }'
powershell -Command new-item $(BUILD_PATH)apps/ -itemtype directory -force
powershell 'Get-ChildItem .\cmd\apps | % { ${OPTS} go build ${BUILD_OPTS} -o $(BUILD_PATH)apps/ $$_.FullName }'

host-apps-windows-appveyor: ## build apps on windows. `go build` with ${OPTS} for AppVeyor image
powershell -Command new-item $(BUILD_PATH)apps/ -itemtype directory -force
powershell 'Get-ChildItem .\cmd\apps | % { ${OPTS} go build -o $(BUILD_PATH)apps/ $$_.FullName }'

# Static Apps
host-apps-static: ## Build app
Expand Down
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,29 @@ git checkout develop
make build1
```

To compile skywire directly from source archive, first download the latest source archive from the release section with your browser or another utility. Extract it with an archiving utility, enter the directory where the sources were extracted, and run `make build1`.
To compile skywire directly from source archive, first download the latest source archive from the release section with your browser or another utility. Extract it with an archiving utility, enter the directory where the sources were extracted, and run `make build`.


`make build1` builds the binaries and apps with `go build`
`make build` builds the binaries and apps with `go build`

`skywire-cli` and `skywire-visor` binaries will populate in the current directory; app binaries will populate the `apps` directory.
`skywire-cli` and `skywire-visor` binaries will populate in the `build` directory; app binaries will populate the `build\apps` directory.

Build output:

```
├──skywire-cli
└─┬skywire-visor
└─┬apps
├──skychat
├──skysocks
├──skysocks-client
├──vpn-client
├──vpn-server
└──skychat
build
└─┬──setup-node
├──skywire-cli
├──skywire-systray
├──skywire-visor
└─┬skywire
└─┬apps
├──skychat
├──skysocks
├──skysocks-client
├──vpn-client
├──vpn-server
└──skychat
```

'install' these executables to the `GOPATH`:
Expand All @@ -153,7 +157,7 @@ For more options, run `make help`.
To run skywire from this point, first generate a config.

```
./skywire-cli config gen -birx
./build/skywire-cli config gen -birx
```
`-b --bestproto` use the best protocol (dmsg | direct) to connect to the skywire production deployment
`-i --ishv` create a local hypervisor configuration
Expand Down
93 changes: 47 additions & 46 deletions cmd/apps/skychat/README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
# Skywire Chat app
# Skywire Chat App

Chat implements basic text messaging between skywire visors.

It is possible to send messages p2p or in groups.

The group feature is structured in a way that it is possible for everyone to host and join multiple servers.

Those servers are structured like that:

- Public Key of Visor
- Public Key of Server 1
- Public Key of Room 1.1
- Public Key of Room 1.2
- ...
- Public Key of Server 2
- Public Key of Room 2.1
- Public Key of Room 2.2

And the chats are adressed with a so called public key route (pkroute):
- Route to a Room = [PK of Visor, PK of Server, PK of Room]
- P2P Route = [PK of Visor, PK of Visor, PK of Visor]


Messaging UI is exposed via web interface.

Chat only supports one WEB client user at a time.

## Local setup

Create 2 visor config files:

`skywire1.json`

```json
{
"apps": [
{
"app": "skychat",
"version": "1.0",
"auto_start": true,
"port": 1
}
]
}
```

`skywire2.json`

```json
{
"apps": [
{
"app": "skychat",
"version": "1.0",
"auto_start": true,
"port": 1,
"args": ["-addr", ":8002"]
}
]
}
```

Compile binaries and start 2 visors:

```bash
$ go build -o ./build/apps/skychat.v1.0 ./cmd/apps/skychat
$ cd ./build
$ ./skywire-visor skywire1.json
$ ./skywire-visor skywire2.json
```

Chat interface will be available on ports `8001` and `8002`.

# Development Info
The app is written with 'Clean Architecture' based on the blog entry of Panayiotis Kritiotis [Clean Architecture in Go](https://pkritiotis.io/clean-architecture-in-golang/)

To get a basic understanding on how it is structured, reading the blog will help.

## Sequence Diagrams
### Init
![Init](http://plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/4rchim3d3s/skywire-mainnet/feature/skychat/cmd/apps/skychat/doc/init.iuml)

### MessengerService.Listen
![MessengerService.Listen](http://plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/4rchim3d3s/skywire-mainnet/feature/skychat/cmd/apps/skychat/doc/messengerServiceListen.iuml)

### MessengerService.Handle
![Init](http://plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/4rchim3d3s/skywire-mainnet/feature/skychat/cmd/apps/skychat/doc/messengerServiceHandle.iuml)

### MessengerService.handleP2PMessage
![Init](http://plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/4rchim3d3s/skywire-mainnet/feature/skychat/cmd/apps/skychat/doc/messengerServiceHandleP2PMessage.iuml)

### MessengerService.handleRemoteServerMessage (This is the client-side handling of servers)
TODO
### MessengerService.handleLocalServerMessage (This is the server-side handling of servers)
TODO

### Usecases
TODO
18 changes: 18 additions & 0 deletions cmd/apps/skychat/cli/chat/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Package clichat contains code for chat command of cli inputports
package clichat

import (
"github.com/spf13/cobra"

clichatsend "github.com/skycoin/skywire/cmd/apps/skychat/cli/chat/send"
)

// RootCmd is the sub-command so interact with the chats
var RootCmd = &cobra.Command{
Use: "chat",
Short: "Send messages or query a chat",
}

func init() {
RootCmd.AddCommand(clichatsend.SendCmd)
}
14 changes: 14 additions & 0 deletions cmd/apps/skychat/cli/chat/send/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Package clichatsend contains code of the cobra cli chat send commands
package clichatsend

import "github.com/spf13/cobra"

// SendCmd is the sub-command to send messages
var SendCmd = &cobra.Command{
Use: "send",
Short: "Send messages",
}

func init() {
SendCmd.AddCommand(textMessageCmd)
}
43 changes: 43 additions & 0 deletions cmd/apps/skychat/cli/chat/send/textmessage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package clichatsend

import (
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire/cmd/apps/skychat/internal/inputports"
)

var textMessageCmd = &cobra.Command{
Use: "text <vpk> <spk> <rpk> <msg>",
Short: "Send text message",
Args: cobra.MinimumNArgs(4),
Run: func(cmd *cobra.Command, args []string) {
vpk := ParsePK(cmd.Flags(), "vpk", args[0])
spk := ParsePK(cmd.Flags(), "spk", args[1])
rpk := ParsePK(cmd.Flags(), "rpk", args[2])
msg := args[3]

fmt.Println("SendTextMessage via cli (cli)")
fmt.Println(msg)
fmt.Printf("to v: %s s: %s, r %s\n", vpk.Hex(), spk.Hex(), rpk.Hex())

err := inputports.InputportsServices.RPCClient.SendTextMessage(vpk, spk, rpk, msg)
if err != nil {
fmt.Println(err)
}
},
}

// ParsePK parses a public key
func ParsePK(_ *pflag.FlagSet, _, v string) cipher.PubKey {
var pk cipher.PubKey
err := pk.Set(v)
if err != nil {
//PrintFatalError(cmdFlags, fmt.Errorf("failed to parse <%s>: %v", name, err))
fmt.Printf("Error")
}
return pk
}
109 changes: 109 additions & 0 deletions cmd/apps/skychat/cli/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Package cli contains code for the cli service of inputports
package cli

import (
"fmt"
"log"

cc "github.com/ivanpirog/coloredcobra"
"github.com/spf13/cobra"

"github.com/skycoin/skywire-utilities/pkg/buildinfo"

clichat "github.com/skycoin/skywire/cmd/apps/skychat/cli/chat"
"github.com/skycoin/skywire/cmd/apps/skychat/internal/app"
"github.com/skycoin/skywire/cmd/apps/skychat/internal/inputports"
"github.com/skycoin/skywire/cmd/apps/skychat/internal/interfaceadapters"
)

var httpport string
var rpcport string

// RootCmd is the root command for skychat
var RootCmd = &cobra.Command{
Use: "skychat",
Short: "skywire chat application",
Long: `
┌─┐┬┌─┬ ┬┌─┐┬ ┬┌─┐┌┬┐
└─┐├┴┐└┬┘│ ├─┤├─┤ │
└─┘┴ ┴ ┴ └─┘┴ ┴┴ ┴ ┴ `,
SilenceErrors: true,
SilenceUsage: true,
DisableSuggestions: true,
DisableFlagsInUseLine: true,
Version: buildinfo.Version(),
Run: func(cmd *cobra.Command, args []string) {

//TODO: Setup Databases depending on flags/attributes

interfaceadapters.InterfaceAdapterServices = interfaceadapters.NewServices()
defer func() {
err := interfaceadapters.InterfaceAdapterServices.Close()
if err != nil {
fmt.Println(err.Error())
}
}()

app.AppServices = app.NewServices(
interfaceadapters.InterfaceAdapterServices.UserRepository,
interfaceadapters.InterfaceAdapterServices.VisorRepository,
interfaceadapters.InterfaceAdapterServices.NotificationService,
interfaceadapters.InterfaceAdapterServices.MessengerService)

inputports.InputportsServices = inputports.NewServices(app.AppServices, httpport, rpcport)

//connectionHandlerService listen
go interfaceadapters.InterfaceAdapterServices.ConnectionHandlerService.Listen()

//rpc-server for cli functionality
go inputports.InputportsServices.RPCServer.ListenAndServe()

//http-server for web-ui
inputports.InputportsServices.HTTPServer.ListenAndServe()
},
}

func init() {
RootCmd.AddCommand(
clichat.RootCmd,
)
var helpflag bool
RootCmd.SetUsageTemplate(help)
RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for "+RootCmd.Use)
RootCmd.SetHelpCommand(&cobra.Command{Hidden: true})
RootCmd.PersistentFlags().MarkHidden("help") //nolint

RootCmd.Flags().StringVar(&httpport, "httpport", ":8001", "port to bind")
RootCmd.Flags().StringVar(&rpcport, "rpcport", ":4040", "port to bind")
}

// Execute executes root CLI command.
func Execute() {
cc.Init(&cc.Config{
RootCmd: RootCmd,
Headings: cc.HiBlue + cc.Bold, //+ cc.Underline,
Commands: cc.HiBlue + cc.Bold,
CmdShortDescr: cc.HiBlue,
Example: cc.HiBlue + cc.Italic,
ExecName: cc.HiBlue + cc.Bold,
Flags: cc.HiBlue + cc.Bold,
//FlagsDataType: cc.HiBlue,
FlagsDescr: cc.HiBlue,
NoExtraNewlines: true,
NoBottomNewline: true,
})

if err := RootCmd.Execute(); err != nil {
log.Fatal("Failed to execute command: ", err)
}
}

const help = "Usage:\r\n" +
" {{.UseLine}}{{if .HasAvailableSubCommands}}{{end}} {{if gt (len .Aliases) 0}}\r\n\r\n" +
"{{.NameAndAliases}}{{end}}{{if .HasAvailableSubCommands}}\r\n\r\n" +
"Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand)}}\r\n " +
"{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}\r\n\r\n" +
"Flags:\r\n" +
"{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}\r\n\r\n" +
"Global Flags:\r\n" +
"{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}\r\n\r\n"
Loading
Loading