Migrated project to Kotlin and created a new frontend
2
.gitignore
vendored
@ -9,6 +9,7 @@ config.properties
|
|||||||
# Created by https://www.gitignore.io
|
# Created by https://www.gitignore.io
|
||||||
|
|
||||||
*.log
|
*.log
|
||||||
|
*.log.*.gz
|
||||||
|
|
||||||
### Gradle ###
|
### Gradle ###
|
||||||
.gradle
|
.gradle
|
||||||
@ -74,7 +75,6 @@ crashlytics-build.properties
|
|||||||
### Eclipse ###
|
### Eclipse ###
|
||||||
*.pydevproject
|
*.pydevproject
|
||||||
.metadata
|
.metadata
|
||||||
.gradle
|
|
||||||
bin/
|
bin/
|
||||||
tmp/
|
tmp/
|
||||||
*.tmp
|
*.tmp
|
||||||
|
65
build.gradle
@ -1,22 +1,33 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
|
ext.kotlin_version = '1.2.0'
|
||||||
ext {
|
ext {
|
||||||
springBootVersion = '1.3.0.M5'
|
springBootVersion = '2.0.0.M7'
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven { url "https://repo.spring.io/snapshot" }
|
|
||||||
maven { url "https://repo.spring.io/milestone" }
|
maven { url "https://repo.spring.io/milestone" }
|
||||||
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
|
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
|
||||||
|
classpath('se.transmode.gradle:gradle-docker:1.2')
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
|
||||||
|
classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group = 'dissem'
|
||||||
|
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'eclipse-wtp'
|
apply plugin: 'kotlin'
|
||||||
|
apply plugin: 'kotlin-spring'
|
||||||
|
apply plugin: 'eclipse'
|
||||||
apply plugin: 'idea'
|
apply plugin: 'idea'
|
||||||
apply plugin: 'spring-boot'
|
apply plugin: 'org.springframework.boot'
|
||||||
apply plugin: 'io.spring.dependency-management'
|
apply plugin: 'io.spring.dependency-management'
|
||||||
|
apply plugin: 'docker'
|
||||||
|
apply plugin: 'com.github.ben-manes.versions'
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
targetCompatibility = 1.8
|
targetCompatibility = 1.8
|
||||||
@ -33,13 +44,13 @@ configurations {
|
|||||||
providedRuntime
|
providedRuntime
|
||||||
}
|
}
|
||||||
|
|
||||||
ext.jabitVersion = 'development-SNAPSHOT'
|
ext.jabitVersion = 'feature-refactoring-SNAPSHOT'
|
||||||
dependencies {
|
dependencies {
|
||||||
compile("org.springframework.boot:spring-boot-starter-hateoas")
|
compile("org.springframework.boot:spring-boot-starter-hateoas")
|
||||||
compile("org.springframework.boot:spring-boot-starter-jersey")
|
compile("org.springframework.boot:spring-boot-starter-jersey")
|
||||||
compile("org.springframework.boot:spring-boot-starter-web")
|
compile("org.springframework.boot:spring-boot-starter-web")
|
||||||
compile("io.springfox:springfox-swagger2:2.0.2")
|
compile("io.springfox:springfox-swagger2:2.7.0")
|
||||||
compile("io.springfox:springfox-swagger-ui:2.0.2")
|
compile("io.springfox:springfox-swagger-ui:2.7.0")
|
||||||
|
|
||||||
compile "ch.dissem.jabit:jabit-core:$jabitVersion"
|
compile "ch.dissem.jabit:jabit-core:$jabitVersion"
|
||||||
compile "ch.dissem.jabit:jabit-networking:$jabitVersion"
|
compile "ch.dissem.jabit:jabit-networking:$jabitVersion"
|
||||||
@ -49,10 +60,14 @@ dependencies {
|
|||||||
|
|
||||||
compile 'com.h2database:h2:1.4.194'
|
compile 'com.h2database:h2:1.4.194'
|
||||||
|
|
||||||
compile 'com.google.zxing:core:3.3.0'
|
compile 'com.google.zxing:core:3.3.1'
|
||||||
|
|
||||||
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
|
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
|
||||||
testCompile("org.springframework.boot:spring-boot-starter-test")
|
testCompile("org.springframework.boot:spring-boot-starter-test")
|
||||||
|
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
|
||||||
|
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
|
||||||
|
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -63,13 +78,39 @@ eclipse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task(copyWebapp, type: Copy, dependsOn: ":webapp:build") {
|
task buildDocker(type: Docker, dependsOn: build) {
|
||||||
from(file('webapp/dist'))
|
push = true
|
||||||
into(file(buildDir.canonicalPath + '/resources/main/static'))
|
applicationName = 'jabit-server'
|
||||||
|
dockerfile = file('src/main/docker/Dockerfile')
|
||||||
|
doFirst {
|
||||||
|
copy {
|
||||||
|
from jar
|
||||||
|
into stageDir
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
build.dependsOn copyWebapp
|
jar {
|
||||||
|
baseName = 'jabit-server'
|
||||||
|
from('frontend/dist') {
|
||||||
|
//Public is a default supported Spring Boot resources directory.
|
||||||
|
into 'public'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//frontend:build will be run before the processResources
|
||||||
|
processResources.dependsOn('frontend:build')
|
||||||
|
|
||||||
task wrapper(type: Wrapper) {
|
task wrapper(type: Wrapper) {
|
||||||
gradleVersion = '2.3'
|
gradleVersion = '2.3'
|
||||||
}
|
}
|
||||||
|
compileKotlin {
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = "1.8"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
compileTestKotlin {
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = "1.8"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
57
frontend/.angular-cli.json
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
{
|
||||||
|
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||||
|
"project": {
|
||||||
|
"name": "jabit-server"
|
||||||
|
},
|
||||||
|
"apps": [
|
||||||
|
{
|
||||||
|
"root": "src",
|
||||||
|
"outDir": "dist",
|
||||||
|
"assets": [
|
||||||
|
"assets",
|
||||||
|
"favicon.ico"
|
||||||
|
],
|
||||||
|
"index": "index.html",
|
||||||
|
"main": "main.ts",
|
||||||
|
"polyfills": "polyfills.ts",
|
||||||
|
"test": "test.ts",
|
||||||
|
"tsconfig": "tsconfig.app.json",
|
||||||
|
"testTsconfig": "tsconfig.spec.json",
|
||||||
|
"prefix": "app",
|
||||||
|
"styles": [
|
||||||
|
"styles.css"
|
||||||
|
],
|
||||||
|
"scripts": [],
|
||||||
|
"environmentSource": "environments/environment.ts",
|
||||||
|
"environments": {
|
||||||
|
"dev": "environments/environment.ts",
|
||||||
|
"prod": "environments/environment.prod.ts"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"e2e": {
|
||||||
|
"protractor": {
|
||||||
|
"config": "./protractor.conf.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lint": [
|
||||||
|
{
|
||||||
|
"project": "src/tsconfig.app.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": "src/tsconfig.spec.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": "e2e/tsconfig.e2e.json"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"test": {
|
||||||
|
"karma": {
|
||||||
|
"config": "./karma.conf.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaults": {
|
||||||
|
"styleExt": "css",
|
||||||
|
"component": {}
|
||||||
|
}
|
||||||
|
}
|
13
frontend/.editorconfig
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Editor configuration, see http://editorconfig.org
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
max_line_length = off
|
||||||
|
trim_trailing_whitespace = false
|
42
frontend/.gitignore
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# compiled output
|
||||||
|
/dist
|
||||||
|
/tmp
|
||||||
|
/out-tsc
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
|
||||||
|
# IDEs and editors
|
||||||
|
/.idea
|
||||||
|
.project
|
||||||
|
.classpath
|
||||||
|
.c9/
|
||||||
|
*.launch
|
||||||
|
.settings/
|
||||||
|
*.sublime-workspace
|
||||||
|
|
||||||
|
# IDE - VSCode
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
|
||||||
|
# misc
|
||||||
|
/.sass-cache
|
||||||
|
/connect.lock
|
||||||
|
/coverage
|
||||||
|
/libpeerconnection.log
|
||||||
|
npm-debug.log
|
||||||
|
testem.log
|
||||||
|
/typings
|
||||||
|
|
||||||
|
# e2e
|
||||||
|
/e2e/*.js
|
||||||
|
/e2e/*.map
|
||||||
|
|
||||||
|
# System Files
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
28
frontend/README.md
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# JabitServer
|
||||||
|
|
||||||
|
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.0.3.
|
||||||
|
|
||||||
|
## Development server
|
||||||
|
|
||||||
|
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
|
||||||
|
|
||||||
|
## Code scaffolding
|
||||||
|
|
||||||
|
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|module`.
|
||||||
|
|
||||||
|
## Build
|
||||||
|
|
||||||
|
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build.
|
||||||
|
|
||||||
|
## Running unit tests
|
||||||
|
|
||||||
|
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
||||||
|
|
||||||
|
## Running end-to-end tests
|
||||||
|
|
||||||
|
Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
|
||||||
|
Before running the tests make sure you are serving the app via `ng serve`.
|
||||||
|
|
||||||
|
## Further help
|
||||||
|
|
||||||
|
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
|
16
frontend/build.gradle
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
plugins {
|
||||||
|
id "com.moowork.node" version "1.1.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
node {
|
||||||
|
// Version of node to use.
|
||||||
|
version = '7.10.0'
|
||||||
|
|
||||||
|
// Enabled the automatic download.
|
||||||
|
download = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// runs "gulp build" as part of your gradle build
|
||||||
|
task build {
|
||||||
|
dependsOn npm_run_build
|
||||||
|
}
|
14
frontend/e2e/app.e2e-spec.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { JabitServerPage } from './app.po';
|
||||||
|
|
||||||
|
describe('jabit-server App', () => {
|
||||||
|
let page: JabitServerPage;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
page = new JabitServerPage();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should display message saying app works', () => {
|
||||||
|
page.navigateTo();
|
||||||
|
expect(page.getParagraphText()).toEqual('app works!');
|
||||||
|
});
|
||||||
|
});
|
11
frontend/e2e/app.po.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { browser, by, element } from 'protractor';
|
||||||
|
|
||||||
|
export class JabitServerPage {
|
||||||
|
navigateTo() {
|
||||||
|
return browser.get('/');
|
||||||
|
}
|
||||||
|
|
||||||
|
getParagraphText() {
|
||||||
|
return element(by.css('app-root h1')).getText();
|
||||||
|
}
|
||||||
|
}
|
12
frontend/e2e/tsconfig.e2e.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"extends": "../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "../out-tsc/e2e",
|
||||||
|
"module": "commonjs",
|
||||||
|
"target": "es5",
|
||||||
|
"types": [
|
||||||
|
"jasmine",
|
||||||
|
"node"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
44
frontend/karma.conf.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// Karma configuration file, see link for more information
|
||||||
|
// https://karma-runner.github.io/0.13/config/configuration-file.html
|
||||||
|
|
||||||
|
module.exports = function (config) {
|
||||||
|
config.set({
|
||||||
|
basePath: '',
|
||||||
|
frameworks: ['jasmine', '@angular/cli'],
|
||||||
|
plugins: [
|
||||||
|
require('karma-jasmine'),
|
||||||
|
require('karma-chrome-launcher'),
|
||||||
|
require('karma-jasmine-html-reporter'),
|
||||||
|
require('karma-coverage-istanbul-reporter'),
|
||||||
|
require('@angular/cli/plugins/karma')
|
||||||
|
],
|
||||||
|
client:{
|
||||||
|
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
||||||
|
},
|
||||||
|
files: [
|
||||||
|
{ pattern: './src/test.ts', watched: false }
|
||||||
|
],
|
||||||
|
preprocessors: {
|
||||||
|
'./src/test.ts': ['@angular/cli']
|
||||||
|
},
|
||||||
|
mime: {
|
||||||
|
'text/x-typescript': ['ts','tsx']
|
||||||
|
},
|
||||||
|
coverageIstanbulReporter: {
|
||||||
|
reports: [ 'html', 'lcovonly' ],
|
||||||
|
fixWebpackSourcePaths: true
|
||||||
|
},
|
||||||
|
angularCli: {
|
||||||
|
environment: 'dev'
|
||||||
|
},
|
||||||
|
reporters: config.angularCli && config.angularCli.codeCoverage
|
||||||
|
? ['progress', 'coverage-istanbul']
|
||||||
|
: ['progress', 'kjhtml'],
|
||||||
|
port: 9876,
|
||||||
|
colors: true,
|
||||||
|
logLevel: config.LOG_INFO,
|
||||||
|
autoWatch: true,
|
||||||
|
browsers: ['Chrome'],
|
||||||
|
singleRun: false
|
||||||
|
});
|
||||||
|
};
|
53
frontend/package.json
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
{
|
||||||
|
"name": "jabit-server",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"license": "MIT",
|
||||||
|
"scripts": {
|
||||||
|
"ng": "ng",
|
||||||
|
"start": "ng serve",
|
||||||
|
"build": "ng build",
|
||||||
|
"test": "ng test",
|
||||||
|
"lint": "ng lint",
|
||||||
|
"e2e": "ng e2e"
|
||||||
|
},
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@angular/animations": "^5.1.0",
|
||||||
|
"@angular/cdk": "^5.0.0",
|
||||||
|
"@angular/common": "^5.1.0",
|
||||||
|
"@angular/compiler": "^5.1.0",
|
||||||
|
"@angular/core": "^5.1.0",
|
||||||
|
"@angular/flex-layout": "^2.0.0-beta.10-4905443",
|
||||||
|
"@angular/forms": "^5.1.0",
|
||||||
|
"@angular/http": "^5.1.0",
|
||||||
|
"@angular/material": "^5.0.0",
|
||||||
|
"@angular/platform-browser": "^5.1.0",
|
||||||
|
"@angular/platform-browser-dynamic": "^5.1.0",
|
||||||
|
"@angular/router": "^5.1.0",
|
||||||
|
"ajv": "^5.5.1",
|
||||||
|
"codelyzer": "^4.0.1",
|
||||||
|
"core-js": "^2.4.1",
|
||||||
|
"rxjs": "^5.5.4",
|
||||||
|
"tslint": "^5.8.0",
|
||||||
|
"zone.js": "^0.8.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@angular/cli": "^1.5.5",
|
||||||
|
"@angular/compiler-cli": "^5.1.0",
|
||||||
|
"@types/jasmine": "2.5.38",
|
||||||
|
"@types/node": "~6.0.60",
|
||||||
|
"codelyzer": "~2.0.0",
|
||||||
|
"jasmine-core": "~2.5.2",
|
||||||
|
"jasmine-spec-reporter": "~3.2.0",
|
||||||
|
"karma": "~1.4.1",
|
||||||
|
"karma-chrome-launcher": "~2.1.1",
|
||||||
|
"karma-cli": "~1.0.1",
|
||||||
|
"karma-coverage-istanbul-reporter": "^0.2.0",
|
||||||
|
"karma-jasmine": "~1.1.0",
|
||||||
|
"karma-jasmine-html-reporter": "^0.2.2",
|
||||||
|
"protractor": "~5.1.0",
|
||||||
|
"ts-node": "~2.0.0",
|
||||||
|
"tslint": "~4.5.0",
|
||||||
|
"typescript": "~2.5.0"
|
||||||
|
}
|
||||||
|
}
|
30
frontend/protractor.conf.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// Protractor configuration file, see link for more information
|
||||||
|
// https://github.com/angular/protractor/blob/master/lib/config.ts
|
||||||
|
|
||||||
|
const { SpecReporter } = require('jasmine-spec-reporter');
|
||||||
|
|
||||||
|
exports.config = {
|
||||||
|
allScriptsTimeout: 11000,
|
||||||
|
specs: [
|
||||||
|
'./e2e/**/*.e2e-spec.ts'
|
||||||
|
],
|
||||||
|
capabilities: {
|
||||||
|
'browserName': 'chrome'
|
||||||
|
},
|
||||||
|
directConnect: true,
|
||||||
|
baseUrl: 'http://localhost:4200/',
|
||||||
|
framework: 'jasmine',
|
||||||
|
jasmineNodeOpts: {
|
||||||
|
showColors: true,
|
||||||
|
defaultTimeoutInterval: 30000,
|
||||||
|
print: function() {}
|
||||||
|
},
|
||||||
|
beforeLaunch: function() {
|
||||||
|
require('ts-node').register({
|
||||||
|
project: 'e2e/tsconfig.e2e.json'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onPrepare() {
|
||||||
|
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
|
||||||
|
}
|
||||||
|
};
|
0
frontend/src/app/app.component.css
Normal file
10
frontend/src/app/app.component.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<mat-toolbar color="primary" class="mat-elevation-z6">
|
||||||
|
<div fxLayout fxLayoutAlign="space-between center" fxFlex>
|
||||||
|
{{title}}
|
||||||
|
<a mat-button title="Go to server status page" class="right"
|
||||||
|
routerLink="/status">
|
||||||
|
Status
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</mat-toolbar>
|
||||||
|
<router-outlet></router-outlet>
|
32
frontend/src/app/app.component.spec.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import { TestBed, async } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
|
describe('AppComponent', () => {
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [
|
||||||
|
AppComponent
|
||||||
|
],
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should create the app', async(() => {
|
||||||
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
|
const app = fixture.debugElement.componentInstance;
|
||||||
|
expect(app).toBeTruthy();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it(`should have as title 'app works!'`, async(() => {
|
||||||
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
|
const app = fixture.debugElement.componentInstance;
|
||||||
|
expect(app.title).toEqual('app works!');
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should render title in a h1 tag', async(() => {
|
||||||
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
|
fixture.detectChanges();
|
||||||
|
const compiled = fixture.debugElement.nativeElement;
|
||||||
|
expect(compiled.querySelector('h1').textContent).toContain('app works!');
|
||||||
|
}));
|
||||||
|
});
|
10
frontend/src/app/app.component.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-root',
|
||||||
|
templateUrl: './app.component.html',
|
||||||
|
styleUrls: ['./app.component.css']
|
||||||
|
})
|
||||||
|
export class AppComponent {
|
||||||
|
title = 'Jabit Bitmessage Server';
|
||||||
|
}
|
35
frontend/src/app/app.module.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import {BrowserModule} from '@angular/platform-browser';
|
||||||
|
import {NgModule} from '@angular/core';
|
||||||
|
|
||||||
|
import {AppComponent} from './app.component';
|
||||||
|
import {MatButtonModule, MatCardModule, MatExpansionModule, MatToolbarModule} from '@angular/material';
|
||||||
|
import {RouterModule} from "@angular/router";
|
||||||
|
import {StatusComponent} from './status/status.component';
|
||||||
|
import {APP_ROUTES} from "./app.routes";
|
||||||
|
import {HttpClientModule} from "@angular/common/http";
|
||||||
|
import { BroadcastComponent } from './broadcast/broadcast.component';
|
||||||
|
import {BrowserAnimationsModule} from "@angular/platform-browser/animations";
|
||||||
|
import {FlexLayoutModule} from "@angular/flex-layout";
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
declarations: [
|
||||||
|
AppComponent,
|
||||||
|
StatusComponent,
|
||||||
|
BroadcastComponent
|
||||||
|
],
|
||||||
|
imports: [
|
||||||
|
BrowserModule,
|
||||||
|
BrowserAnimationsModule,
|
||||||
|
HttpClientModule,
|
||||||
|
RouterModule.forRoot(APP_ROUTES),
|
||||||
|
FlexLayoutModule,
|
||||||
|
MatToolbarModule,
|
||||||
|
MatCardModule,
|
||||||
|
MatExpansionModule,
|
||||||
|
MatButtonModule
|
||||||
|
],
|
||||||
|
providers: [],
|
||||||
|
bootstrap: [AppComponent]
|
||||||
|
})
|
||||||
|
export class AppModule {
|
||||||
|
}
|
15
frontend/src/app/app.routes.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import {Route} from "@angular/router";
|
||||||
|
import {StatusComponent} from "./status/status.component";
|
||||||
|
import {BroadcastComponent} from "./broadcast/broadcast.component";
|
||||||
|
|
||||||
|
export const APP_ROUTES: Route[] = [
|
||||||
|
{
|
||||||
|
path: 'status',
|
||||||
|
component: StatusComponent
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'broadcasts/:address',
|
||||||
|
component: BroadcastComponent
|
||||||
|
},
|
||||||
|
{path: '', redirectTo: 'status', pathMatch: 'full'}
|
||||||
|
];
|
16
frontend/src/app/broadcast/broadcast.component.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<div *ngIf="broadcasts$ | async as broadcasts">
|
||||||
|
<h1>{{broadcasts.sender.alias || broadcasts.sender.address}}</h1>
|
||||||
|
<mat-expansion-panel *ngFor="let message of broadcasts.messages">
|
||||||
|
<mat-expansion-panel-header>
|
||||||
|
<mat-panel-title>
|
||||||
|
{{message.subject}}
|
||||||
|
</mat-panel-title>
|
||||||
|
<mat-panel-description>
|
||||||
|
{{message.received * 1000 | date:'medium'}}
|
||||||
|
</mat-panel-description>
|
||||||
|
</mat-expansion-panel-header>
|
||||||
|
|
||||||
|
<pre><code>{{message.body}}</code></pre>
|
||||||
|
|
||||||
|
</mat-expansion-panel>
|
||||||
|
</div>
|
4
frontend/src/app/broadcast/broadcast.component.scss
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
:host {
|
||||||
|
margin: 2em;
|
||||||
|
display: block;
|
||||||
|
}
|
25
frontend/src/app/broadcast/broadcast.component.spec.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { BroadcastComponent } from './broadcast.component';
|
||||||
|
|
||||||
|
describe('BroadcastComponent', () => {
|
||||||
|
let component: BroadcastComponent;
|
||||||
|
let fixture: ComponentFixture<BroadcastComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ BroadcastComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(BroadcastComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
40
frontend/src/app/broadcast/broadcast.component.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import {Component, OnInit} from '@angular/core';
|
||||||
|
import {ActivatedRoute} from "@angular/router";
|
||||||
|
import {HttpClient} from "@angular/common/http";
|
||||||
|
import {Observable} from "rxjs/Observable";
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-broadcast',
|
||||||
|
templateUrl: './broadcast.component.html',
|
||||||
|
styleUrls: ['./broadcast.component.scss']
|
||||||
|
})
|
||||||
|
export class BroadcastComponent implements OnInit {
|
||||||
|
|
||||||
|
broadcasts$: Observable<Broadcasts>;
|
||||||
|
|
||||||
|
constructor(private route: ActivatedRoute, private http: HttpClient) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
let address = this.route.snapshot.params['address'];
|
||||||
|
this.broadcasts$ = this.http.get<Broadcasts>('http://localhost:8080/read/' + address)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Sender {
|
||||||
|
address: String;
|
||||||
|
alias: String;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Message {
|
||||||
|
id: any;
|
||||||
|
received: number;
|
||||||
|
subject: string;
|
||||||
|
body: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Broadcasts {
|
||||||
|
sender: Sender;
|
||||||
|
messages: Message[]
|
||||||
|
}
|
3
frontend/src/app/status/status.component.html
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<mat-card>
|
||||||
|
<pre><code>{{status}}</code></pre>
|
||||||
|
</mat-card>
|
4
frontend/src/app/status/status.component.scss
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
:host {
|
||||||
|
margin: 2em;
|
||||||
|
display: block;
|
||||||
|
}
|
25
frontend/src/app/status/status.component.spec.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { StatusComponent } from './status.component';
|
||||||
|
|
||||||
|
describe('StatusComponent', () => {
|
||||||
|
let component: StatusComponent;
|
||||||
|
let fixture: ComponentFixture<StatusComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ StatusComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(StatusComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
22
frontend/src/app/status/status.component.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import {Component, OnInit} from '@angular/core';
|
||||||
|
import {HttpClient} from '@angular/common/http';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-status',
|
||||||
|
templateUrl: './status.component.html',
|
||||||
|
styleUrls: ['./status.component.scss']
|
||||||
|
})
|
||||||
|
export class StatusComponent implements OnInit {
|
||||||
|
|
||||||
|
status: string;
|
||||||
|
|
||||||
|
constructor(private http: HttpClient) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.http.get('http://localhost:8080/status').subscribe(data => {
|
||||||
|
this.status = JSON.stringify(data, null, 2);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
0
frontend/src/assets/.gitkeep
Normal file
3
frontend/src/environments/environment.prod.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export const environment = {
|
||||||
|
production: true
|
||||||
|
};
|
8
frontend/src/environments/environment.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// The file contents for the current environment will overwrite these during build.
|
||||||
|
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
|
||||||
|
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
|
||||||
|
// The list of which env maps to which file can be found in `.angular-cli.json`.
|
||||||
|
|
||||||
|
export const environment = {
|
||||||
|
production: false
|
||||||
|
};
|
BIN
frontend/src/favicon.ico
Normal file
After Width: | Height: | Size: 5.3 KiB |
16
frontend/src/index.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>JabitServer</title>
|
||||||
|
<base href="/">
|
||||||
|
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
|
||||||
|
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||||
|
</head>
|
||||||
|
<body class="mat-typography">
|
||||||
|
<app-root>Loading...</app-root>
|
||||||
|
</body>
|
||||||
|
</html>
|
11
frontend/src/main.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { enableProdMode } from '@angular/core';
|
||||||
|
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
|
import { AppModule } from './app/app.module';
|
||||||
|
import { environment } from './environments/environment';
|
||||||
|
|
||||||
|
if (environment.production) {
|
||||||
|
enableProdMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
platformBrowserDynamic().bootstrapModule(AppModule);
|
72
frontend/src/polyfills.ts
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/**
|
||||||
|
* This file includes polyfills needed by Angular and is loaded before the app.
|
||||||
|
* You can add your own extra polyfills to this file.
|
||||||
|
*
|
||||||
|
* This file is divided into 2 sections:
|
||||||
|
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
|
||||||
|
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
|
||||||
|
* file.
|
||||||
|
*
|
||||||
|
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
|
||||||
|
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
|
||||||
|
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
|
||||||
|
*
|
||||||
|
* Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
/***************************************************************************************************
|
||||||
|
* BROWSER POLYFILLS
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
|
||||||
|
// import 'core-js/es6/symbol';
|
||||||
|
// import 'core-js/es6/object';
|
||||||
|
// import 'core-js/es6/function';
|
||||||
|
// import 'core-js/es6/parse-int';
|
||||||
|
// import 'core-js/es6/parse-float';
|
||||||
|
// import 'core-js/es6/number';
|
||||||
|
// import 'core-js/es6/math';
|
||||||
|
// import 'core-js/es6/string';
|
||||||
|
// import 'core-js/es6/date';
|
||||||
|
// import 'core-js/es6/array';
|
||||||
|
// import 'core-js/es6/regexp';
|
||||||
|
// import 'core-js/es6/map';
|
||||||
|
// import 'core-js/es6/set';
|
||||||
|
|
||||||
|
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
|
||||||
|
// import 'classlist.js'; // Run `npm install --save classlist.js`.
|
||||||
|
|
||||||
|
/** IE10 and IE11 requires the following to support `@angular/animation`. */
|
||||||
|
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
|
||||||
|
|
||||||
|
|
||||||
|
/** Evergreen browsers require these. **/
|
||||||
|
import 'core-js/es6/reflect';
|
||||||
|
import 'core-js/es7/reflect';
|
||||||
|
|
||||||
|
|
||||||
|
/** ALL Firefox browsers require the following to support `@angular/animation`. **/
|
||||||
|
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************************************
|
||||||
|
* Zone JS is required by Angular itself.
|
||||||
|
*/
|
||||||
|
import 'zone.js/dist/zone'; // Included with Angular CLI.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************************************
|
||||||
|
* APPLICATION IMPORTS
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date, currency, decimal and percent pipes.
|
||||||
|
* Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
|
||||||
|
*/
|
||||||
|
// import 'intl'; // Run `npm install --save intl`.
|
||||||
|
/**
|
||||||
|
* Need to import at least one locale-data with intl.
|
||||||
|
*/
|
||||||
|
// import 'intl/locale-data/jsonp/en';
|
6
frontend/src/styles.css
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/* You can add global styles to this file, and also import other style files */
|
||||||
|
@import "~@angular/material/prebuilt-themes/indigo-pink.css";
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
}
|
32
frontend/src/test.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
||||||
|
|
||||||
|
import 'zone.js/dist/long-stack-trace-zone';
|
||||||
|
import 'zone.js/dist/proxy.js';
|
||||||
|
import 'zone.js/dist/sync-test';
|
||||||
|
import 'zone.js/dist/jasmine-patch';
|
||||||
|
import 'zone.js/dist/async-test';
|
||||||
|
import 'zone.js/dist/fake-async-test';
|
||||||
|
import { getTestBed } from '@angular/core/testing';
|
||||||
|
import {
|
||||||
|
BrowserDynamicTestingModule,
|
||||||
|
platformBrowserDynamicTesting
|
||||||
|
} from '@angular/platform-browser-dynamic/testing';
|
||||||
|
|
||||||
|
// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
|
||||||
|
declare var __karma__: any;
|
||||||
|
declare var require: any;
|
||||||
|
|
||||||
|
// Prevent Karma from running prematurely.
|
||||||
|
__karma__.loaded = function () {};
|
||||||
|
|
||||||
|
// First, initialize the Angular testing environment.
|
||||||
|
getTestBed().initTestEnvironment(
|
||||||
|
BrowserDynamicTestingModule,
|
||||||
|
platformBrowserDynamicTesting()
|
||||||
|
);
|
||||||
|
// Then we find all the tests.
|
||||||
|
const context = require.context('./', true, /\.spec\.ts$/);
|
||||||
|
// And load the modules.
|
||||||
|
context.keys().map(context);
|
||||||
|
// Finally, start Karma to run the tests.
|
||||||
|
__karma__.start();
|
13
frontend/src/tsconfig.app.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"extends": "../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "../out-tsc/app",
|
||||||
|
"module": "es2015",
|
||||||
|
"baseUrl": "",
|
||||||
|
"types": []
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"test.ts",
|
||||||
|
"**/*.spec.ts"
|
||||||
|
]
|
||||||
|
}
|
20
frontend/src/tsconfig.spec.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"extends": "../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "../out-tsc/spec",
|
||||||
|
"module": "commonjs",
|
||||||
|
"target": "es5",
|
||||||
|
"baseUrl": "",
|
||||||
|
"types": [
|
||||||
|
"jasmine",
|
||||||
|
"node"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"test.ts"
|
||||||
|
],
|
||||||
|
"include": [
|
||||||
|
"**/*.spec.ts",
|
||||||
|
"**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
5
frontend/src/typings.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
/* SystemJS module definition */
|
||||||
|
declare var module: NodeModule;
|
||||||
|
interface NodeModule {
|
||||||
|
id: string;
|
||||||
|
}
|
20
frontend/tsconfig.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"compileOnSave": false,
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./dist/out-tsc",
|
||||||
|
"baseUrl": "src",
|
||||||
|
"sourceMap": true,
|
||||||
|
"declaration": false,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"target": "es5",
|
||||||
|
"typeRoots": [
|
||||||
|
"node_modules/@types"
|
||||||
|
],
|
||||||
|
"lib": [
|
||||||
|
"es2016",
|
||||||
|
"dom"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
130
frontend/tslint.json
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
{
|
||||||
|
"rulesDirectory": [
|
||||||
|
"node_modules/codelyzer"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"callable-types": true,
|
||||||
|
"class-name": true,
|
||||||
|
"comment-format": [
|
||||||
|
true,
|
||||||
|
"check-space"
|
||||||
|
],
|
||||||
|
"curly": true,
|
||||||
|
"eofline": true,
|
||||||
|
"forin": true,
|
||||||
|
"import-blacklist": [
|
||||||
|
true,
|
||||||
|
"rxjs"
|
||||||
|
],
|
||||||
|
"import-spacing": true,
|
||||||
|
"indent": [
|
||||||
|
true,
|
||||||
|
"spaces"
|
||||||
|
],
|
||||||
|
"interface-over-type-literal": true,
|
||||||
|
"label-position": true,
|
||||||
|
"max-line-length": [
|
||||||
|
true,
|
||||||
|
140
|
||||||
|
],
|
||||||
|
"member-access": false,
|
||||||
|
"member-ordering": [
|
||||||
|
true,
|
||||||
|
"static-before-instance",
|
||||||
|
"variables-before-functions"
|
||||||
|
],
|
||||||
|
"no-arg": true,
|
||||||
|
"no-bitwise": true,
|
||||||
|
"no-console": [
|
||||||
|
true,
|
||||||
|
"debug",
|
||||||
|
"info",
|
||||||
|
"time",
|
||||||
|
"timeEnd",
|
||||||
|
"trace"
|
||||||
|
],
|
||||||
|
"no-construct": true,
|
||||||
|
"no-debugger": true,
|
||||||
|
"no-empty": false,
|
||||||
|
"no-empty-interface": true,
|
||||||
|
"no-eval": true,
|
||||||
|
"no-inferrable-types": [
|
||||||
|
true,
|
||||||
|
"ignore-params"
|
||||||
|
],
|
||||||
|
"no-shadowed-variable": true,
|
||||||
|
"no-string-literal": false,
|
||||||
|
"no-string-throw": true,
|
||||||
|
"no-switch-case-fall-through": true,
|
||||||
|
"no-trailing-whitespace": true,
|
||||||
|
"no-unused-expression": true,
|
||||||
|
"no-use-before-declare": true,
|
||||||
|
"no-var-keyword": true,
|
||||||
|
"object-literal-sort-keys": false,
|
||||||
|
"one-line": [
|
||||||
|
true,
|
||||||
|
"check-open-brace",
|
||||||
|
"check-catch",
|
||||||
|
"check-else",
|
||||||
|
"check-whitespace"
|
||||||
|
],
|
||||||
|
"prefer-const": true,
|
||||||
|
"quotemark": [
|
||||||
|
true,
|
||||||
|
"single"
|
||||||
|
],
|
||||||
|
"radix": true,
|
||||||
|
"semicolon": [
|
||||||
|
"always"
|
||||||
|
],
|
||||||
|
"triple-equals": [
|
||||||
|
true,
|
||||||
|
"allow-null-check"
|
||||||
|
],
|
||||||
|
"typedef-whitespace": [
|
||||||
|
true,
|
||||||
|
{
|
||||||
|
"call-signature": "nospace",
|
||||||
|
"index-signature": "nospace",
|
||||||
|
"parameter": "nospace",
|
||||||
|
"property-declaration": "nospace",
|
||||||
|
"variable-declaration": "nospace"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"typeof-compare": true,
|
||||||
|
"unified-signatures": true,
|
||||||
|
"variable-name": false,
|
||||||
|
"whitespace": [
|
||||||
|
true,
|
||||||
|
"check-branch",
|
||||||
|
"check-decl",
|
||||||
|
"check-operator",
|
||||||
|
"check-separator",
|
||||||
|
"check-type"
|
||||||
|
],
|
||||||
|
"directive-selector": [
|
||||||
|
true,
|
||||||
|
"attribute",
|
||||||
|
"app",
|
||||||
|
"camelCase"
|
||||||
|
],
|
||||||
|
"component-selector": [
|
||||||
|
true,
|
||||||
|
"element",
|
||||||
|
"app",
|
||||||
|
"kebab-case"
|
||||||
|
],
|
||||||
|
"use-input-property-decorator": true,
|
||||||
|
"use-output-property-decorator": true,
|
||||||
|
"use-host-property-decorator": true,
|
||||||
|
"no-input-rename": true,
|
||||||
|
"no-output-rename": true,
|
||||||
|
"use-life-cycle-interface": true,
|
||||||
|
"use-pipe-transform-interface": true,
|
||||||
|
"component-class-suffix": true,
|
||||||
|
"directive-class-suffix": true,
|
||||||
|
"no-access-missing-member": true,
|
||||||
|
"templates-use-public": true,
|
||||||
|
"invoke-injectable": true
|
||||||
|
}
|
||||||
|
}
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
|||||||
#Mon Mar 16 20:59:34 CET 2015
|
#Thu Oct 19 11:25:29 CEST 2017
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2-all.zip
|
||||||
|
10
gradlew
vendored
@ -42,11 +42,6 @@ case "`uname`" in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# For Cygwin, ensure paths are in UNIX format before anything is touched.
|
|
||||||
if $cygwin ; then
|
|
||||||
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
# Attempt to set APP_HOME
|
||||||
# Resolve links: $0 may be a link
|
# Resolve links: $0 may be a link
|
||||||
PRG="$0"
|
PRG="$0"
|
||||||
@ -61,9 +56,9 @@ while [ -h "$PRG" ] ; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
SAVED="`pwd`"
|
SAVED="`pwd`"
|
||||||
cd "`dirname \"$PRG\"`/" >&-
|
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||||
APP_HOME="`pwd -P`"
|
APP_HOME="`pwd -P`"
|
||||||
cd "$SAVED" >&-
|
cd "$SAVED" >/dev/null
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
@ -114,6 +109,7 @@ fi
|
|||||||
if $cygwin ; then
|
if $cygwin ; then
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||||
|
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
# We build the pattern for arguments to be converted via cygpath
|
||||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||||
|
@ -1 +1,3 @@
|
|||||||
include 'webapp'
|
include 'frontend'
|
||||||
|
|
||||||
|
rootProject.name = 'jabit-server'
|
6
src/main/docker/Dockerfile
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
FROM frolvlad/alpine-oraclejdk8:slim
|
||||||
|
VOLUME /tmp
|
||||||
|
ADD jabit-server.jar app.jar
|
||||||
|
RUN sh -c 'touch /app.jar'
|
||||||
|
ENV JAVA_OPTS=""
|
||||||
|
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
|
@ -1,13 +0,0 @@
|
|||||||
package ch.dissem.bitmessage.server;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by chrigu on 22.11.15.
|
|
||||||
*/
|
|
||||||
public interface Constants {
|
|
||||||
String ADMIN_LIST = "admins.conf";
|
|
||||||
String CLIENT_LIST = "clients.conf";
|
|
||||||
|
|
||||||
String WHITELIST = "whitelist.conf";
|
|
||||||
String SHORTLIST = "shortlist.conf";
|
|
||||||
String BLACKLIST = "blacklist.conf";
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 Christian Basler
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ch.dissem.bitmessage.server;
|
|
||||||
|
|
||||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
|
||||||
import ch.dissem.bitmessage.entity.Plaintext;
|
|
||||||
import ch.dissem.bitmessage.server.entities.Broadcasts;
|
|
||||||
import ch.dissem.bitmessage.server.entities.Message;
|
|
||||||
import ch.dissem.bitmessage.server.entities.Sender;
|
|
||||||
import ch.dissem.bitmessage.utils.UnixTime;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
public class Converter {
|
|
||||||
public static Broadcasts broadcasts(BitmessageAddress sender, Collection<Plaintext> messages) {
|
|
||||||
Broadcasts result = new Broadcasts();
|
|
||||||
result.sender = sender(sender);
|
|
||||||
result.messages = new Message[messages.size()];
|
|
||||||
int i = 0;
|
|
||||||
for (Plaintext msg : messages) {
|
|
||||||
result.messages[i] = message(msg);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Broadcasts broadcasts(BitmessageAddress sender, Message... messages) {
|
|
||||||
Broadcasts result = new Broadcasts();
|
|
||||||
result.sender = sender(sender);
|
|
||||||
result.messages = messages;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Sender sender(BitmessageAddress sender) {
|
|
||||||
Sender result = new Sender();
|
|
||||||
result.address = sender.getAddress();
|
|
||||||
result.alias = sender.toString();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Message message(String subject, String body) {
|
|
||||||
Message result = new Message();
|
|
||||||
result.id = 0;
|
|
||||||
result.received = UnixTime.now();
|
|
||||||
result.subject = subject;
|
|
||||||
result.body = body;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Message message(Plaintext plaintext) {
|
|
||||||
Message result = new Message();
|
|
||||||
result.id = plaintext.getId();
|
|
||||||
result.received = plaintext.getReceived();
|
|
||||||
result.subject = plaintext.getSubject();
|
|
||||||
result.body = plaintext.getText();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,210 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 Christian Basler
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ch.dissem.bitmessage.server;
|
|
||||||
|
|
||||||
import ch.dissem.bitmessage.BitmessageContext;
|
|
||||||
import ch.dissem.bitmessage.cryptography.bc.BouncyCryptography;
|
|
||||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
|
||||||
import ch.dissem.bitmessage.entity.payload.Pubkey;
|
|
||||||
import ch.dissem.bitmessage.networking.nio.NioNetworkHandler;
|
|
||||||
import ch.dissem.bitmessage.ports.*;
|
|
||||||
import ch.dissem.bitmessage.repository.*;
|
|
||||||
import ch.dissem.bitmessage.server.repository.ServerProofOfWorkRepository;
|
|
||||||
import ch.dissem.bitmessage.utils.Singleton;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import springfox.documentation.spi.DocumentationType;
|
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static ch.dissem.bitmessage.server.Constants.*;
|
|
||||||
import static java.util.stream.Collectors.toSet;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class JabitServerConfig {
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(JabitServerConfig.class);
|
|
||||||
|
|
||||||
public static final int SHORTLIST_SIZE = 5;
|
|
||||||
|
|
||||||
@Value("${bitmessage.port}")
|
|
||||||
private int port;
|
|
||||||
@Value("${bitmessage.connection.ttl.hours}")
|
|
||||||
private int connectionTTL;
|
|
||||||
@Value("${bitmessage.connection.limit}")
|
|
||||||
private int connectionLimit;
|
|
||||||
|
|
||||||
@Value("${database.url}")
|
|
||||||
private String dbUrl;
|
|
||||||
@Value("${database.user}")
|
|
||||||
private String dbUser;
|
|
||||||
@Value("${database.password}")
|
|
||||||
private String dbPassword;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public JdbcConfig jdbcConfig() {
|
|
||||||
return new JdbcConfig(dbUrl, dbUser, dbPassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public AddressRepository addressRepo() {
|
|
||||||
return new JdbcAddressRepository(jdbcConfig());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Inventory inventory() {
|
|
||||||
return new JdbcInventory(jdbcConfig());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public MessageRepository messageRepo() {
|
|
||||||
return new JdbcMessageRepository(jdbcConfig());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ProofOfWorkRepository proofOfWorkRepo() {
|
|
||||||
return new JdbcProofOfWorkRepository(jdbcConfig());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public NodeRegistry nodeRegistry() {
|
|
||||||
return new JdbcNodeRegistry(jdbcConfig());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public NetworkHandler networkHandler() {
|
|
||||||
return new NioNetworkHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Cryptography cryptography() {
|
|
||||||
Cryptography cryptography = new BouncyCryptography();
|
|
||||||
Singleton.initialize(cryptography); // needed for admins and clients
|
|
||||||
return cryptography;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public BitmessageContext.Listener serverListener() {
|
|
||||||
return new ServerListener(admins(), clients(), whitelist(), shortlist(), blacklist());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ServerProofOfWorkRepository serverProofOfWorkRepository() {
|
|
||||||
return new ServerProofOfWorkRepository(jdbcConfig());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public CustomCommandHandler commandHandler() {
|
|
||||||
return new ProofOfWorkRequestHandler(serverProofOfWorkRepository(), clients());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public BitmessageContext bitmessageContext() {
|
|
||||||
return new BitmessageContext.Builder()
|
|
||||||
.addressRepo(addressRepo())
|
|
||||||
.inventory(inventory())
|
|
||||||
.messageRepo(messageRepo())
|
|
||||||
.nodeRegistry(nodeRegistry())
|
|
||||||
.powRepo(proofOfWorkRepo())
|
|
||||||
.networkHandler(networkHandler())
|
|
||||||
.listener(serverListener())
|
|
||||||
.customCommandHandler(commandHandler())
|
|
||||||
.cryptography(cryptography())
|
|
||||||
.port(port)
|
|
||||||
.connectionLimit(connectionLimit)
|
|
||||||
.connectionTTL(connectionTTL)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Set<BitmessageAddress> admins() {
|
|
||||||
cryptography();
|
|
||||||
return Utils.readOrCreateList(
|
|
||||||
ADMIN_LIST,
|
|
||||||
"# Admins can send commands to the server.\n"
|
|
||||||
).stream().map(BitmessageAddress::new).collect(toSet());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Set<BitmessageAddress> clients() {
|
|
||||||
cryptography();
|
|
||||||
return Utils.readOrCreateList(
|
|
||||||
CLIENT_LIST,
|
|
||||||
"# Clients may send incomplete objects for proof of work.\n"
|
|
||||||
).stream().map(BitmessageAddress::new).collect(toSet());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Set<String> whitelist() {
|
|
||||||
return Utils.readOrCreateList(
|
|
||||||
WHITELIST,
|
|
||||||
"# If there are any Bitmessage addresses in the whitelist, only those will be shown.\n" +
|
|
||||||
"# blacklist.conf will be ignored, but shortlist.conf will be applied to whitelisted addresses.\n"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Set<String> shortlist() {
|
|
||||||
return Utils.readOrCreateList(
|
|
||||||
SHORTLIST,
|
|
||||||
"# Broadcasts of these addresses will be restricted to the last " + SHORTLIST_SIZE + " entries.\n\n" +
|
|
||||||
"# Time Service:\n" +
|
|
||||||
"BM-BcbRqcFFSQUUmXFKsPJgVQPSiFA3Xash\n\n" +
|
|
||||||
"# Q's Aktivlist:\n" +
|
|
||||||
"BM-GtT7NLCCAu3HrT7dNTUTY9iDns92Z2ND\n"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Set<String> blacklist() {
|
|
||||||
return Utils.readOrCreateList(
|
|
||||||
BLACKLIST,
|
|
||||||
"# Bitmessage addresses in this file are being ignored and their broadcasts won't be returned.\n"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Docket api() {
|
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
|
||||||
.select()
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public BitmessageAddress identity() {
|
|
||||||
List<BitmessageAddress> identities = bitmessageContext().addresses().getIdentities();
|
|
||||||
BitmessageAddress identity;
|
|
||||||
if (identities.isEmpty()) {
|
|
||||||
LOG.info("Creating new identity...");
|
|
||||||
identity = bitmessageContext().createIdentity(false, Pubkey.Feature.DOES_ACK);
|
|
||||||
LOG.info("Identity " + identity.getAddress() + " created.");
|
|
||||||
} else {
|
|
||||||
LOG.info("Identities:");
|
|
||||||
identities.stream().map(BitmessageAddress::getAddress).forEach(LOG::info);
|
|
||||||
identity = identities.get(0);
|
|
||||||
if (identities.size() > 1) {
|
|
||||||
LOG.info("Using " + identity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LOG.info("QR Code:\n" + Utils.qrCode(identity));
|
|
||||||
return identity;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,123 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 Christian Basler
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ch.dissem.bitmessage.server;
|
|
||||||
|
|
||||||
import ch.dissem.bitmessage.BitmessageContext;
|
|
||||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
|
||||||
import ch.dissem.bitmessage.entity.Plaintext;
|
|
||||||
import ch.dissem.bitmessage.server.entities.Broadcasts;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static ch.dissem.bitmessage.server.Converter.broadcasts;
|
|
||||||
import static ch.dissem.bitmessage.server.Converter.message;
|
|
||||||
import static org.springframework.web.bind.annotation.RequestMethod.GET;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Christian Basler
|
|
||||||
*/
|
|
||||||
@CrossOrigin
|
|
||||||
@RestController
|
|
||||||
public class JabitServerController {
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(JabitServerController.class);
|
|
||||||
|
|
||||||
private static final long HOUR = 60 * 60 * 1000l; // in ms
|
|
||||||
|
|
||||||
private static final String CONFIG_FILE = "config.properties";
|
|
||||||
private static final String PROPERTY_PORT = "port";
|
|
||||||
|
|
||||||
private static final int SHORTLIST_SIZE = 5;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private Set<String> whitelist;
|
|
||||||
@Resource
|
|
||||||
private Set<String> shortlist;
|
|
||||||
@Resource
|
|
||||||
private Set<String> blacklist;
|
|
||||||
@Inject
|
|
||||||
private BitmessageAddress identity;
|
|
||||||
@Inject
|
|
||||||
private BitmessageContext ctx;
|
|
||||||
|
|
||||||
@RequestMapping(value = "status", method = GET, produces = "application/json")
|
|
||||||
public String status() {
|
|
||||||
return ctx.status().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(value = "read/{broadcastAddress}", method = GET)
|
|
||||||
public Broadcasts read(@PathVariable String broadcastAddress) {
|
|
||||||
if ("test".equalsIgnoreCase(broadcastAddress)) {
|
|
||||||
return broadcasts(
|
|
||||||
new BitmessageAddress("BM-2cWhyaPxydemCeM8dWJUBmEo8iu7v2JptK"),
|
|
||||||
message("Test", "This is a test message. The rest service is running."),
|
|
||||||
message("Another Test", "And because it's such fun, a second message.")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
BitmessageAddress broadcaster = ctx.addresses().getAddress(broadcastAddress);
|
|
||||||
if (broadcaster == null) {
|
|
||||||
broadcaster = new BitmessageAddress(broadcastAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!whitelist.isEmpty() && !whitelist.contains(broadcaster.getAddress())) {
|
|
||||||
return broadcasts(broadcaster, message("Not Whitelisted", "Messages for " + broadcaster +
|
|
||||||
" can't be shown, as the sender isn't on the whitelist."));
|
|
||||||
}
|
|
||||||
if (blacklist.contains(broadcaster.getAddress())) {
|
|
||||||
return broadcasts(broadcaster, message("Blacklisted", "Unfortunately, " + broadcaster +
|
|
||||||
" is on the blacklist, so it's messages can't be shown."));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!broadcaster.isSubscribed()) {
|
|
||||||
ctx.addSubscribtion(broadcaster);
|
|
||||||
}
|
|
||||||
List<Plaintext> messages = ctx.messages().findMessages(broadcaster);
|
|
||||||
if (shortlist.contains(broadcaster.getAddress())) {
|
|
||||||
while (messages.size() > SHORTLIST_SIZE) {
|
|
||||||
ctx.messages().remove(messages.get(messages.size() - 1));
|
|
||||||
messages.remove(messages.size() - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return broadcasts(broadcaster, messages);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 0 * * *")
|
|
||||||
public void broadcastStatus() {
|
|
||||||
ctx.broadcast(identity, "Status", ctx.status().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 2 * * *")
|
|
||||||
public void cleanup() {
|
|
||||||
ctx.cleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void setUp() {
|
|
||||||
ctx.startup();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,155 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 Christian Basler
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ch.dissem.bitmessage.server;
|
|
||||||
|
|
||||||
import ch.dissem.bitmessage.InternalContext;
|
|
||||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
|
||||||
import ch.dissem.bitmessage.entity.CustomMessage;
|
|
||||||
import ch.dissem.bitmessage.entity.MessagePayload;
|
|
||||||
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
|
|
||||||
import ch.dissem.bitmessage.exception.DecryptionFailedException;
|
|
||||||
import ch.dissem.bitmessage.extensions.CryptoCustomMessage;
|
|
||||||
import ch.dissem.bitmessage.extensions.pow.ProofOfWorkRequest;
|
|
||||||
import ch.dissem.bitmessage.ports.CustomCommandHandler;
|
|
||||||
import ch.dissem.bitmessage.ports.ProofOfWorkEngine;
|
|
||||||
import ch.dissem.bitmessage.server.repository.ServerProofOfWorkRepository;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static ch.dissem.bitmessage.extensions.pow.ProofOfWorkRequest.Request.CALCULATING;
|
|
||||||
import static ch.dissem.bitmessage.extensions.pow.ProofOfWorkRequest.Request.COMPLETE;
|
|
||||||
import static ch.dissem.bitmessage.utils.UnixTime.DAY;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Christian Basler
|
|
||||||
*/
|
|
||||||
public class ProofOfWorkRequestHandler implements CustomCommandHandler, InternalContext.ContextHolder {
|
|
||||||
private final static Logger LOG = LoggerFactory.getLogger(ProofOfWorkRequestHandler.class);
|
|
||||||
|
|
||||||
private final List<byte[]> decryptionKeys;
|
|
||||||
private final ServerProofOfWorkRepository repo;
|
|
||||||
private BitmessageAddress serverIdentity;
|
|
||||||
private ProofOfWorkEngine engine;
|
|
||||||
private InternalContext context;
|
|
||||||
|
|
||||||
public ProofOfWorkRequestHandler(ServerProofOfWorkRepository repo, Collection<BitmessageAddress> clients) {
|
|
||||||
this.repo = repo;
|
|
||||||
decryptionKeys = clients.stream().map(BitmessageAddress::getPublicDecryptionKey).collect(Collectors.toList());
|
|
||||||
new Timer().schedule(new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
doMissingProofOfWork();
|
|
||||||
}
|
|
||||||
}, 15_000); // After 15 seconds
|
|
||||||
new Timer().schedule(new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
repo.cleanupTasks(7 * DAY);
|
|
||||||
}
|
|
||||||
}, 60_000, DAY * 1000); // First time after 1 minute, then daily
|
|
||||||
}
|
|
||||||
|
|
||||||
public void doMissingProofOfWork() {
|
|
||||||
List<ServerProofOfWorkRepository.Task> incompleteTasks = repo.getIncompleteTasks();
|
|
||||||
LOG.info("Doing POW for " + incompleteTasks.size() + " tasks.");
|
|
||||||
for (ServerProofOfWorkRepository.Task task : incompleteTasks) {
|
|
||||||
engine.calculateNonce(task.initialHash, task.target, repo::updateTask);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MessagePayload handle(CustomMessage message) {
|
|
||||||
CryptoCustomMessage<ProofOfWorkRequest> cryptoMessage = CryptoCustomMessage.read(message,
|
|
||||||
ProofOfWorkRequest::read);
|
|
||||||
ProofOfWorkRequest request = decrypt(cryptoMessage);
|
|
||||||
if (request == null) {
|
|
||||||
return CustomMessage.error(
|
|
||||||
"Unknown sender. Please ask the server's administrator to add you as a client. " +
|
|
||||||
"For this he'll need your identity."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
switch (request.getRequest()) {
|
|
||||||
case CALCULATE:
|
|
||||||
if (!repo.hasTask(request.getInitialHash())) {
|
|
||||||
repo.storeTask(request);
|
|
||||||
// TODO: This is probably the place to do some book-keeping
|
|
||||||
// if we want to bill our customers.
|
|
||||||
engine.calculateNonce(request.getInitialHash(), request.getData(), repo::updateTask);
|
|
||||||
return new CryptoCustomMessage<>(
|
|
||||||
new ProofOfWorkRequest(getIdentity(), request.getInitialHash(), CALCULATING, new byte[0])
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
byte[] nonce = repo.getNonce(request);
|
|
||||||
CryptoCustomMessage<ProofOfWorkRequest> response;
|
|
||||||
if (nonce != null) {
|
|
||||||
response = new CryptoCustomMessage<>(
|
|
||||||
new ProofOfWorkRequest(getIdentity(), request.getInitialHash(), COMPLETE, nonce)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
response = new CryptoCustomMessage<>(
|
|
||||||
new ProofOfWorkRequest(getIdentity(), request.getInitialHash(), CALCULATING, new byte[0])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
response.signAndEncrypt(serverIdentity, request.getSender().getPubkey().getEncryptionKey());
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private BitmessageAddress getIdentity() {
|
|
||||||
if (serverIdentity == null) {
|
|
||||||
synchronized (this) {
|
|
||||||
if (serverIdentity == null) {
|
|
||||||
serverIdentity = context.getAddressRepository().getIdentities().stream().findFirst().orElseGet(() -> {
|
|
||||||
final BitmessageAddress identity = new BitmessageAddress(new PrivateKey(
|
|
||||||
false,
|
|
||||||
context.getStreams()[0],
|
|
||||||
InternalContext.NETWORK_NONCE_TRIALS_PER_BYTE,
|
|
||||||
InternalContext.NETWORK_EXTRA_BYTES
|
|
||||||
));
|
|
||||||
context.getAddressRepository().save(identity);
|
|
||||||
return identity;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return serverIdentity;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ProofOfWorkRequest decrypt(CryptoCustomMessage<ProofOfWorkRequest> cryptoMessage) {
|
|
||||||
for (byte[] key : decryptionKeys) {
|
|
||||||
try {
|
|
||||||
return cryptoMessage.decrypt(key);
|
|
||||||
} catch (DecryptionFailedException ignore) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setContext(InternalContext context) {
|
|
||||||
this.context = context;
|
|
||||||
this.engine = context.getProofOfWorkEngine();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,181 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 Christian Basler
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ch.dissem.bitmessage.server;
|
|
||||||
|
|
||||||
import ch.dissem.bitmessage.BitmessageContext;
|
|
||||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
|
||||||
import ch.dissem.bitmessage.entity.Plaintext;
|
|
||||||
import ch.dissem.bitmessage.entity.valueobject.extended.Message;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
import static ch.dissem.bitmessage.entity.Plaintext.Encoding.EXTENDED;
|
|
||||||
import static ch.dissem.bitmessage.entity.Plaintext.Type.MSG;
|
|
||||||
import static ch.dissem.bitmessage.server.Constants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Christian Basler
|
|
||||||
*/
|
|
||||||
public class ServerListener implements BitmessageContext.Listener.WithContext {
|
|
||||||
private final static Logger LOG = LoggerFactory.getLogger(ServerListener.class);
|
|
||||||
|
|
||||||
private final Collection<BitmessageAddress> admins;
|
|
||||||
private final Collection<BitmessageAddress> clients;
|
|
||||||
|
|
||||||
private final Collection<String> whitelist;
|
|
||||||
private final Collection<String> shortlist;
|
|
||||||
private final Collection<String> blacklist;
|
|
||||||
|
|
||||||
private BitmessageContext ctx;
|
|
||||||
private BitmessageAddress identity;
|
|
||||||
|
|
||||||
public ServerListener(Collection<BitmessageAddress> admins,
|
|
||||||
Collection<BitmessageAddress> clients,
|
|
||||||
Collection<String> whitelist,
|
|
||||||
Collection<String> shortlist,
|
|
||||||
Collection<String> blacklist) {
|
|
||||||
this.admins = admins;
|
|
||||||
this.clients = clients;
|
|
||||||
this.whitelist = whitelist;
|
|
||||||
this.shortlist = shortlist;
|
|
||||||
this.blacklist = blacklist;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setContext(BitmessageContext ctx) {
|
|
||||||
this.ctx = ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
private BitmessageAddress getIdentity() {
|
|
||||||
if (identity == null) {
|
|
||||||
List<BitmessageAddress> identities = ctx.addresses().getIdentities();
|
|
||||||
if (!identities.isEmpty()) {
|
|
||||||
identity = identities.get(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return identity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void receive(Plaintext message) {
|
|
||||||
if (admins.contains(message.getFrom())) {
|
|
||||||
String[] command = message.getSubject().trim().toLowerCase().split("\\s+");
|
|
||||||
String data = message.getText();
|
|
||||||
if (command.length == 1) {
|
|
||||||
switch (command[0].toLowerCase()) {
|
|
||||||
case "status":
|
|
||||||
Plaintext.Builder response = new Plaintext.Builder(MSG);
|
|
||||||
response.from(getIdentity());
|
|
||||||
response.to(message.getFrom());
|
|
||||||
if (message.getEncoding() == EXTENDED) {
|
|
||||||
response.message(
|
|
||||||
new Message.Builder()
|
|
||||||
.subject("RE: status")
|
|
||||||
.body(ctx.status().toString())
|
|
||||||
.addParent(message)
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
response.message("RE: status", ctx.status().toString());
|
|
||||||
}
|
|
||||||
ctx.send(response.build());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LOG.info("ignoring unknown command " + message.getSubject());
|
|
||||||
}
|
|
||||||
} else if (command.length == 2) {
|
|
||||||
switch (command[1].toLowerCase()) {
|
|
||||||
case "client":
|
|
||||||
case "clients":
|
|
||||||
updateUserList(CLIENT_LIST, clients, command[0], data);
|
|
||||||
break;
|
|
||||||
case "admin":
|
|
||||||
case "admins":
|
|
||||||
case "administrator":
|
|
||||||
case "administrators":
|
|
||||||
updateUserList(ADMIN_LIST, admins, command[0], data);
|
|
||||||
break;
|
|
||||||
case "whitelist":
|
|
||||||
updateList(WHITELIST, whitelist, command[0], data);
|
|
||||||
break;
|
|
||||||
case "shortlist":
|
|
||||||
updateList(SHORTLIST, shortlist, command[0], data);
|
|
||||||
break;
|
|
||||||
case "blacklist":
|
|
||||||
updateList(BLACKLIST, blacklist, command[0], data);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LOG.info("ignoring unknown command " + message.getSubject());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateUserList(String file, Collection<BitmessageAddress> list, String command, String data) {
|
|
||||||
switch (command.toLowerCase()) {
|
|
||||||
case "set":
|
|
||||||
list.clear();
|
|
||||||
case "add":
|
|
||||||
Scanner scanner = new Scanner(data);
|
|
||||||
while (scanner.hasNextLine()) {
|
|
||||||
String line = scanner.nextLine();
|
|
||||||
try {
|
|
||||||
list.add(new BitmessageAddress(line));
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.info(command + " " + file + ": ignoring line: " + line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Utils.saveList(file, list.stream().map(BitmessageAddress::getAddress));
|
|
||||||
break;
|
|
||||||
case "remove":
|
|
||||||
list.removeIf(address -> data.contains(address.getAddress()));
|
|
||||||
Utils.saveList(file, list.stream().map(BitmessageAddress::getAddress));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LOG.info("unknown command " + command + " on list " + file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateList(String file, Collection<String> list, String command, String data) {
|
|
||||||
switch (command.toLowerCase()) {
|
|
||||||
case "set":
|
|
||||||
list.clear();
|
|
||||||
case "add":
|
|
||||||
Scanner scanner = new Scanner(data);
|
|
||||||
while (scanner.hasNextLine()) {
|
|
||||||
String line = scanner.nextLine();
|
|
||||||
try {
|
|
||||||
list.add(new BitmessageAddress(line).getAddress());
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.info(command + " " + file + ": ignoring line: " + line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Utils.saveList(file, list.stream());
|
|
||||||
break;
|
|
||||||
case "remove":
|
|
||||||
list.removeIf(data::contains);
|
|
||||||
Utils.saveList(file, list.stream());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LOG.info("unknown command " + command + " on list " + file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,153 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 Christian Basler
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ch.dissem.bitmessage.server;
|
|
||||||
|
|
||||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
|
||||||
import com.google.zxing.WriterException;
|
|
||||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
|
||||||
import com.google.zxing.qrcode.encoder.ByteMatrix;
|
|
||||||
import com.google.zxing.qrcode.encoder.Encoder;
|
|
||||||
import com.google.zxing.qrcode.encoder.QRCode;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
public class Utils {
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
|
|
||||||
|
|
||||||
public static Set<String> readOrCreateList(String filename, String content) {
|
|
||||||
try {
|
|
||||||
File file = new File(filename);
|
|
||||||
if (!file.exists()) {
|
|
||||||
if (file.createNewFile()) {
|
|
||||||
try (FileWriter fw = new FileWriter(file)) {
|
|
||||||
fw.write(content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return readList(file);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void saveList(String filename, Stream<String> content) {
|
|
||||||
try {
|
|
||||||
File file = new File(filename);
|
|
||||||
try (FileWriter fw = new FileWriter(file)) {
|
|
||||||
content.forEach(l -> {
|
|
||||||
try {
|
|
||||||
fw.write(l);
|
|
||||||
fw.write(System.lineSeparator());
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<String> readList(File file) {
|
|
||||||
Set<String> result = new HashSet<>();
|
|
||||||
try {
|
|
||||||
Scanner scanner = new Scanner(file);
|
|
||||||
while (scanner.hasNextLine()) {
|
|
||||||
String line = scanner.nextLine().trim();
|
|
||||||
if (line.startsWith("BM-")) {
|
|
||||||
result.add(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String qrCode(BitmessageAddress address) {
|
|
||||||
StringBuilder link = new StringBuilder();
|
|
||||||
link.append("bitmessage:");
|
|
||||||
link.append(address.getAddress());
|
|
||||||
if (address.getAlias() != null) {
|
|
||||||
link.append("?label=").append(address.getAlias());
|
|
||||||
}
|
|
||||||
// This makes the QR code quite big, so it's not active. But sometimes it might be useful:
|
|
||||||
// if (address.getPubkey() != null) {
|
|
||||||
// link.append(address.getAlias() == null ? '?' : '&');
|
|
||||||
// ByteArrayOutputStream pubkey = new ByteArrayOutputStream();
|
|
||||||
// address.getPubkey().writeUnencrypted(pubkey);
|
|
||||||
// link.append("pubkey=").append(Base64.getUrlEncoder().encodeToString(pubkey.toByteArray()));
|
|
||||||
// }
|
|
||||||
QRCode code;
|
|
||||||
try {
|
|
||||||
code = Encoder.encode(link.toString(), ErrorCorrectionLevel.L, null);
|
|
||||||
} catch (WriterException e) {
|
|
||||||
LOG.error(e.getMessage(), e);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
ByteMatrix matrix = code.getMatrix();
|
|
||||||
StringBuilder result = new StringBuilder();
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
for (int j = 0; j < matrix.getWidth() + 8; j++) {
|
|
||||||
result.append('█');
|
|
||||||
}
|
|
||||||
result.append('\n');
|
|
||||||
}
|
|
||||||
for (int i = 0; i < matrix.getHeight(); i += 2) {
|
|
||||||
result.append("████");
|
|
||||||
for (int j = 0; j < matrix.getWidth(); j++) {
|
|
||||||
if (matrix.get(i, j) > 0) {
|
|
||||||
if (matrix.getHeight() > i + 1 && matrix.get(i + 1, j) > 0) {
|
|
||||||
result.append(' ');
|
|
||||||
} else {
|
|
||||||
result.append('▄');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (matrix.getHeight() > i + 1 && matrix.get(i + 1, j) > 0) {
|
|
||||||
result.append('▀');
|
|
||||||
} else {
|
|
||||||
result.append('█');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result.append("████\n");
|
|
||||||
}
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
for (int j = 0; j < matrix.getWidth() + 8; j++) {
|
|
||||||
result.append('█');
|
|
||||||
}
|
|
||||||
result.append('\n');
|
|
||||||
}
|
|
||||||
return result.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean zero(byte[] nonce) {
|
|
||||||
for (byte b : nonce) {
|
|
||||||
if (b != 0) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,137 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 Christian Basler
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ch.dissem.bitmessage.server.repository;
|
|
||||||
|
|
||||||
import ch.dissem.bitmessage.extensions.pow.ProofOfWorkRequest;
|
|
||||||
import ch.dissem.bitmessage.repository.JdbcConfig;
|
|
||||||
import ch.dissem.bitmessage.repository.JdbcHelper;
|
|
||||||
import ch.dissem.bitmessage.utils.UnixTime;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Christian Basler
|
|
||||||
*/
|
|
||||||
public class ServerProofOfWorkRepository extends JdbcHelper {
|
|
||||||
|
|
||||||
public ServerProofOfWorkRepository(JdbcConfig config) {
|
|
||||||
super(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* client (can be removed once the new IV is returned)
|
|
||||||
* IV (without nonce)
|
|
||||||
* IV (with nonce, can be removed once the new IV is returned)
|
|
||||||
* status: calculating, finished, confirmed
|
|
||||||
* data (can be removed once POW calculation is done)
|
|
||||||
*/
|
|
||||||
public void storeTask(ProofOfWorkRequest request) {
|
|
||||||
try (Connection connection = config.getConnection()) {
|
|
||||||
PreparedStatement ps = connection.prepareStatement(
|
|
||||||
"INSERT INTO ProofOfWorkTask (initial_hash, client, target, timestamp) VALUES (?, ?, ?, ?)");
|
|
||||||
ps.setBytes(1, request.getInitialHash());
|
|
||||||
ps.setString(2, request.getSender().getAddress());
|
|
||||||
ps.setBytes(3, request.getData());
|
|
||||||
ps.setLong(4, UnixTime.now());
|
|
||||||
ps.executeUpdate();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateTask(byte[] initalHash, byte[] nonce) {
|
|
||||||
try (Connection connection = config.getConnection()) {
|
|
||||||
PreparedStatement ps = connection.prepareStatement(
|
|
||||||
"UPDATE ProofOfWorkTask SET nonce = ? WHERE initial_hash = ?");
|
|
||||||
ps.setBytes(1, nonce);
|
|
||||||
ps.setBytes(2, initalHash);
|
|
||||||
ps.executeUpdate();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getNonce(ProofOfWorkRequest request) {
|
|
||||||
try (Connection connection = config.getConnection()) {
|
|
||||||
PreparedStatement ps = connection.prepareStatement("SELECT nonce FROM ProofOfWorkTask WHERE initial_hash = ?");
|
|
||||||
ps.setBytes(1, request.getInitialHash());
|
|
||||||
ResultSet rs = ps.executeQuery();
|
|
||||||
if (rs.next()) {
|
|
||||||
return rs.getBytes(1);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasTask(byte[] initialHash) {
|
|
||||||
try (Connection connection = config.getConnection()) {
|
|
||||||
PreparedStatement ps = connection.prepareStatement("SELECT count(1) FROM ProofOfWorkTask WHERE initial_hash = ?");
|
|
||||||
ps.setBytes(1, initialHash);
|
|
||||||
ResultSet rs = ps.executeQuery();
|
|
||||||
rs.next();
|
|
||||||
return rs.getInt(1) > 0;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Task> getIncompleteTasks() {
|
|
||||||
try (Connection connection = config.getConnection()) {
|
|
||||||
List<Task> result = new LinkedList<>();
|
|
||||||
ResultSet rs = connection.createStatement().executeQuery(
|
|
||||||
"SELECT initial_hash, target FROM ProofOfWorkTask WHERE nonce IS NULL");
|
|
||||||
while (rs.next()) {
|
|
||||||
result.add(new Task(
|
|
||||||
rs.getBytes(1),
|
|
||||||
rs.getBytes(2)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cleanupTasks(long ageInSeconds) {
|
|
||||||
try (Connection connection = config.getConnection()) {
|
|
||||||
PreparedStatement ps = connection.prepareStatement(
|
|
||||||
"DELETE FROM ProofOfWorkTask WHERE timestamp < ?");
|
|
||||||
ps.setLong(1, UnixTime.now() - ageInSeconds);
|
|
||||||
ps.executeUpdate();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Task {
|
|
||||||
public final byte[] initialHash;
|
|
||||||
public final byte[] target;
|
|
||||||
|
|
||||||
private Task(byte[] initialHash, byte[] target) {
|
|
||||||
this.initialHash = initialHash;
|
|
||||||
this.target = target;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
13
src/main/kotlin/ch/dissem/bitmessage/server/Constants.kt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package ch.dissem.bitmessage.server
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by chrigu on 22.11.15.
|
||||||
|
*/
|
||||||
|
object Constants {
|
||||||
|
val ADMIN_LIST = "admins.conf"
|
||||||
|
val CLIENT_LIST = "clients.conf"
|
||||||
|
|
||||||
|
val WHITELIST = "whitelist.conf"
|
||||||
|
val SHORTLIST = "shortlist.conf"
|
||||||
|
val BLACKLIST = "blacklist.conf"
|
||||||
|
}
|
55
src/main/kotlin/ch/dissem/bitmessage/server/Converter.kt
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Christian Basler
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ch.dissem.bitmessage.server
|
||||||
|
|
||||||
|
import ch.dissem.bitmessage.entity.BitmessageAddress
|
||||||
|
import ch.dissem.bitmessage.entity.Plaintext
|
||||||
|
import ch.dissem.bitmessage.server.entities.Broadcasts
|
||||||
|
import ch.dissem.bitmessage.server.entities.Message
|
||||||
|
import ch.dissem.bitmessage.server.entities.Sender
|
||||||
|
import ch.dissem.bitmessage.utils.UnixTime
|
||||||
|
|
||||||
|
object Converter {
|
||||||
|
fun broadcasts(sender: BitmessageAddress, messages: Collection<Plaintext>) = Broadcasts().also {
|
||||||
|
it.sender = sender(sender)
|
||||||
|
it.messages = messages.map { message(it) }.toTypedArray()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun broadcasts(sender: BitmessageAddress, vararg messages: Message) = Broadcasts().also {
|
||||||
|
it.sender = sender(sender)
|
||||||
|
it.messages = arrayOf(*messages)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun sender(sender: BitmessageAddress) = Sender().apply {
|
||||||
|
address = sender.address
|
||||||
|
alias = sender.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun message(subject: String, body: String) = Message().also {
|
||||||
|
it.id = 0
|
||||||
|
it.received = UnixTime.now
|
||||||
|
it.subject = subject
|
||||||
|
it.body = body
|
||||||
|
}
|
||||||
|
|
||||||
|
fun message(plaintext: Plaintext) = Message().apply {
|
||||||
|
id = plaintext.id
|
||||||
|
received = plaintext.sent
|
||||||
|
subject = plaintext.subject
|
||||||
|
body = plaintext.text
|
||||||
|
}
|
||||||
|
}
|
@ -14,19 +14,25 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ch.dissem.bitmessage.server;
|
package ch.dissem.bitmessage.server
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
import org.springframework.scheduling.annotation.EnableScheduling
|
||||||
|
import springfox.documentation.swagger2.annotations.EnableSwagger2
|
||||||
|
|
||||||
@SpringBootApplication
|
|
||||||
@EnableSwagger2
|
@EnableSwagger2
|
||||||
@ComponentScan(basePackageClasses = JabitServerApplication.class)
|
@EnableScheduling
|
||||||
public class JabitServerApplication {
|
@SpringBootApplication
|
||||||
|
@ComponentScan(basePackageClasses = [JabitServerApplication::class])
|
||||||
|
class JabitServerApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
companion object {
|
||||||
SpringApplication.run(JabitServerApplication.class, args);
|
@JvmStatic
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
SpringApplication.run(JabitServerApplication::class.java, *args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
193
src/main/kotlin/ch/dissem/bitmessage/server/JabitServerConfig.kt
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Christian Basler
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ch.dissem.bitmessage.server
|
||||||
|
|
||||||
|
import ch.dissem.bitmessage.BitmessageContext
|
||||||
|
import ch.dissem.bitmessage.cryptography.bc.BouncyCryptography
|
||||||
|
import ch.dissem.bitmessage.entity.BitmessageAddress
|
||||||
|
import ch.dissem.bitmessage.entity.payload.Pubkey
|
||||||
|
import ch.dissem.bitmessage.networking.nio.NioNetworkHandler
|
||||||
|
import ch.dissem.bitmessage.repository.*
|
||||||
|
import ch.dissem.bitmessage.server.Constants.ADMIN_LIST
|
||||||
|
import ch.dissem.bitmessage.server.Constants.BLACKLIST
|
||||||
|
import ch.dissem.bitmessage.server.Constants.CLIENT_LIST
|
||||||
|
import ch.dissem.bitmessage.server.Constants.SHORTLIST
|
||||||
|
import ch.dissem.bitmessage.server.Constants.WHITELIST
|
||||||
|
import ch.dissem.bitmessage.server.repository.ServerProofOfWorkRepository
|
||||||
|
import ch.dissem.bitmessage.utils.Singleton
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import org.springframework.beans.factory.annotation.Value
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import org.springframework.context.annotation.DependsOn
|
||||||
|
import springfox.documentation.spi.DocumentationType
|
||||||
|
import springfox.documentation.spring.web.plugins.Docket
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
class JabitServerConfig {
|
||||||
|
|
||||||
|
@Value("\${bitmessage.port}")
|
||||||
|
private val port: Int = 0
|
||||||
|
@Value("\${bitmessage.connection.ttl.hours}")
|
||||||
|
private val connectionTTL: Long = 0
|
||||||
|
@Value("\${bitmessage.connection.limit}")
|
||||||
|
private val connectionLimit: Int = 0
|
||||||
|
|
||||||
|
@Value("\${database.url}")
|
||||||
|
private lateinit var dbUrl: String
|
||||||
|
@Value("\${database.user}")
|
||||||
|
private lateinit var dbUser: String
|
||||||
|
@Value("\${database.password}")
|
||||||
|
private var dbPassword: String? = null
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun jdbcConfig() = JdbcConfig(dbUrl, dbUser, dbPassword)
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun addressRepo() = JdbcAddressRepository(jdbcConfig())
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun inventory() = JdbcInventory(jdbcConfig())
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun labelRepo() = JdbcLabelRepository(jdbcConfig())
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun messageRepo() = JdbcMessageRepository(jdbcConfig())
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun proofOfWorkRepo() = JdbcProofOfWorkRepository(jdbcConfig())
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun nodeRegistry() = JdbcNodeRegistry(jdbcConfig())
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun networkHandler() = NioNetworkHandler()
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun cryptography() = BouncyCryptography().also {
|
||||||
|
Singleton.initialize(it) // needed for admins and clients
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun serverListener(): BitmessageContext.Listener =
|
||||||
|
ServerListener(
|
||||||
|
admins(), clients(),
|
||||||
|
whitelist(), shortlist(), blacklist()
|
||||||
|
)
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun serverProofOfWorkRepository() = ServerProofOfWorkRepository(jdbcConfig())
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun commandHandler() = ProofOfWorkRequestHandler(serverProofOfWorkRepository(), clients())
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun bitmessageContext() = BitmessageContext.build {
|
||||||
|
addressRepo = addressRepo()
|
||||||
|
inventory = inventory()
|
||||||
|
labelRepo = labelRepo()
|
||||||
|
messageRepo = messageRepo()
|
||||||
|
nodeRegistry = nodeRegistry()
|
||||||
|
proofOfWorkRepo = proofOfWorkRepo()
|
||||||
|
networkHandler = networkHandler()
|
||||||
|
listener = serverListener()
|
||||||
|
customCommandHandler = commandHandler()
|
||||||
|
cryptography = cryptography()
|
||||||
|
preferences.port = port
|
||||||
|
preferences.connectionLimit = connectionLimit
|
||||||
|
preferences.connectionTTL = connectionTTL
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@DependsOn("cryptography")
|
||||||
|
fun admins() = Utils.readOrCreateList(
|
||||||
|
ADMIN_LIST,
|
||||||
|
"""# Admins can send commands to the server.
|
||||||
|
|
|
||||||
|
""".trimMargin()
|
||||||
|
).map { BitmessageAddress(it) }.toMutableSet()
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@DependsOn("cryptography")
|
||||||
|
fun clients() = Utils.readOrCreateList(
|
||||||
|
CLIENT_LIST,
|
||||||
|
"# Clients may send incomplete objects for proof of work.\n"
|
||||||
|
).map { BitmessageAddress(it) }.toMutableSet()
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun whitelist() = Utils.readOrCreateList(
|
||||||
|
WHITELIST,
|
||||||
|
"""# If there are any Bitmessage addresses in the whitelist, only those will be shown.
|
||||||
|
|# blacklist.conf will be ignored, but shortlist.conf will be applied to whitelisted addresses.
|
||||||
|
|
|
||||||
|
""".trimMargin()
|
||||||
|
)
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun shortlist() = Utils.readOrCreateList(
|
||||||
|
SHORTLIST,
|
||||||
|
""""# Broadcasts of these addresses will be restricted to the last $SHORTLIST_SIZE entries.
|
||||||
|
|
|
||||||
|
|# Time Service:
|
||||||
|
|BM-BcbRqcFFSQUUmXFKsPJgVQPSiFA3Xash
|
||||||
|
|
|
||||||
|
|# Q's Aktivlist:
|
||||||
|
|BM-GtT7NLCCAu3HrT7dNTUTY9iDns92Z2ND
|
||||||
|
|
|
||||||
|
""".trimMargin()
|
||||||
|
)
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun blacklist() = Utils.readOrCreateList(
|
||||||
|
BLACKLIST,
|
||||||
|
"""# Bitmessage addresses in this file are being ignored and their broadcasts won't be returned.
|
||||||
|
|
|
||||||
|
""".trimMargin()
|
||||||
|
)
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun api(): Docket = Docket(DocumentationType.SWAGGER_2)
|
||||||
|
.select()
|
||||||
|
.build()
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun identity(): BitmessageAddress {
|
||||||
|
val identities = bitmessageContext().addresses.getIdentities()
|
||||||
|
val identity: BitmessageAddress
|
||||||
|
if (identities.isEmpty()) {
|
||||||
|
LOG.info("Creating new identity...")
|
||||||
|
identity = bitmessageContext().createIdentity(false, Pubkey.Feature.DOES_ACK)
|
||||||
|
LOG.info("Identity " + identity.address + " created.")
|
||||||
|
} else {
|
||||||
|
LOG.info("Identities:")
|
||||||
|
identities.forEach { LOG.info(it.address) }
|
||||||
|
identity = identities[0]
|
||||||
|
if (identities.size > 1) {
|
||||||
|
LOG.info("Using " + identity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOG.info("QR Code:\n" + Utils.qrCode(identity))
|
||||||
|
return identity
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val LOG = LoggerFactory.getLogger(JabitServerConfig::class.java)
|
||||||
|
|
||||||
|
val SHORTLIST_SIZE = 5
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Christian Basler
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ch.dissem.bitmessage.server
|
||||||
|
|
||||||
|
import ch.dissem.bitmessage.BitmessageContext
|
||||||
|
import ch.dissem.bitmessage.entity.BitmessageAddress
|
||||||
|
import ch.dissem.bitmessage.server.Converter.broadcasts
|
||||||
|
import ch.dissem.bitmessage.server.Converter.message
|
||||||
|
import ch.dissem.bitmessage.server.entities.Broadcasts
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled
|
||||||
|
import org.springframework.web.bind.annotation.CrossOrigin
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod.GET
|
||||||
|
import org.springframework.web.bind.annotation.RestController
|
||||||
|
import javax.annotation.PostConstruct
|
||||||
|
import javax.annotation.Resource
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Christian Basler
|
||||||
|
*/
|
||||||
|
@CrossOrigin
|
||||||
|
@RestController
|
||||||
|
class JabitServerController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private lateinit var whitelist: Set<String>
|
||||||
|
@Resource
|
||||||
|
private lateinit var shortlist: Set<String>
|
||||||
|
@Resource
|
||||||
|
private lateinit var blacklist: Set<String>
|
||||||
|
@Inject
|
||||||
|
private lateinit var identity: BitmessageAddress
|
||||||
|
@Inject
|
||||||
|
private lateinit var ctx: BitmessageContext
|
||||||
|
|
||||||
|
@RequestMapping(value = ["identity"], method = [GET], produces = ["application/json"])
|
||||||
|
fun identity() = """{
|
||||||
|
"address": "${identity.address}",
|
||||||
|
"uri": "${Utils.getURL(identity, true)}"
|
||||||
|
}"""
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value = ["status"], method = [GET], produces = ["application/json"])
|
||||||
|
fun status() = "{${ctx.status()}}"
|
||||||
|
|
||||||
|
@RequestMapping(value = ["read/{broadcastAddress}"], method = [GET])
|
||||||
|
fun read(@PathVariable broadcastAddress: String): Broadcasts {
|
||||||
|
if ("test".equals(broadcastAddress, ignoreCase = true)) {
|
||||||
|
return broadcasts(
|
||||||
|
BitmessageAddress("BM-2cWhyaPxydemCeM8dWJUBmEo8iu7v2JptK"),
|
||||||
|
message("Test", "This is a test message. The rest service is running."),
|
||||||
|
message("Another Test", "And because it's such fun, a second message.")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
var broadcaster = ctx.addresses.getAddress(broadcastAddress)
|
||||||
|
if (broadcaster == null) {
|
||||||
|
broadcaster = BitmessageAddress(broadcastAddress)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!whitelist.isEmpty() && !whitelist.contains(broadcaster.address)) {
|
||||||
|
return broadcasts(broadcaster, message("Not Whitelisted", "Messages for " + broadcaster +
|
||||||
|
" can't be shown, as the sender isn't on the whitelist."))
|
||||||
|
}
|
||||||
|
if (blacklist.contains(broadcaster.address)) {
|
||||||
|
return broadcasts(broadcaster, message("Blacklisted", "Unfortunately, " + broadcaster +
|
||||||
|
" is on the blacklist, so it's messages can't be shown."))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!broadcaster.isSubscribed) {
|
||||||
|
ctx.addSubscribtion(broadcaster)
|
||||||
|
}
|
||||||
|
val messages = ctx.messages.findMessages(broadcaster)
|
||||||
|
return if (shortlist.contains(broadcaster.address) && messages.size > SHORTLIST_SIZE) {
|
||||||
|
messages.listIterator(SHORTLIST_SIZE).forEach { ctx.messages.remove(it) }
|
||||||
|
broadcasts(broadcaster, messages.subList(0, SHORTLIST_SIZE))
|
||||||
|
} else {
|
||||||
|
broadcasts(broadcaster, messages)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 0 * * *")
|
||||||
|
fun broadcastStatus() = ctx.broadcast(identity, "Status", ctx.status().toString())
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 2 * * *")
|
||||||
|
fun cleanup() = ctx.cleanup()
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
fun setUp() = ctx.startup()
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val SHORTLIST_SIZE = 5
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Christian Basler
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ch.dissem.bitmessage.server
|
||||||
|
|
||||||
|
import ch.dissem.bitmessage.InternalContext
|
||||||
|
import ch.dissem.bitmessage.entity.BitmessageAddress
|
||||||
|
import ch.dissem.bitmessage.entity.CustomMessage
|
||||||
|
import ch.dissem.bitmessage.entity.MessagePayload
|
||||||
|
import ch.dissem.bitmessage.entity.valueobject.PrivateKey
|
||||||
|
import ch.dissem.bitmessage.exception.DecryptionFailedException
|
||||||
|
import ch.dissem.bitmessage.extensions.CryptoCustomMessage
|
||||||
|
import ch.dissem.bitmessage.extensions.pow.ProofOfWorkRequest
|
||||||
|
import ch.dissem.bitmessage.extensions.pow.ProofOfWorkRequest.Request.CALCULATING
|
||||||
|
import ch.dissem.bitmessage.extensions.pow.ProofOfWorkRequest.Request.COMPLETE
|
||||||
|
import ch.dissem.bitmessage.ports.CustomCommandHandler
|
||||||
|
import ch.dissem.bitmessage.ports.ProofOfWorkEngine
|
||||||
|
import ch.dissem.bitmessage.server.repository.ServerProofOfWorkRepository
|
||||||
|
import ch.dissem.bitmessage.utils.UnixTime.DAY
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.concurrent.schedule
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Christian Basler
|
||||||
|
*/
|
||||||
|
class ProofOfWorkRequestHandler(private val repo: ServerProofOfWorkRepository, clients: Collection<BitmessageAddress>) : CustomCommandHandler, InternalContext.ContextHolder {
|
||||||
|
|
||||||
|
private val decryptionKeys = clients.map { it.publicDecryptionKey }
|
||||||
|
private lateinit var engine: ProofOfWorkEngine
|
||||||
|
private lateinit var context: InternalContext
|
||||||
|
|
||||||
|
private val identity: BitmessageAddress by lazy {
|
||||||
|
context.addressRepository.getIdentities().firstOrNull() ?: BitmessageAddress(PrivateKey(
|
||||||
|
false,
|
||||||
|
context.streams[0],
|
||||||
|
InternalContext.NETWORK_NONCE_TRIALS_PER_BYTE,
|
||||||
|
InternalContext.NETWORK_EXTRA_BYTES
|
||||||
|
)).also { context.addressRepository.save(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
Timer().schedule(15000) {
|
||||||
|
doMissingProofOfWork()
|
||||||
|
} // wait 15 seconds
|
||||||
|
Timer().schedule(60000, DAY * 1000) {
|
||||||
|
repo.cleanupTasks(7 * DAY)
|
||||||
|
} // First time after 1 minute, then daily
|
||||||
|
}
|
||||||
|
|
||||||
|
fun doMissingProofOfWork() {
|
||||||
|
val incompleteTasks = repo.getIncompleteTasks()
|
||||||
|
LOG.info("Doing POW for ${incompleteTasks.size} tasks.")
|
||||||
|
for (task in incompleteTasks) {
|
||||||
|
engine.calculateNonce(task.initialHash, task.target) { initalHash, nonce -> repo.updateTask(initalHash, nonce) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun handle(request: CustomMessage): MessagePayload? {
|
||||||
|
val cryptoMessage = CryptoCustomMessage.read(request) { client, input ->
|
||||||
|
ProofOfWorkRequest.read(client, input)
|
||||||
|
}
|
||||||
|
val decryptedRequest = decrypt(cryptoMessage) ?: return CustomMessage.error(
|
||||||
|
"Unknown sender. Please ask the server's administrator to add you as a client. For this he'll need your identity."
|
||||||
|
)
|
||||||
|
when (decryptedRequest.request) {
|
||||||
|
ProofOfWorkRequest.Request.CALCULATE -> {
|
||||||
|
if (!repo.hasTask(decryptedRequest.initialHash)) {
|
||||||
|
repo.storeTask(decryptedRequest)
|
||||||
|
// TODO: This is probably the place to do some book-keeping
|
||||||
|
// if we want to bill our customers.
|
||||||
|
engine.calculateNonce(decryptedRequest.initialHash, decryptedRequest.data) { initalHash, nonce -> repo.updateTask(initalHash, nonce) }
|
||||||
|
return CryptoCustomMessage(
|
||||||
|
ProofOfWorkRequest(identity, decryptedRequest.initialHash, CALCULATING, ByteArray(0))
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
val nonce = repo.getNonce(decryptedRequest)
|
||||||
|
return CryptoCustomMessage(
|
||||||
|
if (nonce != null) {
|
||||||
|
ProofOfWorkRequest(identity, decryptedRequest.initialHash, COMPLETE, nonce)
|
||||||
|
} else {
|
||||||
|
ProofOfWorkRequest(identity, decryptedRequest.initialHash, CALCULATING, ByteArray(0))
|
||||||
|
}
|
||||||
|
).apply { signAndEncrypt(identity, decryptedRequest.sender.pubkey!!.encryptionKey) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun decrypt(cryptoMessage: CryptoCustomMessage<ProofOfWorkRequest>): ProofOfWorkRequest? {
|
||||||
|
for (key in decryptionKeys) {
|
||||||
|
try {
|
||||||
|
return cryptoMessage.decrypt(key)
|
||||||
|
} catch (_: DecryptionFailedException) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setContext(context: InternalContext) {
|
||||||
|
this.context = context
|
||||||
|
this.engine = context.proofOfWorkEngine
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val LOG = LoggerFactory.getLogger(ProofOfWorkRequestHandler::class.java)
|
||||||
|
}
|
||||||
|
}
|
171
src/main/kotlin/ch/dissem/bitmessage/server/ServerListener.kt
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Christian Basler
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ch.dissem.bitmessage.server
|
||||||
|
|
||||||
|
import ch.dissem.bitmessage.BitmessageContext
|
||||||
|
import ch.dissem.bitmessage.entity.BitmessageAddress
|
||||||
|
import ch.dissem.bitmessage.entity.Plaintext
|
||||||
|
import ch.dissem.bitmessage.entity.Plaintext.Encoding.EXTENDED
|
||||||
|
import ch.dissem.bitmessage.entity.Plaintext.Type.MSG
|
||||||
|
import ch.dissem.bitmessage.entity.valueobject.extended.Message
|
||||||
|
import ch.dissem.bitmessage.server.Constants.ADMIN_LIST
|
||||||
|
import ch.dissem.bitmessage.server.Constants.BLACKLIST
|
||||||
|
import ch.dissem.bitmessage.server.Constants.CLIENT_LIST
|
||||||
|
import ch.dissem.bitmessage.server.Constants.SHORTLIST
|
||||||
|
import ch.dissem.bitmessage.server.Constants.WHITELIST
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Christian Basler
|
||||||
|
*/
|
||||||
|
class ServerListener(private val admins: MutableCollection<BitmessageAddress>,
|
||||||
|
private val clients: MutableCollection<BitmessageAddress>,
|
||||||
|
private val whitelist: MutableCollection<String>,
|
||||||
|
private val shortlist: MutableCollection<String>,
|
||||||
|
private val blacklist: MutableCollection<String>) : BitmessageContext.Listener.WithContext {
|
||||||
|
|
||||||
|
private lateinit var ctx: BitmessageContext
|
||||||
|
private val identity: BitmessageAddress by lazy {
|
||||||
|
val identities = ctx.addresses.getIdentities()
|
||||||
|
if (identities.isEmpty()) {
|
||||||
|
ctx.createIdentity(false)
|
||||||
|
} else {
|
||||||
|
identities[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setContext(ctx: BitmessageContext) {
|
||||||
|
this.ctx = ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun receive(plaintext: Plaintext) {
|
||||||
|
if (admins.contains(plaintext.from)) {
|
||||||
|
val command = plaintext.subject!!.trim { it <= ' ' }.toLowerCase().split("\\s+".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||||
|
val data = plaintext.text
|
||||||
|
if (command.size == 1) {
|
||||||
|
when (command[0].toLowerCase()) {
|
||||||
|
"status" -> {
|
||||||
|
val response = Plaintext.Builder(MSG)
|
||||||
|
response.from(identity)
|
||||||
|
response.to(plaintext.from)
|
||||||
|
if (plaintext.encoding == EXTENDED) {
|
||||||
|
response.message(
|
||||||
|
Message.Builder()
|
||||||
|
.subject("RE: status")
|
||||||
|
.body(ctx.status().toString())
|
||||||
|
.addParent(plaintext)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
response.message("RE: status", ctx.status().toString())
|
||||||
|
}
|
||||||
|
ctx.send(response.build())
|
||||||
|
}
|
||||||
|
else -> LOG.info("ignoring unknown command " + plaintext.subject!!)
|
||||||
|
}
|
||||||
|
} else if (command.size == 2) {
|
||||||
|
when (command[1].toLowerCase()) {
|
||||||
|
"client", "clients" -> updateUserList(CLIENT_LIST, clients, command[0], data)
|
||||||
|
"admin", "admins", "administrator", "administrators" -> updateUserList(ADMIN_LIST, admins, command[0], data)
|
||||||
|
"whitelist" -> updateList(WHITELIST, whitelist, command[0], data)
|
||||||
|
"shortlist" -> updateList(SHORTLIST, shortlist, command[0], data)
|
||||||
|
"blacklist" -> updateList(BLACKLIST, blacklist, command[0], data)
|
||||||
|
else -> LOG.info("ignoring unknown command " + plaintext.subject!!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateUserList(file: String, list: MutableCollection<BitmessageAddress>, command: String, data: String?) {
|
||||||
|
when (command.toLowerCase()) {
|
||||||
|
"set" -> {
|
||||||
|
list.clear()
|
||||||
|
val scanner = Scanner(data!!)
|
||||||
|
while (scanner.hasNextLine()) {
|
||||||
|
val line = scanner.nextLine()
|
||||||
|
try {
|
||||||
|
list.add(BitmessageAddress(line))
|
||||||
|
} catch (e: Exception) {
|
||||||
|
LOG.info("$command $file: ignoring line: $line")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Utils.saveList(file, list.map { it.address })
|
||||||
|
}
|
||||||
|
"add" -> {
|
||||||
|
val scanner = Scanner(data!!)
|
||||||
|
while (scanner.hasNextLine()) {
|
||||||
|
val line = scanner.nextLine()
|
||||||
|
try {
|
||||||
|
list.add(BitmessageAddress(line))
|
||||||
|
} catch (e: Exception) {
|
||||||
|
LOG.info("$command $file: ignoring line: $line")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Utils.saveList(file, list.map { it.address })
|
||||||
|
}
|
||||||
|
"remove" -> {
|
||||||
|
list.removeIf { address -> data!!.contains(address.address) }
|
||||||
|
Utils.saveList(file, list.map { it.address })
|
||||||
|
}
|
||||||
|
else -> LOG.info("unknown command $command on list $file")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateList(file: String, list: MutableCollection<String>, command: String, data: String?) {
|
||||||
|
when (command.toLowerCase()) {
|
||||||
|
"set" -> {
|
||||||
|
list.clear()
|
||||||
|
val scanner = Scanner(data!!)
|
||||||
|
while (scanner.hasNextLine()) {
|
||||||
|
val line = scanner.nextLine()
|
||||||
|
try {
|
||||||
|
list.add(BitmessageAddress(line).address)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
LOG.info("$command $file: ignoring line: $line")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Utils.saveList(file, list)
|
||||||
|
}
|
||||||
|
"add" -> {
|
||||||
|
val scanner = Scanner(data!!)
|
||||||
|
while (scanner.hasNextLine()) {
|
||||||
|
val line = scanner.nextLine()
|
||||||
|
try {
|
||||||
|
list.add(BitmessageAddress(line).address)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
LOG.info("$command $file: ignoring line: $line")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Utils.saveList(file, list)
|
||||||
|
}
|
||||||
|
"remove" -> {
|
||||||
|
list.removeAll { data!!.contains(it) }
|
||||||
|
Utils.saveList(file, list)
|
||||||
|
}
|
||||||
|
else -> LOG.info("unknown command $command on list $file")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val LOG = LoggerFactory.getLogger(ServerListener::class.java)
|
||||||
|
}
|
||||||
|
}
|
@ -14,16 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ch.dissem.bitmessage.server;
|
package ch.dissem.bitmessage.server
|
||||||
|
|
||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
import org.springframework.boot.builder.SpringApplicationBuilder
|
||||||
import org.springframework.boot.context.web.SpringBootServletInitializer;
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer
|
||||||
|
|
||||||
public class ServletInitializer extends SpringBootServletInitializer {
|
class ServletInitializer : SpringBootServletInitializer() {
|
||||||
|
|
||||||
@Override
|
override fun configure(application: SpringApplicationBuilder): SpringApplicationBuilder {
|
||||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
return application.sources(JabitServerApplication::class.java)
|
||||||
return application.sources(JabitServerApplication.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
129
src/main/kotlin/ch/dissem/bitmessage/server/Utils.kt
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Christian Basler
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ch.dissem.bitmessage.server
|
||||||
|
|
||||||
|
import ch.dissem.bitmessage.entity.BitmessageAddress
|
||||||
|
import com.google.zxing.WriterException
|
||||||
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
|
||||||
|
import com.google.zxing.qrcode.encoder.Encoder
|
||||||
|
import com.google.zxing.qrcode.encoder.QRCode
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileWriter
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
object Utils {
|
||||||
|
private val LOG = LoggerFactory.getLogger(Utils::class.java)
|
||||||
|
|
||||||
|
fun readOrCreateList(filename: String, content: String): MutableSet<String> {
|
||||||
|
val file = File(filename).apply {
|
||||||
|
if (!exists()) {
|
||||||
|
if (createNewFile()) {
|
||||||
|
FileWriter(this).use { fw -> fw.write(content) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return readList(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun saveList(filename: String, content: Collection<String>) {
|
||||||
|
FileWriter(filename).use { fw ->
|
||||||
|
content.forEach { l ->
|
||||||
|
fw.write(l)
|
||||||
|
fw.write(System.lineSeparator())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun readList(file: File) = Files.readAllLines(file.toPath())
|
||||||
|
.map { it.trim { it <= ' ' } }
|
||||||
|
.filter { it.startsWith("BM-") }
|
||||||
|
.toMutableSet()
|
||||||
|
|
||||||
|
fun getURL(address: BitmessageAddress, includeKey: Boolean): String {
|
||||||
|
val attributes = mutableListOf<String>()
|
||||||
|
if (address.alias != null) {
|
||||||
|
attributes.add("label=${address.alias}")
|
||||||
|
}
|
||||||
|
if (includeKey) {
|
||||||
|
address.pubkey?.let { pubkey ->
|
||||||
|
val out = ByteArrayOutputStream()
|
||||||
|
pubkey.writer().writeUnencrypted(out)
|
||||||
|
attributes.add("pubkey=${Base64.getUrlEncoder().encodeToString(out.toByteArray())}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return if (attributes.isEmpty()) {
|
||||||
|
"bitmessage:${address.address}"
|
||||||
|
} else {
|
||||||
|
"bitmessage:${address.address}?${attributes.joinToString(separator = "&")}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun qrCode(address: BitmessageAddress): String {
|
||||||
|
val code: QRCode
|
||||||
|
try {
|
||||||
|
code = Encoder.encode(getURL(address, false), ErrorCorrectionLevel.L, null)
|
||||||
|
} catch (e: WriterException) {
|
||||||
|
LOG.error(e.message, e)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
val matrix = code.matrix
|
||||||
|
val result = StringBuilder()
|
||||||
|
for (i in 0..1) {
|
||||||
|
for (j in 0 until matrix.width + 8) {
|
||||||
|
result.append('█')
|
||||||
|
}
|
||||||
|
result.append('\n')
|
||||||
|
}
|
||||||
|
run {
|
||||||
|
var i = 0
|
||||||
|
while (i < matrix.height) {
|
||||||
|
result.append("████")
|
||||||
|
for (j in 0 until matrix.width) {
|
||||||
|
if (matrix.get(i, j) > 0) {
|
||||||
|
if (matrix.height > i + 1 && matrix.get(i + 1, j) > 0) {
|
||||||
|
result.append(' ')
|
||||||
|
} else {
|
||||||
|
result.append('▄')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (matrix.height > i + 1 && matrix.get(i + 1, j) > 0) {
|
||||||
|
result.append('▀')
|
||||||
|
} else {
|
||||||
|
result.append('█')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.append("████\n")
|
||||||
|
i += 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i in 0..1) {
|
||||||
|
for (j in 0 until matrix.width + 8) {
|
||||||
|
result.append('█')
|
||||||
|
}
|
||||||
|
result.append('\n')
|
||||||
|
}
|
||||||
|
return result.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun zero(nonce: ByteArray) = nonce.none { it.toInt() != 0 }
|
||||||
|
}
|
@ -14,17 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ch.dissem.bitmessage.server.entities;
|
package ch.dissem.bitmessage.server.entities
|
||||||
|
|
||||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
|
||||||
import ch.dissem.bitmessage.entity.Plaintext;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSON representation for the broadcasts of a specific sender
|
* JSON representation for the broadcasts of a specific sender
|
||||||
*/
|
*/
|
||||||
public class Broadcasts {
|
data class Broadcasts(
|
||||||
public Sender sender;
|
var sender: Sender? = null,
|
||||||
public Message[] messages;
|
var messages: Array<Message> = emptyArray()
|
||||||
}
|
)
|
@ -14,20 +14,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ch.dissem.bitmessage.server.entities;
|
package ch.dissem.bitmessage.server.entities
|
||||||
|
|
||||||
import ch.dissem.bitmessage.entity.Plaintext;
|
|
||||||
import ch.dissem.bitmessage.utils.UnixTime;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSON representation for plaintext messages
|
* JSON representation for plaintext messages
|
||||||
*/
|
*/
|
||||||
public class Message {
|
data class Message(
|
||||||
public Object id;
|
var id: Any? = null,
|
||||||
public Long received;
|
var received: Long? = null,
|
||||||
public String subject;
|
var subject: String? = null,
|
||||||
public String body;
|
var body: String? = null
|
||||||
}
|
)
|
@ -14,14 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ch.dissem.bitmessage.server.entities;
|
package ch.dissem.bitmessage.server.entities
|
||||||
|
|
||||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSON representation for a BitmessageAddress
|
* JSON representation for a BitmessageAddress
|
||||||
*/
|
*/
|
||||||
public class Sender {
|
data class Sender(
|
||||||
public String address;
|
var address: String? = null,
|
||||||
public String alias;
|
var alias: String? = null
|
||||||
}
|
)
|
@ -14,17 +14,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ch.dissem.bitmessage.server.entities;
|
package ch.dissem.bitmessage.server.entities
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christian Basler
|
* @author Christian Basler
|
||||||
*/
|
*/
|
||||||
public class Update<T> {
|
data class Update<T>(val oldValue: T, val newValue: T)
|
||||||
public final T oldValue;
|
|
||||||
public final T newValue;
|
|
||||||
|
|
||||||
public Update(T oldValue, T newValue) {
|
|
||||||
this.oldValue = oldValue;
|
|
||||||
this.newValue = newValue;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Christian Basler
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ch.dissem.bitmessage.server.repository
|
||||||
|
|
||||||
|
import ch.dissem.bitmessage.extensions.pow.ProofOfWorkRequest
|
||||||
|
import ch.dissem.bitmessage.repository.JdbcConfig
|
||||||
|
import ch.dissem.bitmessage.repository.JdbcHelper
|
||||||
|
import ch.dissem.bitmessage.utils.UnixTime
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Christian Basler
|
||||||
|
*/
|
||||||
|
class ServerProofOfWorkRepository(config: JdbcConfig) : JdbcHelper(config) {
|
||||||
|
|
||||||
|
fun getIncompleteTasks(): List<Task> {
|
||||||
|
config.getConnection().use { connection ->
|
||||||
|
val result = LinkedList<Task>()
|
||||||
|
val rs = connection.createStatement().executeQuery(
|
||||||
|
"SELECT initial_hash, target FROM ProofOfWorkTask WHERE nonce IS NULL")
|
||||||
|
while (rs.next()) {
|
||||||
|
result.add(Task(
|
||||||
|
rs.getBytes(1),
|
||||||
|
rs.getBytes(2)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* client (can be removed once the new IV is returned)
|
||||||
|
* IV (without nonce)
|
||||||
|
* IV (with nonce, can be removed once the new IV is returned)
|
||||||
|
* status: calculating, finished, confirmed
|
||||||
|
* data (can be removed once POW calculation is done)
|
||||||
|
*/
|
||||||
|
fun storeTask(request: ProofOfWorkRequest) {
|
||||||
|
config.getConnection().use { connection ->
|
||||||
|
val ps = connection.prepareStatement(
|
||||||
|
"INSERT INTO ProofOfWorkTask (initial_hash, client, target, timestamp) VALUES (?, ?, ?, ?)")
|
||||||
|
ps.setBytes(1, request.initialHash)
|
||||||
|
ps.setString(2, request.sender.address)
|
||||||
|
ps.setBytes(3, request.data)
|
||||||
|
ps.setLong(4, UnixTime.now)
|
||||||
|
ps.executeUpdate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateTask(initalHash: ByteArray, nonce: ByteArray) {
|
||||||
|
config.getConnection().use { connection ->
|
||||||
|
val ps = connection.prepareStatement(
|
||||||
|
"UPDATE ProofOfWorkTask SET nonce = ? WHERE initial_hash = ?")
|
||||||
|
ps.setBytes(1, nonce)
|
||||||
|
ps.setBytes(2, initalHash)
|
||||||
|
ps.executeUpdate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getNonce(request: ProofOfWorkRequest): ByteArray? {
|
||||||
|
config.getConnection().use { connection ->
|
||||||
|
val ps = connection.prepareStatement("SELECT nonce FROM ProofOfWorkTask WHERE initial_hash = ?")
|
||||||
|
ps.setBytes(1, request.initialHash)
|
||||||
|
val rs = ps.executeQuery()
|
||||||
|
return if (rs.next()) {
|
||||||
|
rs.getBytes(1)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hasTask(initialHash: ByteArray): Boolean {
|
||||||
|
config.getConnection().use { connection ->
|
||||||
|
val ps = connection.prepareStatement("SELECT count(1) FROM ProofOfWorkTask WHERE initial_hash = ?")
|
||||||
|
ps.setBytes(1, initialHash)
|
||||||
|
val rs = ps.executeQuery()
|
||||||
|
rs.next()
|
||||||
|
return rs.getInt(1) > 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun cleanupTasks(ageInSeconds: Long) {
|
||||||
|
config.getConnection().use { connection ->
|
||||||
|
val ps = connection.prepareStatement(
|
||||||
|
"DELETE FROM ProofOfWorkTask WHERE timestamp < ?")
|
||||||
|
ps.setLong(1, UnixTime.now - ageInSeconds)
|
||||||
|
ps.executeUpdate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Task internal constructor(val initialHash: ByteArray, val target: ByteArray)
|
||||||
|
}
|
@ -1,18 +0,0 @@
|
|||||||
package ch.dissem.bitmessage.server;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
import org.springframework.test.context.web.WebAppConfiguration;
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@SpringApplicationConfiguration(classes = JabitServerApplication.class)
|
|
||||||
@WebAppConfiguration
|
|
||||||
public class JabitServerApplicationTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void contextLoads() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,17 @@
|
|||||||
|
package ch.dissem.bitmessage.server
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||||
|
import org.springframework.test.context.web.WebAppConfiguration
|
||||||
|
|
||||||
|
@WebAppConfiguration
|
||||||
|
@RunWith(SpringJUnit4ClassRunner::class)
|
||||||
|
@SpringBootTest(classes = [JabitServerApplication::class])
|
||||||
|
class JabitServerApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun contextLoads() = Unit
|
||||||
|
|
||||||
|
}
|
@ -1,21 +0,0 @@
|
|||||||
# EditorConfig helps developers define and maintain consistent
|
|
||||||
# coding styles between different editors and IDEs
|
|
||||||
# editorconfig.org
|
|
||||||
|
|
||||||
root = true
|
|
||||||
|
|
||||||
|
|
||||||
[*]
|
|
||||||
|
|
||||||
# Change these settings to your own preference
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 2
|
|
||||||
|
|
||||||
# We recommend you to keep these unchanged
|
|
||||||
end_of_line = lf
|
|
||||||
charset = utf-8
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
insert_final_newline = true
|
|
||||||
|
|
||||||
[*.md]
|
|
||||||
trim_trailing_whitespace = false
|
|
1
webapp/.gitattributes
vendored
@ -1 +0,0 @@
|
|||||||
* text=auto
|
|
4
webapp/.gitignore
vendored
@ -1,4 +0,0 @@
|
|||||||
node_modules
|
|
||||||
dist
|
|
||||||
bower_components
|
|
||||||
.tmp
|
|
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"preset": "google",
|
|
||||||
"disallowSpacesInAnonymousFunctionExpression": null,
|
|
||||||
"excludeFiles": ["node_modules/**"]
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
{
|
|
||||||
"node": true,
|
|
||||||
"browser": true,
|
|
||||||
"bitwise": true,
|
|
||||||
"camelcase": true,
|
|
||||||
"curly": true,
|
|
||||||
"eqeqeq": true,
|
|
||||||
"immed": true,
|
|
||||||
"indent": 2,
|
|
||||||
"latedef": true,
|
|
||||||
"noarg": true,
|
|
||||||
"quotmark": "single",
|
|
||||||
"undef": true,
|
|
||||||
"unused": true,
|
|
||||||
"newcap": false,
|
|
||||||
"globals": {
|
|
||||||
"wrap": true,
|
|
||||||
"unwrap": true,
|
|
||||||
"Polymer": true,
|
|
||||||
"Platform": true,
|
|
||||||
"page": true,
|
|
||||||
"app": true
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
# License
|
|
||||||
|
|
||||||
Everything in this repo is BSD style license unless otherwise specified.
|
|
||||||
|
|
||||||
Copyright (c) 2015 The Polymer Authors. All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
* Redistributions in binary form must reproduce the above
|
|
||||||
copyright notice, this list of conditions and the following disclaimer
|
|
||||||
in the documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
* Neither the name of Google Inc. nor the names of its
|
|
||||||
contributors may be used to endorse or promote products derived from
|
|
||||||
this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
364
webapp/README.md
@ -1,364 +0,0 @@
|
|||||||
![](https://cloud.githubusercontent.com/assets/110953/7877439/6a69d03e-0590-11e5-9fac-c614246606de.png)
|
|
||||||
## Polymer Starter Kit
|
|
||||||
|
|
||||||
> A starting point for building web applications with Polymer 1.0
|
|
||||||
|
|
||||||
### Included out of the box:
|
|
||||||
|
|
||||||
* [Polymer](http://polymer-project.org), [Paper](https://elements.polymer-project.org/browse?package=paper-elements), [Iron](https://elements.polymer-project.org/browse?package=iron-elements) and [Neon](https://elements.polymer-project.org/browse?package=neon-elements) elements
|
|
||||||
* [Material Design](http://www.google.com/design/spec/material-design/introduction.html) layout
|
|
||||||
* Routing with [Page.js](https://visionmedia.github.io/page.js/)
|
|
||||||
* Unit testing with [Web Component Tester](https://github.com/Polymer/web-component-tester)
|
|
||||||
* Optional offline setup through [Platinum](https://elements.polymer-project.org/browse?package=platinum-elements) Service Worker elements
|
|
||||||
* End-to-end Build Tooling (including [Vulcanize](https://github.com/Polymer/vulcanize))
|
|
||||||
|
|
||||||
## Getting Started
|
|
||||||
|
|
||||||
To take advantage of Polymer Starter Kit you need to:
|
|
||||||
|
|
||||||
1. Get a copy of the code.
|
|
||||||
2. Install the dependencies if you don't already have them.
|
|
||||||
3. Modify the application to your liking.
|
|
||||||
4. Deploy your production code.
|
|
||||||
|
|
||||||
### Get the code
|
|
||||||
|
|
||||||
[Download](https://github.com/polymerelements/polymer-starter-kit/releases/latest) and extract Polymer Starter Kit to where you want to work. The project comes in two flavours - Light and Full.
|
|
||||||
|
|
||||||
**Beginners**: Try Polymer Starter Kit Light. This doesn't require any extra dependencies nor knowledge of modern front-end tooling. This option is good for prototyping if you haven't build a Polymer app before.
|
|
||||||
|
|
||||||
**Intermediate - Advanced**: Use the full version of Polymer Starter Kit. This comes with all the build tools you'll need for testing and productionising your app so it's nice and lean. You'll need to run a few extra commands to install the tools we recommend but it's worth it to make sure your final app is super optimised.
|
|
||||||
|
|
||||||
Rob Dodson has a fantastic [PolyCast video](https://www.youtube.com/watch?v=xz-yixRxZN8) available that walks through using Polymer Starter Kit. An [end-to-end with Polymer](https://www.youtube.com/watch?v=1f_Tj_JnStA) and Polymer Starter Kit talk is also available.
|
|
||||||
|
|
||||||
### Install dependencies
|
|
||||||
|
|
||||||
#### Quick-start (for experienced users)
|
|
||||||
|
|
||||||
With Node.js installed, run the following one liner from the root of your Polymer Starter Kit download:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm install -g gulp bower && npm install && bower install
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Prerequisites (for everyone)
|
|
||||||
|
|
||||||
The full starter kit requires the following major dependencies:
|
|
||||||
|
|
||||||
- Node.js, used to run JavaScript tools from the command line.
|
|
||||||
- npm, the node package manager, installed with Node.js and used to install Node.js packages.
|
|
||||||
- gulp, a Node.js-based build tool.
|
|
||||||
- bower, a Node.js-based package manager used to install front-end packages (like Polymer).
|
|
||||||
|
|
||||||
**To install dependencies:**
|
|
||||||
|
|
||||||
1) Check your Node.js version.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
node --version
|
|
||||||
```
|
|
||||||
|
|
||||||
The version should be at or above 0.12.x.
|
|
||||||
|
|
||||||
2) If you don't have Node.js installed, or you have a lower version, go to [nodejs.org](https://nodejs.org) and click on the big green Install button.
|
|
||||||
|
|
||||||
3) Install `gulp` and `bower` globally.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm install -g gulp bower
|
|
||||||
```
|
|
||||||
|
|
||||||
This lets you run `gulp` and `bower` from the command line.
|
|
||||||
|
|
||||||
4) Install the starter kit's local `npm` and `bower` dependencies.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
cd polymer-starter-kit && npm install && bower install
|
|
||||||
```
|
|
||||||
|
|
||||||
This installs the element sets (Paper, Iron, Platinum) and tools the starter kit requires to build and serve apps.
|
|
||||||
|
|
||||||
### Development workflow
|
|
||||||
|
|
||||||
#### Serve / watch
|
|
||||||
|
|
||||||
```sh
|
|
||||||
gulp serve
|
|
||||||
```
|
|
||||||
|
|
||||||
This outputs an IP address you can use to locally test and another that can be used on devices connected to your network.
|
|
||||||
|
|
||||||
#### Run tests
|
|
||||||
|
|
||||||
```sh
|
|
||||||
gulp test:local
|
|
||||||
```
|
|
||||||
|
|
||||||
This runs the unit tests defined in the `app/test` directory through [web-component-tester](https://github.com/Polymer/web-component-tester).
|
|
||||||
|
|
||||||
To run tests Java 7 or higher is required. To update Java go to http://www.oracle.com/technetwork/java/javase/downloads/index.html and download ***JDK*** and install it.
|
|
||||||
|
|
||||||
#### Build & Vulcanize
|
|
||||||
|
|
||||||
```sh
|
|
||||||
gulp
|
|
||||||
```
|
|
||||||
|
|
||||||
Build and optimize the current project, ready for deployment. This includes linting as well as vulcanization, image, script, stylesheet and HTML optimization and minification.
|
|
||||||
|
|
||||||
## Application Theming & Styling
|
|
||||||
|
|
||||||
Polymer 1.0 introduces a shim for CSS custom properties. We take advantage of this in `app/styles/app-theme.html` to provide theming for your application. You can also find our presets for Material Design breakpoints in this file.
|
|
||||||
|
|
||||||
[Read more](https://www.polymer-project.org/1.0/docs/devguide/styling.html) about CSS custom properties.
|
|
||||||
|
|
||||||
### Styling
|
|
||||||
1. ***main.css*** - to define styles that can be applied outside of Polymer's custom CSS properties implementation. Some of the use-cases include defining styles that you want to be applied for a splash screen, styles for your application 'shell' before it gets upgraded using Polymer or critical style blocks that you want parsed before your elements are.
|
|
||||||
2. ***app-theme.html*** - to provide theming for your application. You can also find our presets for Material Design breakpoints in this file.
|
|
||||||
3. ***shared-styles.html*** - to shared styles between elements and index.html.
|
|
||||||
4. ***element styles only*** - styles specific to element. These styles should be inside the `<style></style>` inside `template`.
|
|
||||||
|
|
||||||
```HTML
|
|
||||||
<dom-module id="my-list">
|
|
||||||
<template>
|
|
||||||
<style>
|
|
||||||
:host {
|
|
||||||
display: block;
|
|
||||||
background-color: yellow;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<ul>
|
|
||||||
<template is="dom-repeat" items="{{items}}">
|
|
||||||
<li><span class="paper-font-body1">{{item}}</span></li>
|
|
||||||
</template>
|
|
||||||
</ul>
|
|
||||||
</template>
|
|
||||||
</dom-module>
|
|
||||||
```
|
|
||||||
|
|
||||||
These style files are located in the [styles folder](app/styles/).
|
|
||||||
|
|
||||||
## Unit Testing
|
|
||||||
|
|
||||||
Web apps built with Polymer Starter Kit come configured with support for [Web Component Tester](https://github.com/Polymer/web-component-tester) - Polymer's preferred tool for authoring and running unit tests. This makes testing your element based applications a pleasant experience.
|
|
||||||
|
|
||||||
[Read more](https://github.com/Polymer/web-component-tester#html-suites) about using Web Component tester.
|
|
||||||
|
|
||||||
## Dependency Management
|
|
||||||
|
|
||||||
Polymer uses [Bower](http://bower.io) for package management. This makes it easy to keep your elements up to date and versioned. For tooling, we use npm to manage Node.js-based dependencies.
|
|
||||||
|
|
||||||
## Service Worker
|
|
||||||
|
|
||||||
Polymer Starter Kit offers an optional offline experience thanks to Service Worker and the [Platinum Service Worker elements](https://github.com/PolymerElements/platinum-sw). New to Service Worker? Read the following [introduction](http://www.html5rocks.com/en/tutorials/service-worker/introduction/) to understand how it works.
|
|
||||||
|
|
||||||
Our optional offline setup should work well for relatively simple applications. For more complex apps, we recommend learning how Service Worker works so that you can make the most of the Platinum Service Worker element abstractions.
|
|
||||||
|
|
||||||
### Enable Service Worker support?
|
|
||||||
|
|
||||||
To enable Service Worker support for Polymer Starter Kit project use these 3 steps:
|
|
||||||
|
|
||||||
1. Uncomment Service Worker code in index.html
|
|
||||||
```HTML
|
|
||||||
<!-- Uncomment next block to enable Service Worker support (1/2) -->
|
|
||||||
<!--
|
|
||||||
<paper-toast id="caching-complete"
|
|
||||||
duration="6000"
|
|
||||||
text="Caching complete! This app will work offline.">
|
|
||||||
</paper-toast>
|
|
||||||
|
|
||||||
<platinum-sw-register auto-register
|
|
||||||
clients-claim
|
|
||||||
skip-waiting
|
|
||||||
on-service-worker-installed="displayInstalledToast">
|
|
||||||
<platinum-sw-cache default-cache-strategy="networkFirst"
|
|
||||||
precache-file="precache.json">
|
|
||||||
</platinum-sw-cache>
|
|
||||||
</platinum-sw-register>
|
|
||||||
-->
|
|
||||||
```
|
|
||||||
2. Uncomment Service Worker code in elements.html
|
|
||||||
|
|
||||||
```HTML
|
|
||||||
<!-- Uncomment next block to enable Service Worker Support (2/2) -->
|
|
||||||
<!--
|
|
||||||
<link rel="import" href="../bower_components/platinum-sw/platinum-sw-cache.html">
|
|
||||||
<link rel="import" href="../bower_components/platinum-sw/platinum-sw-register.html">
|
|
||||||
-->
|
|
||||||
```
|
|
||||||
3. Uncomment 'cache-config' in the `runSequence()` section of the 'default' gulp task, like below:
|
|
||||||
[(gulpfile.js)](https://github.com/PolymerElements/polymer-starter-kit/blob/master/gulpfile.js)
|
|
||||||
|
|
||||||
```JavaScript
|
|
||||||
// Build Production Files, the Default Task
|
|
||||||
gulp.task('default', ['clean'], function (cb) {
|
|
||||||
runSequence(
|
|
||||||
['copy', 'styles'],
|
|
||||||
'elements',
|
|
||||||
['jshint', 'images', 'fonts', 'html'],
|
|
||||||
'vulcanize', 'cache-config',
|
|
||||||
cb);
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Filing bugs in the right place
|
|
||||||
|
|
||||||
If you experience an issue with Service Worker support in your application, check the origin of the issue and use the appropriate issue tracker:
|
|
||||||
|
|
||||||
* [sw-toolbox](https://github.com/GoogleChrome/sw-toolbox/issues)
|
|
||||||
* [platinum-sw](https://github.com/PolymerElements/platinum-sw/issues)
|
|
||||||
* [platinum-push-notifications-manager](https://github.com/PolymerElements/push-notification-manager/)
|
|
||||||
* For all other issues, feel free to file them [here](https://github.com/polymerelements/polymer-starter-kit/issues).
|
|
||||||
|
|
||||||
#### I get an error message about "Only secure origins are allowed"
|
|
||||||
|
|
||||||
Service Workers are only available to "secure origins" (HTTPS sites, basically) in line with a policy to prefer secure origins for powerful new features. However http://localhost is also considered a secure origin, so if you can, developing on localhost is an easy way to avoid this error. For production, your site will need to support HTTPS.
|
|
||||||
|
|
||||||
#### How do I debug Service Worker?
|
|
||||||
|
|
||||||
If you need to debug the event listener wire-up use `chrome://serviceworker-internals`.
|
|
||||||
|
|
||||||
#### What are those buttons on chrome://serviceworker-internals?
|
|
||||||
|
|
||||||
This page shows your registered workers and provides some basic operations.
|
|
||||||
|
|
||||||
* Unregister: Unregisters the worker.
|
|
||||||
* Start: Starts the worker. This would happen automatically when you navigate to a page in the worker's scope.
|
|
||||||
* Stop: Stops the worker.
|
|
||||||
* Sync: Dispatches a 'sync' event to the worker. If you don't handle this event, nothing will happen.
|
|
||||||
* Push: Dispatches a 'push' event to the worker. If you don't handle this event, nothing will happen.
|
|
||||||
* Inspect: Opens the worker in the Inspector.
|
|
||||||
|
|
||||||
#### Development flow
|
|
||||||
|
|
||||||
In order to guarantee that the latest version of your Service Worker script is being used, follow these instructions:
|
|
||||||
|
|
||||||
* After you made changes to your service worker script, close all but one of the tabs pointing to your web application
|
|
||||||
* Hit shift-reload to bypass the service worker as to ensure that the remaining tab isn't under the control of a service worker
|
|
||||||
* Hit reload to let the newer version of the Service Worker control the page.
|
|
||||||
|
|
||||||
If you find anything to still be stale, you can also try navigating to `chrome:serviceworker-internals` (in Chrome), finding the relevant Service Worker entry for your application and clicking 'Unregister' before refreshing your app. This will (of course) only clear it from the local development machine. If you have already deployed to production then further work will be necessary to remove it from your user's machines.
|
|
||||||
|
|
||||||
#### Disable Service Worker support after you enabled it
|
|
||||||
|
|
||||||
If for any reason you need to disable Service Worker support after previously enabling it, you can remove it from your Polymer Starter Kit project using these 4 steps:
|
|
||||||
|
|
||||||
1. Remove references to the platinum-sw elements from your application [index](https://github.com/PolymerElements/polymer-starter-kit/blob/master/app/index.html).
|
|
||||||
2. Remove the two Platinum Service Worker elements (platinum-sw/..) in [app/elements/elements.html](https://github.com/PolymerElements/polymer-starter-kit/blob/master/app/elements/elements.html)
|
|
||||||
3. Remove 'precache' from the list in the 'default' gulp task ([gulpfile.js](https://github.com/PolymerElements/polymer-starter-kit/blob/master/gulpfile.js))
|
|
||||||
4. Navigate to `chrome://serviceworker-internals` and unregister any Service Workers registered by Polymer Starter Kit for your app just in case there's a copy of it cached.
|
|
||||||
|
|
||||||
## Yeoman support
|
|
||||||
|
|
||||||
[generator-polymer](https://github.com/yeoman/generator-polymer/releases) now includes support for Polymer Starter Kit out of the box.
|
|
||||||
|
|
||||||
## Frequently Asked Questions
|
|
||||||
|
|
||||||
### Where do I customise my application theme?
|
|
||||||
|
|
||||||
Theming can be achieved using [CSS Custom properties](https://www.polymer-project.org/1.0/docs/devguide/styling.html#xscope-styling-details) via [app/styles/app-theme.html](https://github.com/PolymerElements/polymer-starter-kit/blob/master/app/styles/app-theme.html).
|
|
||||||
You can also use `app/styles/main.css` for pure CSS stylesheets (e.g for global styles), however note that Custom properties will not work there under the shim.
|
|
||||||
|
|
||||||
A [Polycast](https://www.youtube.com/watch?v=omASiF85JzI) is also available that walks through theming using Polymer 1.0.
|
|
||||||
|
|
||||||
### Where do I configure routes in my application?
|
|
||||||
|
|
||||||
This can be done via [`app/elements/routing.html`](https://github.com/PolymerElements/polymer-starter-kit/blob/master/app/elements/routing.html). We use Page.js for routing and new routes
|
|
||||||
can be defined in this import. We then toggle which `<iron-pages>` page to display based on the [selected](https://github.com/PolymerElements/polymer-starter-kit/blob/master/app/index.html#L105) route.
|
|
||||||
|
|
||||||
### Why are we using Page.js rather than a declarative router like `<more-routing>`?
|
|
||||||
|
|
||||||
`<more-routing>` (in our opinion) is good, but lacks imperative hooks for getting full control
|
|
||||||
over the routing in your application. This is one place where a pure JS router shines. We may
|
|
||||||
at some point switch back to a declarative router when our hook requirements are tackled. That
|
|
||||||
said, it should be trivial to switch to `<more-routing>` or another declarative router in your
|
|
||||||
own local setup.
|
|
||||||
|
|
||||||
### Where can I find the application layouts from your Google I/O 2015 talk?
|
|
||||||
|
|
||||||
App layouts live in a separate repository called [app-layout-templates](https://github.com/PolymerElements/app-layout-templates).
|
|
||||||
You can select a template and copy over the relevant parts you would like to reuse to Polymer Starter Kit.
|
|
||||||
|
|
||||||
You will probably need to change paths to where your Iron and Paper dependencies can be found to get everything working.
|
|
||||||
This can be done by adding them to the [`elements.html`](https://github.com/PolymerElements/polymer-starter-kit/blob/master/app/elements/elements.html) import.
|
|
||||||
|
|
||||||
### Something has failed during installation. How do I fix this?
|
|
||||||
|
|
||||||
Our most commonly reported issue is around system permissions for installing Node.js dependencies.
|
|
||||||
We recommend following the [fixing npm permissions](https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md)
|
|
||||||
guide to address any messages around administrator permissions being required. If you use `sudo`
|
|
||||||
to work around these issues, this guide may also be useful for avoiding that.
|
|
||||||
|
|
||||||
If you run into an exception that mentions five optional dependencies failing (or an `EEXIST` error), you
|
|
||||||
may have run into an npm [bug](https://github.com/npm/npm/issues/6309). We recommend updating to npm 2.11.0+
|
|
||||||
to work around this. You can do this by opening a Command Prompt/terminal and running `npm install npm@2.11.0 -g`. If you are on Windows,
|
|
||||||
Node.js (and npm) may have been installed into `C:\Program Files\`. Updating npm by running `npm install npm@2.11.0 -g` will install npm
|
|
||||||
into `%AppData%\npm`, but your system will still use the npm version. You can avoid this by deleting your older npm from `C:\Program Files\nodejs`
|
|
||||||
as described [here](https://github.com/npm/npm/issues/6309#issuecomment-67549380).
|
|
||||||
|
|
||||||
If the issue is to do with a failure somewhere else, you might find that due to a network issue
|
|
||||||
a dependency failed to correctly install. We recommend running `npm cache clean` and deleting the `node_modules` directory followed by
|
|
||||||
`npm install` to see if this corrects the problem. If not, please check the [issue tracker](https://github.com/PolymerElements/polymer-starter-kit/issues) in case
|
|
||||||
there is a workaround or fix already posted.
|
|
||||||
|
|
||||||
### I'm having trouble getting Vulcanize to fully build my project on Windows. Help?
|
|
||||||
|
|
||||||
Some Windows users have run into trouble with the `elements.vulcanized.html` file in their `dist` folder
|
|
||||||
not being correctly vulcanized. This can happen if your project is in a folder with a name containing a
|
|
||||||
space. You can work around this issue by ensuring your path doesn't contain one.
|
|
||||||
|
|
||||||
There is also an [in-flight](https://github.com/PolymerElements/polymer-starter-kit/issues/62#issuecomment-108974016) issue
|
|
||||||
where some are finding they need to disable the `inlineCss` option in our configuration for Vulcanize
|
|
||||||
to correctly build. We are still investigating this, however for the time-being use the workaround if
|
|
||||||
you find your builds getting stuck here.
|
|
||||||
|
|
||||||
|
|
||||||
### How do I add new JavaScript files to Starter Kit so they're picked up by the build process?
|
|
||||||
|
|
||||||
At the bottom of `app/index.html`, you will find a build block that can be used to include additional
|
|
||||||
scripts for your app. Build blocks are just normal script tags that are wrapped in a HTML
|
|
||||||
comment that indicates where to concatenate and minify their final contents to.
|
|
||||||
|
|
||||||
Below, we've added in `script2.js` and `script3.js` to this block. The line
|
|
||||||
`<!-- build:js scripts/app.js -->` specifies that these scripts will be squashed into `scripts/app.js`
|
|
||||||
during a build.
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!-- build:js scripts/app.js -->
|
|
||||||
<script src="scripts/app.js"></script>
|
|
||||||
<script src="scripts/script2.js"></script>
|
|
||||||
<script src="scripts/script3.js"></script>
|
|
||||||
<!-- endbuild-->
|
|
||||||
```
|
|
||||||
|
|
||||||
If you are not using the build-blocks, but still wish for additional files (e.g scripts or stylesheets) to be included in the final `dist` directory, you will need to either copy these files as part of the gulpfile.js build process (see the `copy` task for how to automate this) or manually copy the files.
|
|
||||||
|
|
||||||
### I'm finding the installation/tooling here overwhelming. What should I do?
|
|
||||||
|
|
||||||
Don't worry! We've got your covered. Polymer Starter Kit tries to offer everything you need to build and optimize your apps for production, which is why we include the tooling we do. We realise however that our tooling setup may not be for everyone.
|
|
||||||
|
|
||||||
If you find that you just want the simplest setup possible, we recommend using Polymer Starter Kit light, which is available from the [Releases](https://github.com/PolymerElements/polymer-starter-kit/releases) page. This takes next to no time to setup.
|
|
||||||
|
|
||||||
### If you require more granular configuration of Vulcanize than polybuild provides you an option by:
|
|
||||||
|
|
||||||
1. Copy code below
|
|
||||||
2. Then replace `gulp.task('vulcanize', function () {...` entire gulp vulcanize task code in `gulpfile.js`
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// Vulcanize granular configuration
|
|
||||||
gulp.task('vulcanize', function () {
|
|
||||||
var DEST_DIR = 'dist/elements';
|
|
||||||
return gulp.src('dist/elements/elements.vulcanized.html')
|
|
||||||
.pipe($.vulcanize({
|
|
||||||
stripComments: true,
|
|
||||||
inlineCss: true,
|
|
||||||
inlineScripts: true
|
|
||||||
}))
|
|
||||||
.pipe(gulp.dest(DEST_DIR))
|
|
||||||
.pipe($.size({title: 'vulcanize'}));
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
Polymer Starter Kit is a new project and is an ongoing effort by the Web Component community. We welcome your bug reports, PRs for improvements, docs and anything you think would improve the experience for other Polymer developers.
|
|
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"README": "This is the cache config for the dev server. The service worker cache is disabled, and it is recommended that you leave this as-is. In the dist environment, this file will be auto-generated based on the contents of your dist/ directory.",
|
|
||||||
"disabled": true
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
<!--
|
|
||||||
@license
|
|
||||||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
|
||||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
||||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
||||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
||||||
Code distributed by Google as part of the polymer project is also
|
|
||||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- Iron elements -->
|
|
||||||
<link rel="import" href="../bower_components/iron-flex-layout/classes/iron-flex-layout.html">
|
|
||||||
<link rel="import" href="../bower_components/iron-icons/iron-icons.html">
|
|
||||||
<link rel="import" href="../bower_components/iron-pages/iron-pages.html">
|
|
||||||
<link rel="import" href="../bower_components/iron-selector/iron-selector.html">
|
|
||||||
<link rel="import" href="../bower_components/iron-localstorage/iron-localstorage.html">
|
|
||||||
|
|
||||||
<!-- Paper elements -->
|
|
||||||
<link rel="import" href="../bower_components/paper-drawer-panel/paper-drawer-panel.html">
|
|
||||||
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
|
|
||||||
<link rel="import" href="../bower_components/paper-item/paper-item.html">
|
|
||||||
<link rel="import" href="../bower_components/paper-material/paper-material.html">
|
|
||||||
<link rel="import" href="../bower_components/paper-menu/paper-menu.html">
|
|
||||||
<link rel="import" href="../bower_components/paper-scroll-header-panel/paper-scroll-header-panel.html">
|
|
||||||
<link rel="import" href="../bower_components/paper-styles/paper-styles-classes.html">
|
|
||||||
<link rel="import" href="../bower_components/paper-toast/paper-toast.html">
|
|
||||||
<link rel="import" href="../bower_components/paper-toolbar/paper-toolbar.html">
|
|
||||||
|
|
||||||
<!-- Uncomment next block to enable Service Worker Support (2/2) -->
|
|
||||||
<!--
|
|
||||||
<link rel="import" href="../bower_components/platinum-sw/platinum-sw-cache.html">
|
|
||||||
<link rel="import" href="../bower_components/platinum-sw/platinum-sw-register.html">
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- Configure your routes here -->
|
|
||||||
<link rel="import" href="routing.html">
|
|
||||||
|
|
||||||
<!-- Add your elements here -->
|
|
||||||
<link rel="import" href="../styles/app-theme.html">
|
|
||||||
<link rel="import" href="../styles/shared-styles.html">
|
|
||||||
<link rel="import" href="message-list/message-list.html">
|
|
@ -1,80 +0,0 @@
|
|||||||
<!--
|
|
||||||
@license
|
|
||||||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
|
||||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
||||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
||||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
||||||
Code distributed by Google as part of the polymer project is also
|
|
||||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
||||||
-->
|
|
||||||
<link rel="import" href="../../bower_components/polymer/polymer.html">
|
|
||||||
<link rel="import" href="../../bower_components/paper-material/paper-material.html">
|
|
||||||
<link rel="import" href="../../bower_components/iron-ajax/iron-ajax.html">
|
|
||||||
|
|
||||||
<dom-module id="message-list">
|
|
||||||
<template>
|
|
||||||
<link rel="import" href="../../styles/app-theme.html">
|
|
||||||
<style include="shared-styles"></style>
|
|
||||||
<style>
|
|
||||||
.received {
|
|
||||||
float: right;
|
|
||||||
font-size: 60%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.paper-font-body2 {
|
|
||||||
white-space: pre-wrap;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<iron-ajax
|
|
||||||
auto
|
|
||||||
url="{{getUrl(server, address)}}"
|
|
||||||
handle-as="json"
|
|
||||||
last-response="{{broadcasts}}"
|
|
||||||
debounce-duration="300"></iron-ajax>
|
|
||||||
<template is="dom-repeat" items="{{broadcasts.messages}}">
|
|
||||||
<paper-material elevation="1">
|
|
||||||
<h1>{{item.subject}}<span class="received">{{toDate(item.received)}}</span></h1>
|
|
||||||
|
|
||||||
<p class="paper-font-body2">{{item.body}}</p>
|
|
||||||
</paper-material>
|
|
||||||
</template>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
(function () {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
Polymer({
|
|
||||||
is: 'message-list',
|
|
||||||
|
|
||||||
properties: {
|
|
||||||
address: {
|
|
||||||
type: String,
|
|
||||||
value: 'BM-2D9QKN4teYRvoq2fyzpiftPh9WP9qggtzh',
|
|
||||||
notify: true
|
|
||||||
},
|
|
||||||
broadcasts: {
|
|
||||||
type: Object,
|
|
||||||
notify: true
|
|
||||||
},
|
|
||||||
server: {
|
|
||||||
type: String,
|
|
||||||
value: location.port === 5000 ? 'http://localhost:8080/' : '',
|
|
||||||
notify: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
toDate: function (timestamp) {
|
|
||||||
return new Date(timestamp * 1000).toLocaleString();
|
|
||||||
},
|
|
||||||
getUrl: function (server, address) {
|
|
||||||
console.log(server + 'read/' + address);
|
|
||||||
return server + 'read/' + address;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})();
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</dom-module>
|
|
@ -1,46 +0,0 @@
|
|||||||
<!--
|
|
||||||
@license
|
|
||||||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
|
||||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
||||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
||||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
||||||
Code distributed by Google as part of the polymer project is also
|
|
||||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
||||||
-->
|
|
||||||
|
|
||||||
<script src="../bower_components/page/page.js"></script>
|
|
||||||
<script>
|
|
||||||
window.addEventListener('WebComponentsReady', function() {
|
|
||||||
|
|
||||||
// We use Page.js for routing. This is a Micro
|
|
||||||
// client-side router inspired by the Express router
|
|
||||||
// More info: https://visionmedia.github.io/page.js/
|
|
||||||
|
|
||||||
// Middleware
|
|
||||||
function scrollToTop(ctx, next) {
|
|
||||||
app.scrollPageToTop();
|
|
||||||
next();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Routes
|
|
||||||
page('/', scrollToTop, function() {
|
|
||||||
app.route = 'home';
|
|
||||||
});
|
|
||||||
|
|
||||||
page('/read', scrollToTop, function() {
|
|
||||||
app.route = 'home';
|
|
||||||
});
|
|
||||||
|
|
||||||
page('/read/:address', scrollToTop, function(data) {
|
|
||||||
app.route = 'message-list';
|
|
||||||
app.params = data.params;
|
|
||||||
console.log(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
// add #! before urls
|
|
||||||
page({
|
|
||||||
hashbang: true
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
</script>
|
|
Before Width: | Height: | Size: 611 B |
Before Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 4.4 KiB |
@ -1,145 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<!--
|
|
||||||
@license
|
|
||||||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
|
||||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
||||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
||||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
||||||
Code distributed by Google as part of the polymer project is also
|
|
||||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
||||||
-->
|
|
||||||
|
|
||||||
<html lang="">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="description" content="">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<meta name="generator" content="Polymer Starter Kit" />
|
|
||||||
<title>Bitmessage Broadcasts</title>
|
|
||||||
<!-- Place favicon.ico in the `app/` directory -->
|
|
||||||
|
|
||||||
<!-- Chrome for Android theme color -->
|
|
||||||
<meta name="theme-color" content="#FFA000">
|
|
||||||
|
|
||||||
<!-- Web Application Manifest -->
|
|
||||||
<link rel="manifest" href="manifest.json">
|
|
||||||
|
|
||||||
<!-- Tile color for Win8 -->
|
|
||||||
<meta name="msapplication-TileColor" content="#FFC107">
|
|
||||||
|
|
||||||
<!-- Add to homescreen for Chrome on Android -->
|
|
||||||
<meta name="mobile-web-app-capable" content="yes">
|
|
||||||
<meta name="application-name" content="PSK">
|
|
||||||
<link rel="icon" sizes="192x192" href="images/touch/chrome-touch-icon-192x192.png">
|
|
||||||
|
|
||||||
<!-- Add to homescreen for Safari on iOS -->
|
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
|
||||||
<meta name="apple-mobile-web-app-title" content="Polymer Starter Kit">
|
|
||||||
<link rel="apple-touch-icon" href="images/touch/apple-touch-icon.png">
|
|
||||||
|
|
||||||
<!-- Tile icon for Win8 (144x144) -->
|
|
||||||
<meta name="msapplication-TileImage" content="images/touch/ms-touch-icon-144x144-precomposed.png">
|
|
||||||
|
|
||||||
<!-- build:css styles/main.css -->
|
|
||||||
<link rel="stylesheet" href="styles/main.css">
|
|
||||||
<!-- endbuild-->
|
|
||||||
|
|
||||||
<!-- build:js bower_components/webcomponentsjs/webcomponents-lite.min.js -->
|
|
||||||
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
|
|
||||||
<!-- endbuild -->
|
|
||||||
|
|
||||||
<!-- will be replaced with elements/elements.vulcanized.html -->
|
|
||||||
<link rel="import" href="elements/elements.html">
|
|
||||||
<!-- endreplace-->
|
|
||||||
|
|
||||||
<!-- For shared styles, shared-styles.html import in elements.html -->
|
|
||||||
<style is="custom-style" include="shared-styles"></style>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body unresolved class="fullbleed layout vertical">
|
|
||||||
<span id="browser-sync-binding"></span>
|
|
||||||
<template is="dom-bind" id="app">
|
|
||||||
|
|
||||||
<paper-drawer-panel id="paperDrawerPanel">
|
|
||||||
<!-- Drawer Scroll Header Panel -->
|
|
||||||
<paper-scroll-header-panel drawer fixed>
|
|
||||||
|
|
||||||
<!-- Drawer Toolbar -->
|
|
||||||
<paper-toolbar id="drawerToolbar">
|
|
||||||
<span class="paper-font-title">Menu</span>
|
|
||||||
</paper-toolbar>
|
|
||||||
|
|
||||||
<!-- Drawer Content -->
|
|
||||||
<paper-menu class="list" attr-for-selected="data-route" selected="[[route]]">
|
|
||||||
<a data-route="home" href="/" on-click="onDataRouteClick">
|
|
||||||
<iron-icon icon="home"></iron-icon>
|
|
||||||
<span>Home</span>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<iron-localstorage name="my-broadcasts"
|
|
||||||
value="{{broadcasts}}"
|
|
||||||
on-iron-localstorage-load-empty="initializeExamples"></iron-localstorage>
|
|
||||||
<template is="dom-repeat" items="{{broadcasts}}">
|
|
||||||
<a data-route="{{join('message-list/',index)}}" href="{{join('/read/',item.address)}}" on-click="onDataRouteClick">
|
|
||||||
<iron-icon icon="mail"></iron-icon>
|
|
||||||
<span>{{item.alias}}</span>
|
|
||||||
</a>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
</paper-menu>
|
|
||||||
</paper-scroll-header-panel>
|
|
||||||
|
|
||||||
<!-- Main Area -->
|
|
||||||
<paper-scroll-header-panel main condenses keep-condensed-header>
|
|
||||||
|
|
||||||
<!-- Main Toolbar -->
|
|
||||||
<paper-toolbar id="mainToolbar" class="tall">
|
|
||||||
<paper-icon-button id="paperToggle" icon="menu" paper-drawer-toggle></paper-icon-button>
|
|
||||||
<span class="flex"></span>
|
|
||||||
|
|
||||||
<!-- Toolbar icons -->
|
|
||||||
<paper-icon-button icon="refresh"></paper-icon-button>
|
|
||||||
<paper-icon-button icon="search"></paper-icon-button>
|
|
||||||
|
|
||||||
<!-- Application name -->
|
|
||||||
<div class="middle middle-container center horizontal layout">
|
|
||||||
<div class="app-name">Bitmessage Broadcasts</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Application sub title -->
|
|
||||||
<div class="bottom bottom-container center horizontal layout">
|
|
||||||
<div class="bottom-title paper-font-subhead">Please don't abuse.</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</paper-toolbar>
|
|
||||||
|
|
||||||
<!-- Main Content -->
|
|
||||||
<div class="content">
|
|
||||||
<iron-pages attr-for-selected="data-route" selected="{{route}}">
|
|
||||||
|
|
||||||
<section data-route="home">
|
|
||||||
<paper-material elevation="1">
|
|
||||||
<h1>Welcome.</h1>
|
|
||||||
</paper-material>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section data-route="message-list">
|
|
||||||
<message-list address="{{params.address}}"></message-list>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
</iron-pages>
|
|
||||||
</div>
|
|
||||||
</paper-scroll-header-panel>
|
|
||||||
</paper-drawer-panel>
|
|
||||||
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<!-- build:js scripts/app.js -->
|
|
||||||
<script src="scripts/app.js"></script>
|
|
||||||
<!-- endbuild-->
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
@ -1,29 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "Polymer Starter Kit",
|
|
||||||
"short_name": "Polymer Starter Kit",
|
|
||||||
"icons": [{
|
|
||||||
"src": "images/touch/icon-128x128.png",
|
|
||||||
"sizes": "128x128",
|
|
||||||
"type": "image/png"
|
|
||||||
}, {
|
|
||||||
"src": "images/touch/apple-touch-icon.png",
|
|
||||||
"sizes": "152x152",
|
|
||||||
"type": "image/png"
|
|
||||||
}, {
|
|
||||||
"src": "images/touch/ms-touch-icon-144x144-precomposed.png",
|
|
||||||
"sizes": "144x144",
|
|
||||||
"type": "image/png"
|
|
||||||
}, {
|
|
||||||
"src": "images/touch/chrome-touch-icon-192x192.png",
|
|
||||||
"sizes": "192x192",
|
|
||||||
"type": "image/png"
|
|
||||||
},{
|
|
||||||
"src": "images/touch/chrome-splashscreen-icon-384x384.png",
|
|
||||||
"sizes": "384x384",
|
|
||||||
"type": "image/png"
|
|
||||||
}],
|
|
||||||
"start_url": "/?homescreen=1",
|
|
||||||
"background_color": "#FFC107",
|
|
||||||
"display": "standalone",
|
|
||||||
"theme_color": "#FFA000"
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
# www.robotstxt.org
|
|
||||||
|
|
||||||
User-agent: *
|
|
||||||
Disallow:
|
|
@ -1,104 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
|
||||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
||||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
||||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
||||||
Code distributed by Google as part of the polymer project is also
|
|
||||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
||||||
*/
|
|
||||||
|
|
||||||
(function(document) {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// Grab a reference to our auto-binding template
|
|
||||||
// and give it some initial binding values
|
|
||||||
// Learn more about auto-binding templates at http://goo.gl/Dx1u2g
|
|
||||||
var app = document.querySelector('#app');
|
|
||||||
|
|
||||||
app.join = function() {
|
|
||||||
var result = '';
|
|
||||||
for (var index = 0; index < arguments.length; index++) {
|
|
||||||
result += arguments[index];
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
app.displayInstalledToast = function() {
|
|
||||||
// Check to make sure caching is actually enabled—it won't be in the dev environment.
|
|
||||||
if (!document.querySelector('platinum-sw-cache').disabled) {
|
|
||||||
document.querySelector('#caching-complete').show();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Listen for template bound event to know when bindings
|
|
||||||
// have resolved and content has been stamped to the page
|
|
||||||
app.addEventListener('dom-change', function() {
|
|
||||||
console.log('Our app is ready to rock!');
|
|
||||||
});
|
|
||||||
|
|
||||||
// See https://github.com/Polymer/polymer/issues/1381
|
|
||||||
window.addEventListener('WebComponentsReady', function() {
|
|
||||||
// imports are loaded and elements have been registered
|
|
||||||
});
|
|
||||||
|
|
||||||
// Main area's paper-scroll-header-panel custom condensing transformation of
|
|
||||||
// the appName in the middle-container and the bottom title in the bottom-container.
|
|
||||||
// The appName is moved to top and shrunk on condensing. The bottom sub title
|
|
||||||
// is shrunk to nothing on condensing.
|
|
||||||
addEventListener('paper-header-transform', function(e) {
|
|
||||||
var appName = document.querySelector('#mainToolbar .app-name');
|
|
||||||
var middleContainer = document.querySelector('#mainToolbar .middle-container');
|
|
||||||
var bottomContainer = document.querySelector('#mainToolbar .bottom-container');
|
|
||||||
var detail = e.detail;
|
|
||||||
var heightDiff = detail.height - detail.condensedHeight;
|
|
||||||
var yRatio = Math.min(1, detail.y / heightDiff);
|
|
||||||
var maxMiddleScale = 0.50; // appName max size when condensed. The smaller the number the smaller the condensed size.
|
|
||||||
var scaleMiddle = Math.max(maxMiddleScale, (heightDiff - detail.y) / (heightDiff / (1-maxMiddleScale)) + maxMiddleScale);
|
|
||||||
var scaleBottom = 1 - yRatio;
|
|
||||||
|
|
||||||
// Move/translate middleContainer
|
|
||||||
Polymer.Base.transform('translate3d(0,' + yRatio * 100 + '%,0)', middleContainer);
|
|
||||||
|
|
||||||
// Scale bottomContainer and bottom sub title to nothing and back
|
|
||||||
Polymer.Base.transform('scale(' + scaleBottom + ') translateZ(0)', bottomContainer);
|
|
||||||
|
|
||||||
// Scale middleContainer appName
|
|
||||||
Polymer.Base.transform('scale(' + scaleMiddle + ') translateZ(0)', appName);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Close drawer after menu item is selected if drawerPanel is narrow
|
|
||||||
app.onDataRouteClick = function() {
|
|
||||||
var drawerPanel = document.querySelector('#paperDrawerPanel');
|
|
||||||
if (drawerPanel.narrow) {
|
|
||||||
drawerPanel.closeDrawer();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Scroll page to top and expand header
|
|
||||||
app.scrollPageToTop = function() {
|
|
||||||
document.getElementById('mainContainer').scrollTop = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
app.initializeExamples = function() {
|
|
||||||
this.value = [
|
|
||||||
{
|
|
||||||
alias: 'General',
|
|
||||||
address: 'BM-2cToDNkgW4KN92vuEjgnT1To3WEyt4r3DK'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
alias: 'DevTalk',
|
|
||||||
address: 'BM-2D9QKN4teYRvoq2fyzpiftPh9WP9qggtzh'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
alias: 'Timeservice',
|
|
||||||
address: 'BM-BcbRqcFFSQUUmXFKsPJgVQPSiFA3Xash'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
alias: 'Q\'s Aktivlist',
|
|
||||||
address: 'BM-GtT7NLCCAu3HrT7dNTUTY9iDns92Z2ND'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
console.log(this.value);
|
|
||||||
};
|
|
||||||
|
|
||||||
})(document);
|
|
@ -1,170 +0,0 @@
|
|||||||
<!-- Palette generated by Material Palette - materialpalette.com/amber/blue-grey -->
|
|
||||||
<!-- Replace the one that comes in their starter kit -->
|
|
||||||
<!--
|
|
||||||
@license
|
|
||||||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
|
||||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
||||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
||||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
||||||
Code distributed by Google as part of the polymer project is also
|
|
||||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
||||||
-->
|
|
||||||
|
|
||||||
<style is="custom-style">
|
|
||||||
|
|
||||||
/*
|
|
||||||
Polymer includes a shim for CSS Custom Properties that we can use for application theming.
|
|
||||||
Below, you'll find the default palette for the Polymer Starter Kit layout. Feel free to play
|
|
||||||
with changing the colors used or generate your own palette of colours at MaterialPalette.com.
|
|
||||||
|
|
||||||
See https://www.polymer-project.org/1.0/docs/devguide/styling.html#xscope-styling-details
|
|
||||||
for further information on custom CSS properties.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Application theme */
|
|
||||||
|
|
||||||
:root {
|
|
||||||
--dark-primary-color: #FFA000;
|
|
||||||
--default-primary-color: #FFC107;
|
|
||||||
--light-primary-color: #FFECB3;
|
|
||||||
--text-primary-color: #FFFFFF;
|
|
||||||
--accent-color: #607D8B;
|
|
||||||
--primary-background-color: #FFECB3;
|
|
||||||
--primary-text-color: #212121;
|
|
||||||
--secondary-text-color: #727272;
|
|
||||||
--disabled-text-color: #BDBDBD;
|
|
||||||
--divider-color: #B6B6B6;
|
|
||||||
|
|
||||||
|
|
||||||
/* Components */
|
|
||||||
|
|
||||||
/* paper-drawer-panel */
|
|
||||||
--drawer-menu-color: #ffffff;
|
|
||||||
--drawer-border-color: 1px solid #ccc;
|
|
||||||
--drawer-toolbar-border-color: 1px solid rgba(0, 0, 0, 0.22);
|
|
||||||
|
|
||||||
/* paper-menu */
|
|
||||||
--paper-menu-background-color: #fff;
|
|
||||||
--menu-link-color: #111111;
|
|
||||||
|
|
||||||
/* paper-input */
|
|
||||||
--paper-input-container-color: rgba(255, 255, 255, 0.64);
|
|
||||||
--paper-input-container-focus-color: rgba(255, 255, 255, 1);
|
|
||||||
--paper-input-container-input-color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* General styles */
|
|
||||||
|
|
||||||
#drawerToolbar {
|
|
||||||
color: var(--secondary-text-color);
|
|
||||||
background-color: var(--drawer-menu-color);
|
|
||||||
border-bottom: var(--drawer-toolbar-border-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
paper-scroll-header-panel {
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
paper-menu iron-icon {
|
|
||||||
margin-right: 33px;
|
|
||||||
opacity: 0.54;
|
|
||||||
}
|
|
||||||
|
|
||||||
.paper-menu > .iron-selected {
|
|
||||||
color: var(--default-primary-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
paper-menu a {
|
|
||||||
text-decoration: none;
|
|
||||||
color: var(--menu-link-color);
|
|
||||||
display: -ms-flexbox;
|
|
||||||
display: -webkit-flex;
|
|
||||||
display: flex;
|
|
||||||
-ms-flex-direction: row;
|
|
||||||
-webkit-flex-direction: row;
|
|
||||||
flex-direction: row;
|
|
||||||
-ms-flex-align: center;
|
|
||||||
-webkit-align-items: center;
|
|
||||||
align-items: center;
|
|
||||||
font-family: 'Roboto', 'Noto', sans-serif;
|
|
||||||
-webkit-font-smoothing: antialiased;
|
|
||||||
text-rendering: optimizeLegibility;
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: 400;
|
|
||||||
line-height: 24px;
|
|
||||||
min-height: 48px;
|
|
||||||
padding: 0 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
paper-toolbar.tall .app-name {
|
|
||||||
font-size: 40px;
|
|
||||||
font-weight: 300;
|
|
||||||
/* Required for main area's paper-scroll-header-panel custom condensing transformation */
|
|
||||||
-webkit-transform-origin: left center;
|
|
||||||
transform-origin: left center;
|
|
||||||
}
|
|
||||||
|
|
||||||
#mainToolbar .middle-container {
|
|
||||||
height: 100%;
|
|
||||||
margin-left: 48px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#mainToolbar:not(.tall) .middle {
|
|
||||||
font-size: 18px;
|
|
||||||
padding-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#mainToolbar .bottom {
|
|
||||||
margin-left: 48px;
|
|
||||||
/* Required for main area's paper-scroll-header-panel custom condensing transformation */
|
|
||||||
-webkit-transform-origin: left center;
|
|
||||||
transform-origin: left center;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Height of the scroll area */
|
|
||||||
.content {
|
|
||||||
height: 900px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Material Design Adaptive Breakpoints */
|
|
||||||
/*
|
|
||||||
Below you'll find CSS media queries based on the breakpoint guidance
|
|
||||||
published by the Material Design team. You can choose to use, customise
|
|
||||||
or remove these breakpoints based on your needs.
|
|
||||||
|
|
||||||
http://www.google.com/design/spec/layout/adaptive-ui.html#adaptive-ui-breakpoints
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* mobile-small */
|
|
||||||
@media all and (min-width: 0) and (max-width: 360px) and (orientation: portrait) { }
|
|
||||||
/* mobile-large */
|
|
||||||
@media all and (min-width: 361px) and (orientation: portrait) { }
|
|
||||||
/* mobile-small-landscape */
|
|
||||||
@media all and (min-width: 0) and (max-width: 480px) and (orientation: landscape) { }
|
|
||||||
/* mobile-large-landscape */
|
|
||||||
@media all and (min-width: 481px) and (orientation: landscape) { }
|
|
||||||
/* tablet-small-landscape */
|
|
||||||
@media all and (min-width: 600px) and (max-width: 960px) and (orientation: landscape) { }
|
|
||||||
/* tablet-large-landscape */
|
|
||||||
@media all and (min-width: 961px) and (orientation: landscape) { }
|
|
||||||
/* tablet-small */
|
|
||||||
@media all and (min-width: 600px) and (orientation: portrait) { }
|
|
||||||
/* tablet-large */
|
|
||||||
@media all and (min-width: 601px) and (max-width: 840px) and (orientation : portrait) { }
|
|
||||||
/* desktop-x-small-landscape */
|
|
||||||
@media all and (min-width: 0) and (max-width: 480px) and (orientation: landscape) { }
|
|
||||||
/* desktop-x-small */
|
|
||||||
@media all and (min-width: 0) and (max-width: 480px) and (max-aspect-ratio: 4/3) { }
|
|
||||||
/* desktop-small-landscape */
|
|
||||||
@media all and (min-width: 481px) and (max-width: 840px) and (orientation: landscape) { }
|
|
||||||
/* desktop-small */
|
|
||||||
@media all and (min-width: 481px) and (max-width: 840px) and (max-aspect-ratio: 4/3) { }
|
|
||||||
/* desktop-medium-landscape */
|
|
||||||
@media all and (min-width: 841px) and (max-width: 1280px) and (orientation: landscape) { }
|
|
||||||
/* desktop-medium */
|
|
||||||
@media all and (min-width: 841px) and (max-width: 1280px) and (max-aspect-ratio: 4/3) { }
|
|
||||||
/* desktop-large */
|
|
||||||
@media all and (min-width: 1281px) and (max-width: 1600px) { }
|
|
||||||
/* desktop-xlarge */
|
|
||||||
@media all and (min-width: 1601px) and (max-width: 1920px) { }
|
|
||||||
</style>
|
|
@ -1,14 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
|
||||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
||||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
||||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
||||||
Code distributed by Google as part of the polymer project is also
|
|
||||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
||||||
*/
|
|
||||||
|
|
||||||
body {
|
|
||||||
background: #fafafa;
|
|
||||||
font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
||||||
color: #333;
|
|
||||||
}
|
|
@ -1,76 +0,0 @@
|
|||||||
<!-- shared styles for all elements and index.html -->
|
|
||||||
<dom-module id="shared-styles">
|
|
||||||
<template>
|
|
||||||
<style>
|
|
||||||
.page-title {
|
|
||||||
@apply(--paper-font-display2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 600px) {
|
|
||||||
.page-title {
|
|
||||||
font-size: 24px!important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
paper-material {
|
|
||||||
border-radius: 2px;
|
|
||||||
height: 100%;
|
|
||||||
padding: 16px 0 16px 0;
|
|
||||||
width: calc(98.66% - 16px);
|
|
||||||
margin: 16px auto;
|
|
||||||
background: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Breakpoints */
|
|
||||||
|
|
||||||
/* Small */
|
|
||||||
@media (max-width: 600px) {
|
|
||||||
|
|
||||||
paper-material {
|
|
||||||
--menu-container-display: none;
|
|
||||||
width: calc(97.33% - 32px);
|
|
||||||
padding-left: 16px;
|
|
||||||
padding-right: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
paper-toolbar.tall .app-name {
|
|
||||||
font-size: 24px;
|
|
||||||
font-weight: 400;
|
|
||||||
}
|
|
||||||
|
|
||||||
#drawer .paper-toolbar {
|
|
||||||
margin-left: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#overlay {
|
|
||||||
min-width: 360px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bg {
|
|
||||||
background: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Tablet+ */
|
|
||||||
@media (min-width: 601px) {
|
|
||||||
|
|
||||||
paper-material {
|
|
||||||
width: calc(98% - 46px);
|
|
||||||
margin-bottom: 32px;
|
|
||||||
padding-left: 30px;
|
|
||||||
padding-right: 30px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#drawer.paper-drawer-panel > [drawer] {
|
|
||||||
border-right: 1px solid rgba(0, 0, 0, 0.14);
|
|
||||||
}
|
|
||||||
|
|
||||||
iron-pages {
|
|
||||||
padding: 48px 62px;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</template>
|
|
||||||
</dom-module>
|
|
@ -1,10 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
|
||||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
||||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
||||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
||||||
Code distributed by Google as part of the polymer project is also
|
|
||||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
||||||
*/
|
|
||||||
|
|
||||||
importScripts('bower_components/platinum-sw/service-worker.js');
|
|
@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "polymer-starter-kit",
|
|
||||||
"private": true,
|
|
||||||
"dependencies": {
|
|
||||||
"polymer": "Polymer/polymer#^1.1.0",
|
|
||||||
"iron-elements": "PolymerElements/iron-elements#^1.0.0",
|
|
||||||
"paper-elements": "PolymerElements/paper-elements#^1.0.1",
|
|
||||||
"platinum-elements": "PolymerElements/platinum-elements#^1.1.0",
|
|
||||||
"neon-elements": "PolymerElements/neon-elements#^1.0.0",
|
|
||||||
"page": "visionmedia/page.js#~1.6.3"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"web-component-tester": "*",
|
|
||||||
"test-fixture": "PolymerElements/test-fixture#^1.0.0"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id "com.moowork.gulp" version "0.11"
|
|
||||||
}
|
|
||||||
|
|
||||||
// makes sure on each build that gulp is installed
|
|
||||||
gulp_default.dependsOn 'installGulp'
|
|
||||||
|
|
||||||
// processes your package.json before running gulp build
|
|
||||||
gulp_default.dependsOn 'npmInstall'
|
|
||||||
|
|
||||||
// runs "gulp build" as part of your gradle build
|
|
||||||
task build {
|
|
||||||
dependsOn gulp_default
|
|
||||||
}
|
|
@ -1,280 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
|
||||||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
||||||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
||||||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
||||||
Code distributed by Google as part of the polymer project is also
|
|
||||||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// Include Gulp & tools we'll use
|
|
||||||
var gulp = require('gulp');
|
|
||||||
var $ = require('gulp-load-plugins')();
|
|
||||||
var del = require('del');
|
|
||||||
var runSequence = require('run-sequence');
|
|
||||||
var browserSync = require('browser-sync');
|
|
||||||
var reload = browserSync.reload;
|
|
||||||
var merge = require('merge-stream');
|
|
||||||
var path = require('path');
|
|
||||||
var fs = require('fs');
|
|
||||||
var glob = require('glob');
|
|
||||||
var historyApiFallback = require('connect-history-api-fallback');
|
|
||||||
var packageJson = require('./package.json');
|
|
||||||
var crypto = require('crypto');
|
|
||||||
var polybuild = require('polybuild');
|
|
||||||
|
|
||||||
var AUTOPREFIXER_BROWSERS = [
|
|
||||||
'ie >= 10',
|
|
||||||
'ie_mob >= 10',
|
|
||||||
'ff >= 30',
|
|
||||||
'chrome >= 34',
|
|
||||||
'safari >= 7',
|
|
||||||
'opera >= 23',
|
|
||||||
'ios >= 7',
|
|
||||||
'android >= 4.4',
|
|
||||||
'bb >= 10'
|
|
||||||
];
|
|
||||||
|
|
||||||
var styleTask = function (stylesPath, srcs) {
|
|
||||||
return gulp.src(srcs.map(function(src) {
|
|
||||||
return path.join('app', stylesPath, src);
|
|
||||||
}))
|
|
||||||
.pipe($.changed(stylesPath, {extension: '.css'}))
|
|
||||||
.pipe($.autoprefixer(AUTOPREFIXER_BROWSERS))
|
|
||||||
.pipe(gulp.dest('.tmp/' + stylesPath))
|
|
||||||
.pipe($.cssmin())
|
|
||||||
.pipe(gulp.dest('../src/main/resources/static/' + stylesPath))
|
|
||||||
.pipe($.size({title: stylesPath}));
|
|
||||||
};
|
|
||||||
|
|
||||||
// Compile and automatically prefix stylesheets
|
|
||||||
gulp.task('styles', function () {
|
|
||||||
return styleTask('styles', ['**/*.css']);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('elements', function () {
|
|
||||||
return styleTask('elements', ['**/*.css']);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Lint JavaScript
|
|
||||||
gulp.task('jshint', function () {
|
|
||||||
return gulp.src([
|
|
||||||
'app/scripts/**/*.js',
|
|
||||||
'app/elements/**/*.js',
|
|
||||||
'app/elements/**/*.html',
|
|
||||||
'gulpfile.js'
|
|
||||||
])
|
|
||||||
.pipe(reload({stream: true, once: true}))
|
|
||||||
.pipe($.jshint.extract()) // Extract JS from .html files
|
|
||||||
.pipe($.jshint())
|
|
||||||
.pipe($.jshint.reporter('jshint-stylish'))
|
|
||||||
.pipe($.if(!browserSync.active, $.jshint.reporter('fail')));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Optimize images
|
|
||||||
gulp.task('images', function () {
|
|
||||||
return gulp.src('app/images/**/*')
|
|
||||||
.pipe($.cache($.imagemin({
|
|
||||||
progressive: true,
|
|
||||||
interlaced: true
|
|
||||||
})))
|
|
||||||
.pipe(gulp.dest('dist/images'))
|
|
||||||
.pipe($.size({title: 'images'}));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Copy all files at the root level (app)
|
|
||||||
gulp.task('copy', function () {
|
|
||||||
var app = gulp.src([
|
|
||||||
'app/*',
|
|
||||||
'!app/test',
|
|
||||||
'!app/cache-config.json'
|
|
||||||
], {
|
|
||||||
dot: true
|
|
||||||
}).pipe(gulp.dest('dist'));
|
|
||||||
|
|
||||||
var bower = gulp.src([
|
|
||||||
'bower_components/**/*'
|
|
||||||
]).pipe(gulp.dest('dist/bower_components'));
|
|
||||||
|
|
||||||
var elements = gulp.src(['app/elements/**/*.html'])
|
|
||||||
.pipe(gulp.dest('dist/elements'));
|
|
||||||
|
|
||||||
var swBootstrap = gulp.src(['bower_components/platinum-sw/bootstrap/*.js'])
|
|
||||||
.pipe(gulp.dest('dist/elements/bootstrap'));
|
|
||||||
|
|
||||||
var swToolbox = gulp.src(['bower_components/sw-toolbox/*.js'])
|
|
||||||
.pipe(gulp.dest('dist/sw-toolbox'));
|
|
||||||
|
|
||||||
var vulcanized = gulp.src(['app/elements/elements.html'])
|
|
||||||
.pipe($.rename('elements.vulcanized.html'))
|
|
||||||
.pipe(gulp.dest('dist/elements'));
|
|
||||||
|
|
||||||
return merge(app, bower, elements, vulcanized, swBootstrap, swToolbox)
|
|
||||||
.pipe($.size({title: 'copy'}));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Copy web fonts to dist
|
|
||||||
gulp.task('fonts', function () {
|
|
||||||
return gulp.src(['app/fonts/**'])
|
|
||||||
.pipe(gulp.dest('dist/fonts'))
|
|
||||||
.pipe($.size({title: 'fonts'}));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Scan your HTML for assets & optimize them
|
|
||||||
gulp.task('html', function () {
|
|
||||||
var assets = $.useref.assets({searchPath: ['.tmp', 'app', 'dist']});
|
|
||||||
|
|
||||||
return gulp.src(['app/**/*.html', '!app/{elements,test}/**/*.html'])
|
|
||||||
// Replace path for vulcanized assets
|
|
||||||
.pipe($.if('*.html', $.replace('elements/elements.html', 'elements/elements.vulcanized.html')))
|
|
||||||
.pipe(assets)
|
|
||||||
// Concatenate and minify JavaScript
|
|
||||||
.pipe($.if('*.js', $.uglify({preserveComments: 'some'})))
|
|
||||||
// Concatenate and minify styles
|
|
||||||
// In case you are still using useref build blocks
|
|
||||||
.pipe($.if('*.css', $.cssmin()))
|
|
||||||
.pipe(assets.restore())
|
|
||||||
.pipe($.useref())
|
|
||||||
// Minify any HTML
|
|
||||||
.pipe($.if('*.html', $.minifyHtml({
|
|
||||||
quotes: true,
|
|
||||||
empty: true,
|
|
||||||
spare: true
|
|
||||||
})))
|
|
||||||
// Output files
|
|
||||||
.pipe(gulp.dest('dist'))
|
|
||||||
.pipe($.size({title: 'html'}));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Polybuild will take care of inlining HTML imports,
|
|
||||||
// scripts and CSS for you.
|
|
||||||
gulp.task('vulcanize', function () {
|
|
||||||
return gulp.src('dist/index.html')
|
|
||||||
.pipe(polybuild({maximumCrush: true}))
|
|
||||||
.pipe(gulp.dest('dist/'));
|
|
||||||
});
|
|
||||||
|
|
||||||
// If you require more granular configuration of Vulcanize
|
|
||||||
// than polybuild provides, follow instructions from readme at:
|
|
||||||
// https://github.com/PolymerElements/polymer-starter-kit/#if-you-require-more-granular-configuration-of-vulcanize-than-polybuild-provides-you-an-option-by
|
|
||||||
|
|
||||||
// Rename Polybuild's index.build.html to index.html
|
|
||||||
gulp.task('rename-index', function () {
|
|
||||||
gulp.src('dist/index.build.html')
|
|
||||||
.pipe($.rename('index.html'))
|
|
||||||
.pipe(gulp.dest('dist/'));
|
|
||||||
return del(['dist/index.build.html']);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Generate config data for the <sw-precache-cache> element.
|
|
||||||
// This include a list of files that should be precached, as well as a (hopefully unique) cache
|
|
||||||
// id that ensure that multiple PSK projects don't share the same Cache Storage.
|
|
||||||
// This task does not run by default, but if you are interested in using service worker caching
|
|
||||||
// in your project, please enable it within the 'default' task.
|
|
||||||
// See https://github.com/PolymerElements/polymer-starter-kit#enable-service-worker-support
|
|
||||||
// for more context.
|
|
||||||
gulp.task('cache-config', function (callback) {
|
|
||||||
var dir = 'dist';
|
|
||||||
var config = {
|
|
||||||
cacheId: packageJson.name || path.basename(__dirname),
|
|
||||||
disabled: false
|
|
||||||
};
|
|
||||||
|
|
||||||
glob('{elements,scripts,styles}/**/*.*', {cwd: dir}, function(error, files) {
|
|
||||||
if (error) {
|
|
||||||
callback(error);
|
|
||||||
} else {
|
|
||||||
files.push('index.html', './', 'bower_components/webcomponentsjs/webcomponents-lite.min.js');
|
|
||||||
config.precache = files;
|
|
||||||
|
|
||||||
var md5 = crypto.createHash('md5');
|
|
||||||
md5.update(JSON.stringify(config.precache));
|
|
||||||
config.precacheFingerprint = md5.digest('hex');
|
|
||||||
|
|
||||||
var configPath = path.join(dir, 'cache-config.json');
|
|
||||||
fs.writeFile(configPath, JSON.stringify(config), callback);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Clean output directory
|
|
||||||
gulp.task('clean', function (cb) {
|
|
||||||
del(['.tmp', 'dist'], cb);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Watch files for changes & reload
|
|
||||||
gulp.task('serve', ['styles', 'elements', 'images'], function () {
|
|
||||||
browserSync({
|
|
||||||
port: 5000,
|
|
||||||
notify: false,
|
|
||||||
logPrefix: 'PSK',
|
|
||||||
snippetOptions: {
|
|
||||||
rule: {
|
|
||||||
match: '<span id="browser-sync-binding"></span>',
|
|
||||||
fn: function (snippet) {
|
|
||||||
return snippet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// Run as an https by uncommenting 'https: true'
|
|
||||||
// Note: this uses an unsigned certificate which on first access
|
|
||||||
// will present a certificate warning in the browser.
|
|
||||||
// https: true,
|
|
||||||
server: {
|
|
||||||
baseDir: ['.tmp', 'app'],
|
|
||||||
middleware: [ historyApiFallback() ],
|
|
||||||
routes: {
|
|
||||||
'/bower_components': 'bower_components'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.watch(['app/**/*.html'], reload);
|
|
||||||
gulp.watch(['app/styles/**/*.css'], ['styles', reload]);
|
|
||||||
gulp.watch(['app/elements/**/*.css'], ['elements', reload]);
|
|
||||||
gulp.watch(['app/{scripts,elements}/**/{*.js,*.html}'], ['jshint']);
|
|
||||||
gulp.watch(['app/images/**/*'], reload);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Build and serve the output from the dist build
|
|
||||||
gulp.task('serve:dist', ['default'], function () {
|
|
||||||
browserSync({
|
|
||||||
port: 5001,
|
|
||||||
notify: false,
|
|
||||||
logPrefix: 'PSK',
|
|
||||||
snippetOptions: {
|
|
||||||
rule: {
|
|
||||||
match: '<span id="browser-sync-binding"></span>',
|
|
||||||
fn: function (snippet) {
|
|
||||||
return snippet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// Run as an https by uncommenting 'https: true'
|
|
||||||
// Note: this uses an unsigned certificate which on first access
|
|
||||||
// will present a certificate warning in the browser.
|
|
||||||
// https: true,
|
|
||||||
server: 'dist',
|
|
||||||
middleware: [ historyApiFallback() ]
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Build production files, the default task
|
|
||||||
gulp.task('default', ['clean'], function (cb) {
|
|
||||||
// Uncomment 'cache-config' after 'rename-index' if you are going to use service workers.
|
|
||||||
runSequence(
|
|
||||||
['copy', 'styles'],
|
|
||||||
'elements',
|
|
||||||
['jshint', 'images', 'fonts', 'html'],
|
|
||||||
'vulcanize','rename-index', // 'cache-config',
|
|
||||||
cb);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Load tasks for web-component-tester
|
|
||||||
// Adds tasks for `gulp test:local` and `gulp test:remote`
|
|
||||||
require('web-component-tester').gulp.init(gulp);
|
|
||||||
|
|
||||||
// Load custom tasks from the `tasks` directory
|
|
||||||
try { require('require-dir')('tasks'); } catch (err) {}
|
|
@ -1,39 +0,0 @@
|
|||||||
{
|
|
||||||
"private": true,
|
|
||||||
"devDependencies": {
|
|
||||||
"browser-sync": "^2.7.7",
|
|
||||||
"connect-history-api-fallback": "^1.1.0",
|
|
||||||
"del": "^1.1.1",
|
|
||||||
"glob": "^5.0.6",
|
|
||||||
"gulp": "^3.8.5",
|
|
||||||
"gulp-autoprefixer": "^2.1.0",
|
|
||||||
"gulp-cache": "^0.2.8",
|
|
||||||
"gulp-changed": "^1.0.0",
|
|
||||||
"gulp-cssmin": "^0.1.7",
|
|
||||||
"gulp-if": "^1.2.1",
|
|
||||||
"gulp-imagemin": "^2.2.1",
|
|
||||||
"gulp-jshint": "^1.6.3",
|
|
||||||
"gulp-load-plugins": "^0.10.0",
|
|
||||||
"gulp-minify-html": "^1.0.2",
|
|
||||||
"gulp-rename": "^1.2.0",
|
|
||||||
"gulp-replace": "^0.5.3",
|
|
||||||
"gulp-size": "^1.0.0",
|
|
||||||
"gulp-uglify": "^1.2.0",
|
|
||||||
"gulp-useref": "^1.1.2",
|
|
||||||
"gulp-vulcanize": "^6.0.0",
|
|
||||||
"jshint-stylish": "^2.0.0",
|
|
||||||
"merge-stream": "^0.1.7",
|
|
||||||
"polybuild": "^1.0.5",
|
|
||||||
"require-dir": "^0.3.0",
|
|
||||||
"run-sequence": "^1.0.2",
|
|
||||||
"vulcanize": ">= 1.4.2",
|
|
||||||
"web-component-tester": "^3.1.3"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "gulp test:local",
|
|
||||||
"start": "gulp serve"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.10.0"
|
|
||||||
}
|
|
||||||
}
|
|