forked from Jigsaw-Code/outline-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Jigsaw-Code#251 from Jigsaw-Code/fortuna-refactor
Separate shared metrics code
- Loading branch information
Showing
18 changed files
with
962 additions
and
742 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIJKQIBAAKCAgEAy8RtwobMKZCcvVBkP6oQqb0moUJEv1N2G166p/fr0DjoK8Ei | ||
70xjKGcqDFhXvR75oW4DjSL1jUwSXfI4L8b3Kd71UBqJD2Xpb6upLII6MxIxnanU | ||
hI0a0R7x8G64GgC204YmMB7HN2Z8rxGrC7H0qDCUbn+vKEBSfSxp99XRgRBzk1Z0 | ||
sNPGd0xxDh8Gsm7ViGuDmyEv5ICCrAMVr2vEjyHczqb9FQe7/7JSKrY3rrOFcH0k | ||
V0wtw9nT5wp9uJGxO0EYy5AYma7CKeUC46ijLB16rbNc22FaezsMTHbRnXpks+KT | ||
0Pt8DLO5tjQsZ4yo5vZDb9WzWuMdUkkBIHw/9gUP3Hb+OKjdsdjc6A+sfKXrotBA | ||
UdirlMTs2FzRpDJhAg9qTL/mngJtEBN7wXLhXKPXCZdtH/dBX91QZBbIxNaqeY/A | ||
AKG6VZONGgZcVtU1ix8+uqijABkWprhVLO0jBxkSPZiMy2iTz6p+FJ+zy/ZbRfl+ | ||
YZGjhs6xdklhll1zrCSXBcY2aAUsgQWwZl8hG1ibTcFGq0lxCRdcXeYwX8uuRFwE | ||
ZFBq3yG6SZOR4JZLWrEgLHdb6T7rik2U73cyX+/3x+j2QG65mvqLdisaja3d/961 | ||
Tjj4qFliz5ZWPECVWNigqnmqSe/nv5XPC2A93GM25PHFY+bJlpa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
6aH4he4vEOqwgiWojHh93/G7GnVbBgIFxRmDjAyXoAz8VE8e9QpZBXq5+l0LV8Qm | ||
awlxG0bWvi50hmc2sSOP41E1qK5kbrsRAoIBAQDUDpgJ2HrCKnkIFj3IzPHnw/Ur | ||
+bmWUtfCCP07THH7dYMSfZLMwXwwJeNHtJIo4TUqghcTSH+QJYhCwOkwwexa/F4Z | ||
E3FRy/KBlsjIcL/bEelCK8PpsZd9fYZkrHK+hz7uyiXULrErbkiQo0akze1DghCw | ||
R0gSgkRj2YLZ+2e5Tud/eDC1l9JbVWuAOj1n2/MdxsRIMSMBdTRaivLHuWVi83Gx | ||
yyGuJxy/H9Z0izmDJzbPl3ETf6OLLvJY3tL8qgQrQWajvu8dvGyi2F4KpuaLu29b | ||
pTg7GLNkzLcltLZpcJf9sk0+XJP1Ky07Cqg0qfVSBIzyCQ5XQgAnXy67lOWK | ||
-----END RSA PRIVATE KEY----- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIJKAIBAAKCAgEAnrDtsh/DFaawDjY1XOijPpk1dpJlcKibSLfrTeGJAepT1IS2 | ||
h8s/V1PP4WOqCpHAoukzcJFbyIhAFUsuXlpY32YEAKIHA0dEHvdq/GgluylyZqLv | ||
2r2II+Fm01142ZXQGg+SEI4i0+fkZsWU7HnbmBydJKFpyn5yQv3LMwhaPCZmg5B4 | ||
SxnkeigfrmxfKP2xZ9qoxNivVulf0mlcRl/UkjXqFUCAR6zCUqiMIdZ/JYiaMd+3 | ||
39owVqiTBo2+AdtiO4GxQ964NwqcfL7cdhHslKt8/MUsOuTkAuMWT41SiwUih6nk | ||
E87rgwQbg4Iv70YEcqR6d0JR8VWj8pfPnSTECN4XYFdkE59udS5q6R95v2VF2EKL | ||
MV4R5S+D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hKV6L/Q8YFnVwdWIwdI+cNFRRke9wj3Or | ||
Kss4cQKCAQAEvFkKMY9Kr/LqDup0ly8QtQB5sH6gotcwrk/9Fu8DDYiEhtSicSRh | ||
AL415DlxgT3MWyAfbHq6YOj0epm+BcvqvTUlQdO8L6M6Y4BB+1eRkXsU9OiIuYWz | ||
V5AiHD3oF0dzaCD+/8yJt+Rr+PcBjcflo6LbNacT/WGKJR/Sb8AnbxBl+3rz5Avo | ||
68KOSWQHS4nqWKhAdZXC9UevRc5dvKa5kvYu3Bwd2mm0Skwu6qhdmcMIsgbmRWKd | ||
XzjWhrRofs8CGCdkBYKWVjj3okiJ9+gbFPwco7XkG4FO8HfGDC2QqpBtk7Jy494X | ||
aKCOzxPMqQci2ZY5+qc+APKSnODkFn0BAoIBAEeov1NmKjF9YLzDnCYKpEzT0/CS | ||
K8Ipcq3B5M1wOanrv9lFdSZdmdqY5XWTcSgjNfE75kALUstiUoUVBxmIZY8b/I2t | ||
Vun3shvoHv1Bxj8qKnOPBG93lUC6Xs3/9HrvmXJGPk+keMiglFLPNFmZWV9ElkIv | ||
6Q1E2kE3oGFUmhfQAqJ302QrHnIvcocfrxtsN3rh7s0NTrsadEJunzeW1C8SYXLO | ||
gZtvv5Iw4ulgQD7f3Y7VbUlqarWztLiuGujjlts/jkqMCp+dgWEMPjGxxnyVHk3a | ||
0MQPWJrhqHxBq25tAxu3Gd33WDOPL9wceyyVnpvIUVj7zU35h/sJUM7aHrg= | ||
-----END RSA PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright 2018 The Outline Authors | ||
// | ||
// 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. | ||
|
||
import * as fs from 'fs'; | ||
|
||
import * as file_read from './file_read'; | ||
import * as logging from './logging'; | ||
|
||
export interface JsonConfig<T> { | ||
// Returns a reference (*not* a copy) to the json object backing the config. | ||
data(): T; | ||
// Writes the config to the backing storage. | ||
write(); | ||
} | ||
|
||
export function loadFileConfig<T>(filename: string): JsonConfig<T> { | ||
const text = file_read.readFileIfExists(filename); | ||
let dataJson = {} as T; | ||
if (text) { | ||
dataJson = JSON.parse(text) as T; | ||
} | ||
return new FileConfig<T>(filename, dataJson); | ||
} | ||
|
||
// FileConfig is a JsonConfig backed by a filesystem file. | ||
export class FileConfig<T> implements JsonConfig<T> { | ||
constructor(private filename: string, private dataJson: T) {} | ||
|
||
data(): T { | ||
return this.dataJson; | ||
} | ||
|
||
write() { | ||
// Write to temporary file, then move that temporary file to the | ||
// persistent location, to avoid accidentally breaking the metrics file. | ||
// Use *Sync calls for atomic operations, to guard against corrupting | ||
// these files. | ||
const tempFilename = `${this.filename}.${Date.now()}`; | ||
try { | ||
fs.writeFileSync(tempFilename, JSON.stringify(this.dataJson), {encoding: 'utf8'}); | ||
fs.renameSync(tempFilename, this.filename); | ||
} catch (error) { | ||
// TODO: Stop swalling the exception and handle it in the callers. | ||
logging.error(`Error writing config ${this.filename} ${error}`); | ||
} | ||
} | ||
} | ||
|
||
// ChildConfig is a JsonConfig backed by another config. | ||
export class ChildConfig<T> implements JsonConfig<T> { | ||
constructor(private parentConfig: JsonConfig<{}>, private dataJson: T) {} | ||
|
||
data(): T { | ||
return this.dataJson; | ||
} | ||
|
||
write() { | ||
this.parentConfig.write(); | ||
} | ||
} | ||
|
||
// DelayedConfig is a JsonConfig that only writes the data in a periodic time interval. | ||
// Calls to write() will mark the data as "dirty" for the next inverval. | ||
export class DelayedConfig<T> implements JsonConfig<T> { | ||
private dirty = false; | ||
constructor(private config: JsonConfig<T>, writePeriodMs: number) { | ||
// This repeated call will never be cancelled until the execution is terminated. | ||
setInterval(() => { | ||
if (!this.dirty) { | ||
return; | ||
} | ||
this.config.write(); | ||
this.dirty = false; | ||
}, writePeriodMs); | ||
} | ||
|
||
data(): T { | ||
return this.config.data(); | ||
} | ||
|
||
write() { | ||
this.dirty = true; | ||
} | ||
} | ||
|
||
// InMemoryConfig is a JsonConfig backed by an internal member variable. Useful for testing. | ||
export class InMemoryConfig<T> implements JsonConfig<T> { | ||
// Holds the data JSON as it was when `write()` was called. | ||
public mostRecentWrite: T; | ||
constructor(private dataJson: T) { | ||
this.mostRecentWrite = this.dataJson; | ||
} | ||
|
||
data(): T { | ||
return this.dataJson; | ||
} | ||
|
||
write() { | ||
this.mostRecentWrite = JSON.parse(JSON.stringify(this.dataJson)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.