Skip to content

Commit

Permalink
Adapt toxencryptsave.go to the new toxencryptsave API.
Browse files Browse the repository at this point in the history
Also, removed xtox, because I have no idea what gopp is. Google doesn't
either. Someone can revive this HLAPI for Go someday, but for now it's
gone.
  • Loading branch information
iphydf committed Jan 22, 2018
1 parent de7063d commit 2c3b0bc
Show file tree
Hide file tree
Showing 25 changed files with 177 additions and 2,426 deletions.
105 changes: 39 additions & 66 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,71 +1,44 @@
language: go
compiler: clang
sudo: required

go:
- "1.4"
- "1.5"
- "1.6"
- "1.7"
addons:
apt:
sources:
- sourceline: 'ppa:chris-lea/libsodium'
packages:
- libclang-dev
- libopus-dev
- libsodium-dev
- libvpx-dev

compiler:
- gcc
- clang
go:
#- 1.4.x
#- 1.5.x
#- 1.6.x
#- 1.7.x
#- 1.8.x
#- 1.9.x
- master

install:
- sudo apt-get update
# installing libsodium, needed for toxcore
- git clone https://github.com/jedisct1/libsodium.git
- cd libsodium
- git checkout tags/1.0.3
- ./autogen.sh
- ./configure --prefix=/usr
- make -j3 > /dev/null
- sudo make install > /dev/null
- cd ..
# installing libopus, needed for audio encoding/decoding
- wget http://downloads.xiph.org/releases/opus/opus-1.1.tar.gz > /dev/null
- tar xzf opus-1.1.tar.gz > /dev/null
- cd opus-1.1
- ./configure
- make -j3 > /dev/null
- sudo make install > /dev/null
- cd ..
# installing vpx
- sudo apt-get install yasm
- git clone https://chromium.googlesource.com/webm/libvpx > /dev/null
- cd libvpx
- ./configure --enable-shared > /dev/null
- make -j3 >/dev/null
- sudo make install > /dev/null
- cd ..
# creating librarys' links and updating cache
- sudo ldconfig
- git clone https://github.com/irungentoo/toxcore.git toxcore
- cd toxcore
- autoreconf -i
- ./configure --prefix=/usr --disable-tests --disable-ntox
- make -j2
- sudo make install
- cd ..
- sudo ldconfig > /dev/null
- apt-cache search tox
- apt-cache search opus
- apt-cache search libvpx

script:
- pwd
- go get github.com/streamrail/concurrent-map
# - go get -v -x github.com/kitech/go-toxcore
# - go get -v -x github.com/kitech/go-toxcore/examples
- go install -v -x
- go build -v -x -o echobot ./examples/toxecho.go
- go test -v -covermode count -timeout 60m


notifications:
email: false

# irc:
# channels:
# - "chat.freenode.net#tox-dev"
# on_success: always
# on_failure: always
# Add libclang's lib directory to search path for Go.
- export CGO_LDFLAGS="-L`llvm-config --libdir`"
# Install toxcore.
- git clone https://github.com/TokTok/c-toxcore
- cd c-toxcore
- cmake .
- make -j2
- sudo make install
- cd ..
- sudo ldconfig > /dev/null
# Install Go packages.
- go get github.com/bitly/go-simplejson
- go get github.com/go-clang/v3.8/clang
- go get github.com/kitech/godsts/maps/hashbidimap
- go get github.com/kitech/godsts/maps/hashmap
- go get github.com/kitech/godsts/sets/hashset
- go get github.com/masatana/go-textdistance
- go get github.com/sasha-s/go-deadlock
- go get github.com/sysr-q/gopp/gopp
- go get github.com/xrash/smetrics
42 changes: 42 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = [
"c.go",
"const.go",
"const_auto.go",
"group.go",
"group_intern.c",
"group_intern.go",
"group_legacy.go",
"hooks.go",
"options.go",
"tox.go",
"toxav.go",
"toxencryptsave.go",
"userdata.go",
"userdata_legacy.go",
"utils.go",
"yuv2rgb.c",
],
cdeps = ["//c-toxcore"],
cgo = True,
copts = ["-g -O2 -std=c99 -Wall"],
importpath = "github.com/TokTok/go-toxcore-c",
visibility = ["//visibility:public"],
deps = [
"@com_github_sasha_s_go_deadlock//:go_default_library",
"@com_github_streamrail_concurrent_map//:go_default_library",
],
)

go_test(
name = "go_default_test",
srcs = [
"group_test.go",
"tox_test.go",
],
embed = [":go_default_library"],
importpath = "github.com/TokTok/go-toxcore-c",
)
6 changes: 4 additions & 2 deletions c.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package tox

/*
#cgo CFLAGS: -g -O2 -std=c99 -Wall
// #cgo LDFLAGS: -ltoxcore -ltoxdns -ltoxav -ltoxencryptsave -lvpx -lopus -lsodium -lm
#cgo pkg-config: libtoxcore libtoxav
// #cgo LDFLAGS: -ltoxcore -lvpx -lopus -lsodium -lm
#cgo pkg-config: toxcore
// Needed because toxcore declares -lvpx in its Libs.private:
#cgo LDFLAGS: -lvpx
// #cgo LDFLAGS: -L/home/gzleo/oss/toxcore/build/.libs/
*/
import "C"
Expand Down
16 changes: 16 additions & 0 deletions cmds/tsdec/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
name = "go_default_library",
srcs = ["tsdec.go"],
importpath = "github.com/TokTok/go-toxcore-c/cmds/tsdec",
visibility = ["//visibility:private"],
deps = ["//go-toxcore-c:go_default_library"],
)

go_binary(
name = "tsdec",
embed = [":go_default_library"],
importpath = "github.com/TokTok/go-toxcore-c/cmds/tsdec",
visibility = ["//visibility:public"],
)
15 changes: 7 additions & 8 deletions cmds/tsdec.go → cmds/tsdec/tsdec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"log"
"os"

"github.com/kitech/go-toxcore"
"github.com/TokTok/go-toxcore-c"
)

func init() {
Expand Down Expand Up @@ -60,13 +60,12 @@ func main() {
if err != nil {
log.Println(ok, err, len(salt), salt)
}
pkey := tox.NewToxPassKey()
ok, err = pkey.DeriveWithSalt([]byte(pass), salt)
pkey, err := tox.DeriveWithSalt([]byte(pass), salt)
defer pkey.Free()
if err != nil {
log.Println(ok, err)
log.Println(err)
}
ok, err, datad := pkey.Decrypt(data)
pkey.Free()
if err != nil {
// log.Println(ok, err, len(datad), datad[0:32])
log.Println("Decrypt error, check your -pass:", err)
Expand Down Expand Up @@ -105,7 +104,6 @@ func main() {
} else { // do encrypt
log.Println("Encrypting...")

pakey := tox.NewToxPassKey()
// first time, there is no salt
salt := make([]byte, tox.PASS_KEY_LENGTH)
_, err, salt := tox.GetSalt(data)
Expand All @@ -115,8 +113,9 @@ func main() {
}
_ = salt

// _, err = pakey.DeriveWithSalt([]byte(pass), salt)
_, err = pakey.Derive([]byte(pass))
// pakey, err = tox.DeriveWithSalt([]byte(pass), salt)
pakey, err := tox.Derive([]byte(pass))
defer pakey.Free()
if err != nil {
log.Println(err)
return
Expand Down
16 changes: 16 additions & 0 deletions cmds/tsexp/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
name = "go_default_library",
srcs = ["tsexp.go"],
importpath = "github.com/TokTok/go-toxcore-c/cmds/tsexp",
visibility = ["//visibility:private"],
deps = ["//go-toxcore-c:go_default_library"],
)

go_binary(
name = "tsexp",
embed = [":go_default_library"],
importpath = "github.com/TokTok/go-toxcore-c/cmds/tsexp",
visibility = ["//visibility:public"],
)
9 changes: 4 additions & 5 deletions cmds/tsexp.go → cmds/tsexp/tsexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"log"
"time"

"github.com/kitech/go-toxcore"
"github.com/TokTok/go-toxcore-c"
)

func init() {
Expand Down Expand Up @@ -47,13 +47,12 @@ func main() {
if err != nil {
log.Println(ok, err, len(salt), salt)
}
pkey := tox.NewToxPassKey()
ok, err = pkey.DeriveWithSalt([]byte(pass), salt)
pkey, err := tox.DeriveWithSalt([]byte(pass), salt)
defer pkey.Free()
if err != nil {
log.Println(ok, err)
log.Println(err)
}
ok, err, datad := pkey.Decrypt(data)
pkey.Free()
if err != nil {
// log.Println(ok, err, len(datad), datad[0:32])
log.Println("Decrypt error, check your -pass:", err)
Expand Down
16 changes: 16 additions & 0 deletions examples/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
name = "go_default_library",
srcs = ["toxecho.go"],
importpath = "github.com/TokTok/go-toxcore-c/examples",
visibility = ["//visibility:private"],
deps = ["//go-toxcore-c:go_default_library"],
)

go_binary(
name = "examples",
embed = [":go_default_library"],
importpath = "github.com/TokTok/go-toxcore-c/examples",
visibility = ["//visibility:public"],
)
2 changes: 1 addition & 1 deletion examples/toxecho.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"time"

"github.com/kitech/go-toxcore"
"github.com/TokTok/go-toxcore-c"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion group.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void callbackConferenceTitleWrapperForC(Tox*, uint32_t, uint32_t, uint8_t*, size
void callbackConferenceNameListChangeWrapperForC(Tox*, uint32_t, uint32_t, TOX_CONFERENCE_STATE_CHANGE, void*);
// fix nouse compile warning
static inline void fixnousetoxgroup() {
static inline __attribute__((__unused__)) void fixnousetoxgroup() {
}
*/
Expand Down
2 changes: 1 addition & 1 deletion tools/generrmsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"strings"

"github.com/go-clang/v3.9/clang"
"github.com/go-clang/v3.8/clang"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion tox.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void callbackFileChunkRequestWrapperForC(Tox *tox, uint32_t friend_number, uint3
size_t length, void *user_data);
// fix nouse compile warning
static inline void fixnousetox() {
static inline __attribute__((__unused__)) void fixnousetox() {
}
*/
Expand Down
17 changes: 14 additions & 3 deletions tox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestCreate(t *testing.T) {
})
t.Run("tcp options", func(t *testing.T) {
opts := NewToxOptions()
opts.Tcp_port = 34567
opts.Tcp_port = 44577
_t := NewTox(opts)
if _t == nil {
t.Error("nil")
Expand All @@ -55,7 +55,7 @@ func TestCreate(t *testing.T) {
})
t.Run("tcp conflict", func(t *testing.T) {
opts := NewToxOptions()
opts.Tcp_port = 34567
opts.Tcp_port = 44587
_t, _t2 := NewTox(opts), NewTox(opts)
if _t == nil || _t2 != nil {
t.Error("should non-nil/nil", _t, _t2)
Expand Down Expand Up @@ -740,6 +740,9 @@ func TestGroup(t *testing.T) {
if err != nil {
t.Error(err)
}
if err != nil {
t.Error(err)
}
waitcond(func() bool {
return t1.t.CountChatList() == 1
}, 100)
Expand All @@ -749,6 +752,9 @@ func TestGroup(t *testing.T) {
if t2.t.CountChatList() != 1 {
t.Error("must 1 chat", t2.t.CountChatList())
}
waitcond(func() bool {
return t1.t.GroupNumberPeers(gn) > 0
}, 100)

if _, err := t1.t.DelGroupChat(gn); err != nil {
t.Error(err)
Expand Down Expand Up @@ -784,6 +790,10 @@ func TestGroup(t *testing.T) {
recved_act := ""
recved_msg := ""
t1.t.CallbackGroupMessage(func(_ *Tox, groupNumber, peerNumber int, msg string, ud interface{}) {
recved_msg = msg
}, nil)
t1.t.CallbackGroupAction(func(_ *Tox, groupNumber, peerNumber int, msg string, ud interface{}) {
recved_act = msg
}, nil)

go t1.Iterate()
Expand Down Expand Up @@ -832,7 +842,8 @@ func TestGroup(t *testing.T) {
return len(recved_msg) > 0 && len(recved_act) > 0
}, 10)
if recved_msg != "foo123" || recved_act != "bar123" {
t.Error(recved_msg, recved_act)
t.Errorf("Received msg='%s', act='%s', but wanted '%s' and '%s'",
recved_msg, recved_act, "foo123", "bar123")
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion toxav.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extern void rgb_to_i420(unsigned char* rgb, vpx_image_t *img);
// fix nouse compile warning
static inline void fixnousetoxav() {
static inline __attribute__((__unused__)) void fixnousetoxav() {
cb_call_wrapper_for_go(NULL, NULL, NULL);
cb_call_state_wrapper_for_go(NULL, NULL, NULL);
cb_bit_rate_status_wrapper_for_go(NULL, NULL, NULL);
Expand Down
1 change: 0 additions & 1 deletion toxdns.go

This file was deleted.

Loading

0 comments on commit 2c3b0bc

Please sign in to comment.