Skip to content

Commit

Permalink
Init ui
Browse files Browse the repository at this point in the history
jorbush committed Jun 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 884dcaf commit 629e9c0
Showing 11 changed files with 801 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.torrent
*.iso
logs/*
.DS_Store
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
.PHONY: install run clean-logs debian-test linter
.PHONY: install start-cli start-ui clean-logs debian-test linter

install:
go mod tidy

run:
start-cli:
go run *.go input/*.torrent

start-ui:
go run main.go -ui

clean-logs:
rm -rf logs
mkdir logs
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,25 @@ A BitTorrent client implementation in Go, designed to download files efficiently

- [Go](https://golang.org/doc/install)

## Usage
## Installation

Run the following command to install the project dependencies:

```bash
make install
```

## Usage APP UI

### Run the App

Run the client using the make command:

```bash
make start-ui
```

## Usage CLI

### Download a Torrent File

@@ -15,11 +33,12 @@ Download a torrent file, for example, the Debian installation image:
```bash
curl -o input/debian.torrent https://cdimage.debian.org/debian-cd/current/amd64/bt-cd/debian-12.5.0-amd64-netinst.iso.torrent
```
### Run the Client
### Run CLI

Run the client using the make command:

```bash
make run
make start-cli
```

This command will start the BitTorrent client, which will download the content of the torrent file saved in the `input` directory. For example, the Debian image.
4 changes: 2 additions & 2 deletions bittorrent/core/client.go
Original file line number Diff line number Diff line change
@@ -3,10 +3,10 @@ package core
import (
"bytes"
"fmt"
"gotorrent/bittorrent/network"
"gotorrent/bittorrent/utils"
"log"
"net"
"p2p/bittorrent/network"
"p2p/bittorrent/utils"
"time"
)

4 changes: 2 additions & 2 deletions bittorrent/core/p2p.go
Original file line number Diff line number Diff line change
@@ -4,9 +4,9 @@ import (
"bytes"
"crypto/sha1"
"fmt"
"gotorrent/bittorrent/network"
"gotorrent/ui"
"log"
"p2p/bittorrent/network"
"p2p/ui"
"runtime"
"time"
)
2 changes: 1 addition & 1 deletion bittorrent/core/torrentfile.go
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@ import (
"crypto/rand"
"crypto/sha1"
"fmt"
"gotorrent/bittorrent/network"
"os"
"p2p/bittorrent/network"

"github.com/jackpal/bencode-go"
)
2 changes: 1 addition & 1 deletion bittorrent/core/tracker.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package core

import (
"gotorrent/bittorrent/network"
"log"
"net/http"
"net/url"
"p2p/bittorrent/network"
"strconv"
"time"

38 changes: 37 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
module p2p
module gotorrent

go 1.22.2

require github.com/jackpal/bencode-go v1.0.2

require (
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
)

require (
fyne.io/fyne/v2 v2.4.5
fyne.io/systray v1.10.1-0.20231115130155-104f5ef7839e // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fredbi/uri v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe // indirect
github.com/fyne-io/glfw-js v0.0.0-20220120001248-ee7290d23504 // indirect
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2 // indirect
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240306074159-ea2d69986ecb // indirect
github.com/go-text/render v0.1.0 // indirect
github.com/go-text/typesetting v0.1.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/tevino/abool v1.2.0 // indirect
github.com/yuin/goldmark v1.5.5 // indirect
golang.org/x/image v0.11.0 // indirect
golang.org/x/mobile v0.0.0-20230531173138-3c911d8e3eda // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect
)
668 changes: 668 additions & 0 deletions go.sum

Large diffs are not rendered by default.

Empty file removed logs/.gitkeep
Empty file.
66 changes: 62 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package main

import (
"flag"
"fmt"
"gotorrent/bittorrent/core"
"gotorrent/ui"
"log"
"os"
"p2p/bittorrent/core"
"p2p/ui"
"time"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
)

func main() {
inPath := os.Args[1]
useUI := flag.Bool("ui", false, "Use graphical user interface")
flag.Parse()

logFile, err := ui.SetupLogger()
if err != nil {
@@ -19,7 +27,57 @@ func main() {
}
defer logFile.Close()

tf, err := core.Open(inPath)
if *useUI {
startUI()
} else {
startCLI()
}
}

func startUI() {
myApp := app.New()
myWindow := myApp.NewWindow("GoTorrent")

label := widget.NewLabel("Drag and drop a torrent file or click to browse")
fileEntry := widget.NewEntry()
fileEntry.SetPlaceHolder("No file selected")

fileButton := widget.NewButton("Browse", func() {
fileDialog := dialog.NewFileOpen(func(reader fyne.URIReadCloser, err error) {
if err != nil {
log.Println("Failed to open file:", err)
return
}
if reader == nil {
log.Println("No file selected")
return
}
fileEntry.SetText(reader.URI().Path())
}, myWindow)
fileDialog.Show()
})

startButton := widget.NewButton("Start Download", func() {
filePath := fileEntry.Text
if filePath == "" {
log.Println("No file selected for download")
return
}
startDownload(filePath)
})

content := container.NewVBox(label, fileEntry, fileButton, startButton)
myWindow.SetContent(content)
myWindow.ShowAndRun()
}

func startCLI() {
inPath := os.Args[1]
startDownload(inPath)
}

func startDownload(filePath string) {
tf, err := core.Open(filePath)
if err != nil {
log.Fatal(err)
}

0 comments on commit 629e9c0

Please sign in to comment.