id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 51 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
244,200 | orbingol/NURBS-Python | geomdl/construct.py | extract_curves | def extract_curves(psurf, **kwargs):
""" Extracts curves from a surface.
The return value is a ``dict`` object containing the following keys:
* ``u``: the curves which generate u-direction (or which lie on the v-direction)
* ``v``: the curves which generate v-direction (or which lie on the u-direction... | python | def extract_curves(psurf, **kwargs):
if psurf.pdimension != 2:
raise GeomdlException("The input should be a spline surface")
if len(psurf) != 1:
raise GeomdlException("Can only operate on single spline surfaces")
# Get keyword arguments
extract_u = kwargs.get('extract_u', True)
extr... | [
"def",
"extract_curves",
"(",
"psurf",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"psurf",
".",
"pdimension",
"!=",
"2",
":",
"raise",
"GeomdlException",
"(",
"\"The input should be a spline surface\"",
")",
"if",
"len",
"(",
"psurf",
")",
"!=",
"1",
":",
"r... | Extracts curves from a surface.
The return value is a ``dict`` object containing the following keys:
* ``u``: the curves which generate u-direction (or which lie on the v-direction)
* ``v``: the curves which generate v-direction (or which lie on the u-direction)
As an example; if a curve lies on the ... | [
"Extracts",
"curves",
"from",
"a",
"surface",
"."
] | b1c6a8b51cf143ff58761438e93ba6baef470627 | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/construct.py#L208-L270 |
244,201 | orbingol/NURBS-Python | geomdl/construct.py | extract_surfaces | def extract_surfaces(pvol):
""" Extracts surfaces from a volume.
:param pvol: input volume
:type pvol: abstract.Volume
:return: extracted surface
:rtype: dict
"""
if pvol.pdimension != 3:
raise GeomdlException("The input should be a spline volume")
if len(pvol) != 1:
rai... | python | def extract_surfaces(pvol):
if pvol.pdimension != 3:
raise GeomdlException("The input should be a spline volume")
if len(pvol) != 1:
raise GeomdlException("Can only operate on single spline volumes")
# Get data from the volume object
vol_data = pvol.data
rational = vol_data['rationa... | [
"def",
"extract_surfaces",
"(",
"pvol",
")",
":",
"if",
"pvol",
".",
"pdimension",
"!=",
"3",
":",
"raise",
"GeomdlException",
"(",
"\"The input should be a spline volume\"",
")",
"if",
"len",
"(",
"pvol",
")",
"!=",
"1",
":",
"raise",
"GeomdlException",
"(",
... | Extracts surfaces from a volume.
:param pvol: input volume
:type pvol: abstract.Volume
:return: extracted surface
:rtype: dict | [
"Extracts",
"surfaces",
"from",
"a",
"volume",
"."
] | b1c6a8b51cf143ff58761438e93ba6baef470627 | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/construct.py#L273-L343 |
244,202 | orbingol/NURBS-Python | geomdl/construct.py | extract_isosurface | def extract_isosurface(pvol):
""" Extracts the largest isosurface from a volume.
The following example illustrates one of the usage scenarios:
.. code-block:: python
:linenos:
from geomdl import construct, multi
from geomdl.visualization import VisMPL
# Assuming that "myv... | python | def extract_isosurface(pvol):
if pvol.pdimension != 3:
raise GeomdlException("The input should be a spline volume")
if len(pvol) != 1:
raise GeomdlException("Can only operate on single spline volumes")
# Extract surfaces from the parametric volume
isosrf = extract_surfaces(pvol)
# ... | [
"def",
"extract_isosurface",
"(",
"pvol",
")",
":",
"if",
"pvol",
".",
"pdimension",
"!=",
"3",
":",
"raise",
"GeomdlException",
"(",
"\"The input should be a spline volume\"",
")",
"if",
"len",
"(",
"pvol",
")",
"!=",
"1",
":",
"raise",
"GeomdlException",
"("... | Extracts the largest isosurface from a volume.
The following example illustrates one of the usage scenarios:
.. code-block:: python
:linenos:
from geomdl import construct, multi
from geomdl.visualization import VisMPL
# Assuming that "myvol" variable stores your spline volume... | [
"Extracts",
"the",
"largest",
"isosurface",
"from",
"a",
"volume",
"."
] | b1c6a8b51cf143ff58761438e93ba6baef470627 | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/construct.py#L346-L383 |
244,203 | orbingol/NURBS-Python | geomdl/trimming.py | check_trim_curve | def check_trim_curve(curve, parbox, **kwargs):
""" Checks if the trim curve was closed and sense was set.
:param curve: trim curve
:param parbox: parameter space bounding box of the underlying surface
:return: a tuple containing the status of the operation and list of extra trim curves generated
:r... | python | def check_trim_curve(curve, parbox, **kwargs):
def next_idx(edge_idx, direction):
tmp = edge_idx + direction
if tmp < 0:
return 3
if tmp > 3:
return 0
return tmp
# Keyword arguments
tol = kwargs.get('tol', 10e-8)
# First, check if the curve is cl... | [
"def",
"check_trim_curve",
"(",
"curve",
",",
"parbox",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"next_idx",
"(",
"edge_idx",
",",
"direction",
")",
":",
"tmp",
"=",
"edge_idx",
"+",
"direction",
"if",
"tmp",
"<",
"0",
":",
"return",
"3",
"if",
"tmp... | Checks if the trim curve was closed and sense was set.
:param curve: trim curve
:param parbox: parameter space bounding box of the underlying surface
:return: a tuple containing the status of the operation and list of extra trim curves generated
:rtype: tuple | [
"Checks",
"if",
"the",
"trim",
"curve",
"was",
"closed",
"and",
"sense",
"was",
"set",
"."
] | b1c6a8b51cf143ff58761438e93ba6baef470627 | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/trimming.py#L174-L278 |
244,204 | orbingol/NURBS-Python | geomdl/trimming.py | get_par_box | def get_par_box(domain, last=False):
""" Returns the bounding box of the surface parametric domain in ccw direction.
:param domain: parametric domain
:type domain: list, tuple
:param last: if True, adds the first vertex to the end of the return list
:type last: bool
:return: edges of the parame... | python | def get_par_box(domain, last=False):
u_range = domain[0]
v_range = domain[1]
verts = [(u_range[0], v_range[0]), (u_range[1], v_range[0]), (u_range[1], v_range[1]), (u_range[0], v_range[1])]
if last:
verts.append(verts[0])
return tuple(verts) | [
"def",
"get_par_box",
"(",
"domain",
",",
"last",
"=",
"False",
")",
":",
"u_range",
"=",
"domain",
"[",
"0",
"]",
"v_range",
"=",
"domain",
"[",
"1",
"]",
"verts",
"=",
"[",
"(",
"u_range",
"[",
"0",
"]",
",",
"v_range",
"[",
"0",
"]",
")",
",... | Returns the bounding box of the surface parametric domain in ccw direction.
:param domain: parametric domain
:type domain: list, tuple
:param last: if True, adds the first vertex to the end of the return list
:type last: bool
:return: edges of the parametric domain
:rtype: tuple | [
"Returns",
"the",
"bounding",
"box",
"of",
"the",
"surface",
"parametric",
"domain",
"in",
"ccw",
"direction",
"."
] | b1c6a8b51cf143ff58761438e93ba6baef470627 | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/trimming.py#L281-L296 |
244,205 | orbingol/NURBS-Python | geomdl/trimming.py | detect_sense | def detect_sense(curve, tol):
""" Detects the sense, i.e. clockwise or counter-clockwise, of the curve.
:param curve: 2-dimensional trim curve
:type curve: abstract.Curve
:param tol: tolerance value
:type tol: float
:return: True if detection is successful, False otherwise
:rtype: bool
... | python | def detect_sense(curve, tol):
if curve.opt_get('reversed') is None:
# Detect sense since it is unset
pts = curve.evalpts
num_pts = len(pts)
for idx in range(1, num_pts - 1):
sense = detect_ccw(pts[idx - 1], pts[idx], pts[idx + 1], tol)
if sense < 0: # cw
... | [
"def",
"detect_sense",
"(",
"curve",
",",
"tol",
")",
":",
"if",
"curve",
".",
"opt_get",
"(",
"'reversed'",
")",
"is",
"None",
":",
"# Detect sense since it is unset",
"pts",
"=",
"curve",
".",
"evalpts",
"num_pts",
"=",
"len",
"(",
"pts",
")",
"for",
"... | Detects the sense, i.e. clockwise or counter-clockwise, of the curve.
:param curve: 2-dimensional trim curve
:type curve: abstract.Curve
:param tol: tolerance value
:type tol: float
:return: True if detection is successful, False otherwise
:rtype: bool | [
"Detects",
"the",
"sense",
"i",
".",
"e",
".",
"clockwise",
"or",
"counter",
"-",
"clockwise",
"of",
"the",
"curve",
"."
] | b1c6a8b51cf143ff58761438e93ba6baef470627 | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/trimming.py#L299-L336 |
244,206 | orbingol/NURBS-Python | geomdl/ray.py | intersect | def intersect(ray1, ray2, **kwargs):
""" Finds intersection of 2 rays.
This functions finds the parameter values for the 1st and 2nd input rays and returns a tuple of
``(parameter for ray1, parameter for ray2, intersection status)``.
``status`` value is a enum type which reports the case which the inte... | python | def intersect(ray1, ray2, **kwargs):
if not isinstance(ray1, Ray) or not isinstance(ray2, Ray):
raise TypeError("The input arguments must be instances of the Ray object")
if ray1.dimension != ray2.dimension:
raise ValueError("Dimensions of the input rays must be the same")
# Keyword argume... | [
"def",
"intersect",
"(",
"ray1",
",",
"ray2",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"isinstance",
"(",
"ray1",
",",
"Ray",
")",
"or",
"not",
"isinstance",
"(",
"ray2",
",",
"Ray",
")",
":",
"raise",
"TypeError",
"(",
"\"The input arguments mu... | Finds intersection of 2 rays.
This functions finds the parameter values for the 1st and 2nd input rays and returns a tuple of
``(parameter for ray1, parameter for ray2, intersection status)``.
``status`` value is a enum type which reports the case which the intersection operation encounters.
The inter... | [
"Finds",
"intersection",
"of",
"2",
"rays",
"."
] | b1c6a8b51cf143ff58761438e93ba6baef470627 | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/ray.py#L107-L150 |
244,207 | orbingol/NURBS-Python | geomdl/freeform.py | Freeform.evaluate | def evaluate(self, **kwargs):
""" Sets points that form the geometry.
Keyword Arguments:
* ``points``: sets the points
"""
self._eval_points = kwargs.get('points', self._init_array())
self._dimension = len(self._eval_points[0]) | python | def evaluate(self, **kwargs):
self._eval_points = kwargs.get('points', self._init_array())
self._dimension = len(self._eval_points[0]) | [
"def",
"evaluate",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_eval_points",
"=",
"kwargs",
".",
"get",
"(",
"'points'",
",",
"self",
".",
"_init_array",
"(",
")",
")",
"self",
".",
"_dimension",
"=",
"len",
"(",
"self",
".",
"_e... | Sets points that form the geometry.
Keyword Arguments:
* ``points``: sets the points | [
"Sets",
"points",
"that",
"form",
"the",
"geometry",
"."
] | b1c6a8b51cf143ff58761438e93ba6baef470627 | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/freeform.py#L20-L27 |
244,208 | orbingol/NURBS-Python | geomdl/exchange_vtk.py | export_polydata | def export_polydata(obj, file_name, **kwargs):
""" Exports control points or evaluated points in VTK Polydata format.
Please see the following document for details: http://www.vtk.org/VTK/img/file-formats.pdf
Keyword Arguments:
* ``point_type``: **ctrlpts** for control points or **evalpts** for ev... | python | def export_polydata(obj, file_name, **kwargs):
content = export_polydata_str(obj, **kwargs)
return exch.write_file(file_name, content) | [
"def",
"export_polydata",
"(",
"obj",
",",
"file_name",
",",
"*",
"*",
"kwargs",
")",
":",
"content",
"=",
"export_polydata_str",
"(",
"obj",
",",
"*",
"*",
"kwargs",
")",
"return",
"exch",
".",
"write_file",
"(",
"file_name",
",",
"content",
")"
] | Exports control points or evaluated points in VTK Polydata format.
Please see the following document for details: http://www.vtk.org/VTK/img/file-formats.pdf
Keyword Arguments:
* ``point_type``: **ctrlpts** for control points or **evalpts** for evaluated points
* ``tessellate``: tessellates th... | [
"Exports",
"control",
"points",
"or",
"evaluated",
"points",
"in",
"VTK",
"Polydata",
"format",
"."
] | b1c6a8b51cf143ff58761438e93ba6baef470627 | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/exchange_vtk.py#L125-L141 |
244,209 | orbingol/NURBS-Python | geomdl/utilities.py | make_zigzag | def make_zigzag(points, num_cols):
""" Converts linear sequence of points into a zig-zag shape.
This function is designed to create input for the visualization software. It orders the points to draw a zig-zag
shape which enables generating properly connected lines without any scanlines. Please see the belo... | python | def make_zigzag(points, num_cols):
new_points = []
points_size = len(points)
forward = True
idx = 0
rev_idx = -1
while idx < points_size:
if forward:
new_points.append(points[idx])
else:
new_points.append(points[rev_idx])
rev_idx -= 1
i... | [
"def",
"make_zigzag",
"(",
"points",
",",
"num_cols",
")",
":",
"new_points",
"=",
"[",
"]",
"points_size",
"=",
"len",
"(",
"points",
")",
"forward",
"=",
"True",
"idx",
"=",
"0",
"rev_idx",
"=",
"-",
"1",
"while",
"idx",
"<",
"points_size",
":",
"i... | Converts linear sequence of points into a zig-zag shape.
This function is designed to create input for the visualization software. It orders the points to draw a zig-zag
shape which enables generating properly connected lines without any scanlines. Please see the below sketch on the
functionality of the ``... | [
"Converts",
"linear",
"sequence",
"of",
"points",
"into",
"a",
"zig",
"-",
"zag",
"shape",
"."
] | b1c6a8b51cf143ff58761438e93ba6baef470627 | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/utilities.py#L40-L80 |
244,210 | orbingol/NURBS-Python | geomdl/utilities.py | make_quad | def make_quad(points, size_u, size_v):
""" Converts linear sequence of input points into a quad structure.
:param points: list of points to be ordered
:type points: list, tuple
:param size_v: number of elements in a row
:type size_v: int
:param size_u: number of elements in a column
:type s... | python | def make_quad(points, size_u, size_v):
# Start with generating a zig-zag shape in row direction and then take its reverse
new_points = make_zigzag(points, size_v)
new_points.reverse()
# Start generating a zig-zag shape in col direction
forward = True
for row in range(0, size_v):
temp = ... | [
"def",
"make_quad",
"(",
"points",
",",
"size_u",
",",
"size_v",
")",
":",
"# Start with generating a zig-zag shape in row direction and then take its reverse",
"new_points",
"=",
"make_zigzag",
"(",
"points",
",",
"size_v",
")",
"new_points",
".",
"reverse",
"(",
")",
... | Converts linear sequence of input points into a quad structure.
:param points: list of points to be ordered
:type points: list, tuple
:param size_v: number of elements in a row
:type size_v: int
:param size_u: number of elements in a column
:type size_u: int
:return: re-ordered points
:... | [
"Converts",
"linear",
"sequence",
"of",
"input",
"points",
"into",
"a",
"quad",
"structure",
"."
] | b1c6a8b51cf143ff58761438e93ba6baef470627 | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/utilities.py#L83-L112 |
244,211 | orbingol/NURBS-Python | geomdl/utilities.py | make_quadtree | def make_quadtree(points, size_u, size_v, **kwargs):
""" Generates a quadtree-like structure from surface control points.
This function generates a 2-dimensional list of control point coordinates. Considering the object-oriented
representation of a quadtree data structure, first dimension of the generated ... | python | def make_quadtree(points, size_u, size_v, **kwargs):
# Get keyword arguments
extrapolate = kwargs.get('extrapolate', True)
# Convert control points array into 2-dimensional form
points2d = []
for i in range(0, size_u):
row_list = []
for j in range(0, size_v):
row_list.ap... | [
"def",
"make_quadtree",
"(",
"points",
",",
"size_u",
",",
"size_v",
",",
"*",
"*",
"kwargs",
")",
":",
"# Get keyword arguments",
"extrapolate",
"=",
"kwargs",
".",
"get",
"(",
"'extrapolate'",
",",
"True",
")",
"# Convert control points array into 2-dimensional fo... | Generates a quadtree-like structure from surface control points.
This function generates a 2-dimensional list of control point coordinates. Considering the object-oriented
representation of a quadtree data structure, first dimension of the generated list corresponds to a list of
*QuadTree* classes. Second ... | [
"Generates",
"a",
"quadtree",
"-",
"like",
"structure",
"from",
"surface",
"control",
"points",
"."
] | b1c6a8b51cf143ff58761438e93ba6baef470627 | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/utilities.py#L115-L189 |
244,212 | orbingol/NURBS-Python | geomdl/utilities.py | evaluate_bounding_box | def evaluate_bounding_box(ctrlpts):
""" Computes the minimum bounding box of the point set.
The (minimum) bounding box is the smallest enclosure in which all the input points lie.
:param ctrlpts: points
:type ctrlpts: list, tuple
:return: bounding box in the format [min, max]
:rtype: tuple
... | python | def evaluate_bounding_box(ctrlpts):
# Estimate dimension from the first element of the control points
dimension = len(ctrlpts[0])
# Evaluate bounding box
bbmin = [float('inf') for _ in range(0, dimension)]
bbmax = [float('-inf') for _ in range(0, dimension)]
for cpt in ctrlpts:
for i, a... | [
"def",
"evaluate_bounding_box",
"(",
"ctrlpts",
")",
":",
"# Estimate dimension from the first element of the control points",
"dimension",
"=",
"len",
"(",
"ctrlpts",
"[",
"0",
"]",
")",
"# Evaluate bounding box",
"bbmin",
"=",
"[",
"float",
"(",
"'inf'",
")",
"for",... | Computes the minimum bounding box of the point set.
The (minimum) bounding box is the smallest enclosure in which all the input points lie.
:param ctrlpts: points
:type ctrlpts: list, tuple
:return: bounding box in the format [min, max]
:rtype: tuple | [
"Computes",
"the",
"minimum",
"bounding",
"box",
"of",
"the",
"point",
"set",
"."
] | b1c6a8b51cf143ff58761438e93ba6baef470627 | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/utilities.py#L192-L216 |
244,213 | orbingol/NURBS-Python | geomdl/_tessellate.py | make_triangle_mesh | def make_triangle_mesh(points, size_u, size_v, **kwargs):
""" Generates a triangular mesh from an array of points.
This function generates a triangular mesh for a NURBS or B-Spline surface on its parametric space.
The input is the surface points and the number of points on the parametric dimensions u and v... | python | def make_triangle_mesh(points, size_u, size_v, **kwargs):
def fix_numbering(vertex_list, triangle_list):
# Initialize variables
final_vertices = []
# Get all vertices inside the triangle list
tri_vertex_ids = []
for tri in triangle_list:
for td in tri.data:
... | [
"def",
"make_triangle_mesh",
"(",
"points",
",",
"size_u",
",",
"size_v",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"fix_numbering",
"(",
"vertex_list",
",",
"triangle_list",
")",
":",
"# Initialize variables",
"final_vertices",
"=",
"[",
"]",
"# Get all vertice... | Generates a triangular mesh from an array of points.
This function generates a triangular mesh for a NURBS or B-Spline surface on its parametric space.
The input is the surface points and the number of points on the parametric dimensions u and v,
indicated as row and column sizes in the function signature.... | [
"Generates",
"a",
"triangular",
"mesh",
"from",
"an",
"array",
"of",
"points",
"."
] | b1c6a8b51cf143ff58761438e93ba6baef470627 | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/_tessellate.py#L18-L148 |
244,214 | orbingol/NURBS-Python | geomdl/_tessellate.py | polygon_triangulate | def polygon_triangulate(tri_idx, *args):
""" Triangulates a monotone polygon defined by a list of vertices.
The input vertices must form a convex polygon and must be arranged in counter-clockwise order.
:param tri_idx: triangle numbering start value
:type tri_idx: int
:param args: list of Vertex o... | python | def polygon_triangulate(tri_idx, *args):
# Initialize variables
tidx = 0
triangles = []
# Generate triangles
for idx in range(1, len(args) - 1):
tri = Triangle()
tri.id = tri_idx + tidx
tri.add_vertex(args[0], args[idx], args[idx + 1])
triangles.append(tri)
t... | [
"def",
"polygon_triangulate",
"(",
"tri_idx",
",",
"*",
"args",
")",
":",
"# Initialize variables",
"tidx",
"=",
"0",
"triangles",
"=",
"[",
"]",
"# Generate triangles",
"for",
"idx",
"in",
"range",
"(",
"1",
",",
"len",
"(",
"args",
")",
"-",
"1",
")",
... | Triangulates a monotone polygon defined by a list of vertices.
The input vertices must form a convex polygon and must be arranged in counter-clockwise order.
:param tri_idx: triangle numbering start value
:type tri_idx: int
:param args: list of Vertex objects
:type args: Vertex
:return: list o... | [
"Triangulates",
"a",
"monotone",
"polygon",
"defined",
"by",
"a",
"list",
"of",
"vertices",
"."
] | b1c6a8b51cf143ff58761438e93ba6baef470627 | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/_tessellate.py#L151-L176 |
244,215 | orbingol/NURBS-Python | geomdl/_tessellate.py | make_quad_mesh | def make_quad_mesh(points, size_u, size_v):
""" Generates a mesh of quadrilateral elements.
:param points: list of points
:type points: list, tuple
:param size_u: number of points on the u-direction (column)
:type size_u: int
:param size_v: number of points on the v-direction (row)
:type si... | python | def make_quad_mesh(points, size_u, size_v):
# Numbering
vertex_idx = 0
quad_idx = 0
# Generate vertices
vertices = []
for pt in points:
vrt = Vertex(*pt, id=vertex_idx)
vertices.append(vrt)
vertex_idx += 1
# Generate quads
quads = []
for i in range(0, size_u... | [
"def",
"make_quad_mesh",
"(",
"points",
",",
"size_u",
",",
"size_v",
")",
":",
"# Numbering",
"vertex_idx",
"=",
"0",
"quad_idx",
"=",
"0",
"# Generate vertices",
"vertices",
"=",
"[",
"]",
"for",
"pt",
"in",
"points",
":",
"vrt",
"=",
"Vertex",
"(",
"*... | Generates a mesh of quadrilateral elements.
:param points: list of points
:type points: list, tuple
:param size_u: number of points on the u-direction (column)
:type size_u: int
:param size_v: number of points on the v-direction (row)
:type size_v: int
:return: a tuple containing lists of v... | [
"Generates",
"a",
"mesh",
"of",
"quadrilateral",
"elements",
"."
] | b1c6a8b51cf143ff58761438e93ba6baef470627 | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/_tessellate.py#L179-L214 |
244,216 | orbingol/NURBS-Python | geomdl/_tessellate.py | surface_tessellate | def surface_tessellate(v1, v2, v3, v4, vidx, tidx, trim_curves, tessellate_args):
""" Triangular tessellation algorithm for surfaces with no trims.
This function can be directly used as an input to :func:`.make_triangle_mesh` using ``tessellate_func`` keyword
argument.
:param v1: vertex 1
:type v1... | python | def surface_tessellate(v1, v2, v3, v4, vidx, tidx, trim_curves, tessellate_args):
# Triangulate vertices
tris = polygon_triangulate(tidx, v1, v2, v3, v4)
# Return vertex and triangle lists
return [], tris | [
"def",
"surface_tessellate",
"(",
"v1",
",",
"v2",
",",
"v3",
",",
"v4",
",",
"vidx",
",",
"tidx",
",",
"trim_curves",
",",
"tessellate_args",
")",
":",
"# Triangulate vertices",
"tris",
"=",
"polygon_triangulate",
"(",
"tidx",
",",
"v1",
",",
"v2",
",",
... | Triangular tessellation algorithm for surfaces with no trims.
This function can be directly used as an input to :func:`.make_triangle_mesh` using ``tessellate_func`` keyword
argument.
:param v1: vertex 1
:type v1: Vertex
:param v2: vertex 2
:type v2: Vertex
:param v3: vertex 3
:type v3... | [
"Triangular",
"tessellation",
"algorithm",
"for",
"surfaces",
"with",
"no",
"trims",
"."
] | b1c6a8b51cf143ff58761438e93ba6baef470627 | https://github.com/orbingol/NURBS-Python/blob/b1c6a8b51cf143ff58761438e93ba6baef470627/geomdl/_tessellate.py#L217-L246 |
244,217 | Bearle/django-private-chat | django_private_chat/handlers.py | gone_online | def gone_online(stream):
"""
Distributes the users online status to everyone he has dialog with
"""
while True:
packet = yield from stream.get()
session_id = packet.get('session_key')
if session_id:
user_owner = get_user_from_session(session_id)
i... | python | def gone_online(stream):
while True:
packet = yield from stream.get()
session_id = packet.get('session_key')
if session_id:
user_owner = get_user_from_session(session_id)
if user_owner:
logger.debug('User ' + user_owner.username + ' gone online'... | [
"def",
"gone_online",
"(",
"stream",
")",
":",
"while",
"True",
":",
"packet",
"=",
"yield",
"from",
"stream",
".",
"get",
"(",
")",
"session_id",
"=",
"packet",
".",
"get",
"(",
"'session_key'",
")",
"if",
"session_id",
":",
"user_owner",
"=",
"get_user... | Distributes the users online status to everyone he has dialog with | [
"Distributes",
"the",
"users",
"online",
"status",
"to",
"everyone",
"he",
"has",
"dialog",
"with"
] | 5b51e65875795c5c0ce21bb631c53bd3aac4c26b | https://github.com/Bearle/django-private-chat/blob/5b51e65875795c5c0ce21bb631c53bd3aac4c26b/django_private_chat/handlers.py#L40-L60 |
244,218 | Bearle/django-private-chat | django_private_chat/handlers.py | new_messages_handler | def new_messages_handler(stream):
"""
Saves a new chat message to db and distributes msg to connected users
"""
# TODO: handle no user found exception
while True:
packet = yield from stream.get()
session_id = packet.get('session_key')
msg = packet.get('message')
... | python | def new_messages_handler(stream):
# TODO: handle no user found exception
while True:
packet = yield from stream.get()
session_id = packet.get('session_key')
msg = packet.get('message')
username_opponent = packet.get('username')
if session_id and msg and username_op... | [
"def",
"new_messages_handler",
"(",
"stream",
")",
":",
"# TODO: handle no user found exception\r",
"while",
"True",
":",
"packet",
"=",
"yield",
"from",
"stream",
".",
"get",
"(",
")",
"session_id",
"=",
"packet",
".",
"get",
"(",
"'session_key'",
")",
"msg",
... | Saves a new chat message to db and distributes msg to connected users | [
"Saves",
"a",
"new",
"chat",
"message",
"to",
"db",
"and",
"distributes",
"msg",
"to",
"connected",
"users"
] | 5b51e65875795c5c0ce21bb631c53bd3aac4c26b | https://github.com/Bearle/django-private-chat/blob/5b51e65875795c5c0ce21bb631c53bd3aac4c26b/django_private_chat/handlers.py#L118-L165 |
244,219 | Bearle/django-private-chat | django_private_chat/handlers.py | users_changed_handler | def users_changed_handler(stream):
"""
Sends connected client list of currently active users in the chatroom
"""
while True:
yield from stream.get()
# Get list list of current active users
users = [
{'username': username, 'uuid': uuid_str}
for u... | python | def users_changed_handler(stream):
while True:
yield from stream.get()
# Get list list of current active users
users = [
{'username': username, 'uuid': uuid_str}
for username, uuid_str in ws_connections.values()
]
# Make packet with list of... | [
"def",
"users_changed_handler",
"(",
"stream",
")",
":",
"while",
"True",
":",
"yield",
"from",
"stream",
".",
"get",
"(",
")",
"# Get list list of current active users\r",
"users",
"=",
"[",
"{",
"'username'",
":",
"username",
",",
"'uuid'",
":",
"uuid_str",
... | Sends connected client list of currently active users in the chatroom | [
"Sends",
"connected",
"client",
"list",
"of",
"currently",
"active",
"users",
"in",
"the",
"chatroom"
] | 5b51e65875795c5c0ce21bb631c53bd3aac4c26b | https://github.com/Bearle/django-private-chat/blob/5b51e65875795c5c0ce21bb631c53bd3aac4c26b/django_private_chat/handlers.py#L169-L188 |
244,220 | Bearle/django-private-chat | django_private_chat/handlers.py | is_typing_handler | def is_typing_handler(stream):
"""
Show message to opponent if user is typing message
"""
while True:
packet = yield from stream.get()
session_id = packet.get('session_key')
user_opponent = packet.get('username')
typing = packet.get('typing')
if session_i... | python | def is_typing_handler(stream):
while True:
packet = yield from stream.get()
session_id = packet.get('session_key')
user_opponent = packet.get('username')
typing = packet.get('typing')
if session_id and user_opponent and typing is not None:
user_owner = get_... | [
"def",
"is_typing_handler",
"(",
"stream",
")",
":",
"while",
"True",
":",
"packet",
"=",
"yield",
"from",
"stream",
".",
"get",
"(",
")",
"session_id",
"=",
"packet",
".",
"get",
"(",
"'session_key'",
")",
"user_opponent",
"=",
"packet",
".",
"get",
"("... | Show message to opponent if user is typing message | [
"Show",
"message",
"to",
"opponent",
"if",
"user",
"is",
"typing",
"message"
] | 5b51e65875795c5c0ce21bb631c53bd3aac4c26b | https://github.com/Bearle/django-private-chat/blob/5b51e65875795c5c0ce21bb631c53bd3aac4c26b/django_private_chat/handlers.py#L192-L211 |
244,221 | Bearle/django-private-chat | django_private_chat/handlers.py | read_message_handler | def read_message_handler(stream):
"""
Send message to user if the opponent has read the message
"""
while True:
packet = yield from stream.get()
session_id = packet.get('session_key')
user_opponent = packet.get('username')
message_id = packet.get('message_id')
... | python | def read_message_handler(stream):
while True:
packet = yield from stream.get()
session_id = packet.get('session_key')
user_opponent = packet.get('username')
message_id = packet.get('message_id')
if session_id and user_opponent and message_id is not None:
us... | [
"def",
"read_message_handler",
"(",
"stream",
")",
":",
"while",
"True",
":",
"packet",
"=",
"yield",
"from",
"stream",
".",
"get",
"(",
")",
"session_id",
"=",
"packet",
".",
"get",
"(",
"'session_key'",
")",
"user_opponent",
"=",
"packet",
".",
"get",
... | Send message to user if the opponent has read the message | [
"Send",
"message",
"to",
"user",
"if",
"the",
"opponent",
"has",
"read",
"the",
"message"
] | 5b51e65875795c5c0ce21bb631c53bd3aac4c26b | https://github.com/Bearle/django-private-chat/blob/5b51e65875795c5c0ce21bb631c53bd3aac4c26b/django_private_chat/handlers.py#L215-L242 |
244,222 | Bearle/django-private-chat | django_private_chat/handlers.py | main_handler | def main_handler(websocket, path):
"""
An Asyncio Task is created for every new websocket client connection
that is established. This coroutine listens to messages from the connected
client and routes the message to the proper queue.
This coroutine can be thought of as a producer.
"""
... | python | def main_handler(websocket, path):
# Get users name from the path
path = path.split('/')
username = path[2]
session_id = path[1]
user_owner = get_user_from_session(session_id)
if user_owner:
user_owner = user_owner.username
# Persist users connection, associate user w/a u... | [
"def",
"main_handler",
"(",
"websocket",
",",
"path",
")",
":",
"# Get users name from the path\r",
"path",
"=",
"path",
".",
"split",
"(",
"'/'",
")",
"username",
"=",
"path",
"[",
"2",
"]",
"session_id",
"=",
"path",
"[",
"1",
"]",
"user_owner",
"=",
"... | An Asyncio Task is created for every new websocket client connection
that is established. This coroutine listens to messages from the connected
client and routes the message to the proper queue.
This coroutine can be thought of as a producer. | [
"An",
"Asyncio",
"Task",
"is",
"created",
"for",
"every",
"new",
"websocket",
"client",
"connection",
"that",
"is",
"established",
".",
"This",
"coroutine",
"listens",
"to",
"messages",
"from",
"the",
"connected",
"client",
"and",
"routes",
"the",
"message",
"... | 5b51e65875795c5c0ce21bb631c53bd3aac4c26b | https://github.com/Bearle/django-private-chat/blob/5b51e65875795c5c0ce21bb631c53bd3aac4c26b/django_private_chat/handlers.py#L246-L283 |
244,223 | blockstack/blockstack-core | api/search/substring_search.py | anyword_substring_search_inner | def anyword_substring_search_inner(query_word, target_words):
""" return True if ANY target_word matches a query_word
"""
for target_word in target_words:
if(target_word.startswith(query_word)):
return query_word
return False | python | def anyword_substring_search_inner(query_word, target_words):
for target_word in target_words:
if(target_word.startswith(query_word)):
return query_word
return False | [
"def",
"anyword_substring_search_inner",
"(",
"query_word",
",",
"target_words",
")",
":",
"for",
"target_word",
"in",
"target_words",
":",
"if",
"(",
"target_word",
".",
"startswith",
"(",
"query_word",
")",
")",
":",
"return",
"query_word",
"return",
"False"
] | return True if ANY target_word matches a query_word | [
"return",
"True",
"if",
"ANY",
"target_word",
"matches",
"a",
"query_word"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/api/search/substring_search.py#L41-L50 |
244,224 | blockstack/blockstack-core | api/search/substring_search.py | anyword_substring_search | def anyword_substring_search(target_words, query_words):
""" return True if all query_words match
"""
matches_required = len(query_words)
matches_found = 0
for query_word in query_words:
reply = anyword_substring_search_inner(query_word, target_words)
if reply is not False:
... | python | def anyword_substring_search(target_words, query_words):
matches_required = len(query_words)
matches_found = 0
for query_word in query_words:
reply = anyword_substring_search_inner(query_word, target_words)
if reply is not False:
matches_found += 1
else:
... | [
"def",
"anyword_substring_search",
"(",
"target_words",
",",
"query_words",
")",
":",
"matches_required",
"=",
"len",
"(",
"query_words",
")",
"matches_found",
"=",
"0",
"for",
"query_word",
"in",
"query_words",
":",
"reply",
"=",
"anyword_substring_search_inner",
"... | return True if all query_words match | [
"return",
"True",
"if",
"all",
"query_words",
"match"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/api/search/substring_search.py#L53-L76 |
244,225 | blockstack/blockstack-core | api/search/substring_search.py | substring_search | def substring_search(query, list_of_strings, limit_results=DEFAULT_LIMIT):
""" main function to call for searching
"""
matching = []
query_words = query.split(' ')
# sort by longest word (higest probability of not finding a match)
query_words.sort(key=len, reverse=True)
counter = 0
... | python | def substring_search(query, list_of_strings, limit_results=DEFAULT_LIMIT):
matching = []
query_words = query.split(' ')
# sort by longest word (higest probability of not finding a match)
query_words.sort(key=len, reverse=True)
counter = 0
for s in list_of_strings:
target_words = s.s... | [
"def",
"substring_search",
"(",
"query",
",",
"list_of_strings",
",",
"limit_results",
"=",
"DEFAULT_LIMIT",
")",
":",
"matching",
"=",
"[",
"]",
"query_words",
"=",
"query",
".",
"split",
"(",
"' '",
")",
"# sort by longest word (higest probability of not finding a m... | main function to call for searching | [
"main",
"function",
"to",
"call",
"for",
"searching"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/api/search/substring_search.py#L79-L105 |
244,226 | blockstack/blockstack-core | api/search/substring_search.py | search_people_by_bio | def search_people_by_bio(query, limit_results=DEFAULT_LIMIT,
index=['onename_people_index']):
""" queries lucene index to find a nearest match, output is profile username
"""
from pyes import QueryStringQuery, ES
conn = ES()
q = QueryStringQuery(query,
... | python | def search_people_by_bio(query, limit_results=DEFAULT_LIMIT,
index=['onename_people_index']):
from pyes import QueryStringQuery, ES
conn = ES()
q = QueryStringQuery(query,
search_fields=['username', 'profile_bio'],
default_operator=... | [
"def",
"search_people_by_bio",
"(",
"query",
",",
"limit_results",
"=",
"DEFAULT_LIMIT",
",",
"index",
"=",
"[",
"'onename_people_index'",
"]",
")",
":",
"from",
"pyes",
"import",
"QueryStringQuery",
",",
"ES",
"conn",
"=",
"ES",
"(",
")",
"q",
"=",
"QuerySt... | queries lucene index to find a nearest match, output is profile username | [
"queries",
"lucene",
"index",
"to",
"find",
"a",
"nearest",
"match",
"output",
"is",
"profile",
"username"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/api/search/substring_search.py#L172-L210 |
244,227 | blockstack/blockstack-core | api/search/substring_search.py | order_search_results | def order_search_results(query, search_results):
""" order of results should be a) query in first name, b) query in last name
"""
results = search_results
results_names = []
old_query = query
query = query.split(' ')
first_word = ''
second_word = ''
third_word = ''
if(len(que... | python | def order_search_results(query, search_results):
results = search_results
results_names = []
old_query = query
query = query.split(' ')
first_word = ''
second_word = ''
third_word = ''
if(len(query) < 2):
first_word = old_query
else:
first_word = query[0]
s... | [
"def",
"order_search_results",
"(",
"query",
",",
"search_results",
")",
":",
"results",
"=",
"search_results",
"results_names",
"=",
"[",
"]",
"old_query",
"=",
"query",
"query",
"=",
"query",
".",
"split",
"(",
"' '",
")",
"first_word",
"=",
"''",
"second_... | order of results should be a) query in first name, b) query in last name | [
"order",
"of",
"results",
"should",
"be",
"a",
")",
"query",
"in",
"first",
"name",
"b",
")",
"query",
"in",
"last",
"name"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/api/search/substring_search.py#L242-L295 |
244,228 | blockstack/blockstack-core | blockstack/lib/storage/auth.py | get_data_hash | def get_data_hash(data_txt):
"""
Generate a hash over data for immutable storage.
Return the hex string.
"""
h = hashlib.sha256()
h.update(data_txt)
return h.hexdigest() | python | def get_data_hash(data_txt):
h = hashlib.sha256()
h.update(data_txt)
return h.hexdigest() | [
"def",
"get_data_hash",
"(",
"data_txt",
")",
":",
"h",
"=",
"hashlib",
".",
"sha256",
"(",
")",
"h",
".",
"update",
"(",
"data_txt",
")",
"return",
"h",
".",
"hexdigest",
"(",
")"
] | Generate a hash over data for immutable storage.
Return the hex string. | [
"Generate",
"a",
"hash",
"over",
"data",
"for",
"immutable",
"storage",
".",
"Return",
"the",
"hex",
"string",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/storage/auth.py#L32-L39 |
244,229 | blockstack/blockstack-core | blockstack/lib/storage/auth.py | verify_zonefile | def verify_zonefile( zonefile_str, value_hash ):
"""
Verify that a zonefile hashes to the given value hash
@zonefile_str must be the zonefile as a serialized string
"""
zonefile_hash = get_zonefile_data_hash( zonefile_str )
if zonefile_hash != value_hash:
log.debug("Zonefile hash mismatc... | python | def verify_zonefile( zonefile_str, value_hash ):
zonefile_hash = get_zonefile_data_hash( zonefile_str )
if zonefile_hash != value_hash:
log.debug("Zonefile hash mismatch: expected %s, got %s" % (value_hash, zonefile_hash))
return False
return True | [
"def",
"verify_zonefile",
"(",
"zonefile_str",
",",
"value_hash",
")",
":",
"zonefile_hash",
"=",
"get_zonefile_data_hash",
"(",
"zonefile_str",
")",
"if",
"zonefile_hash",
"!=",
"value_hash",
":",
"log",
".",
"debug",
"(",
"\"Zonefile hash mismatch: expected %s, got %s... | Verify that a zonefile hashes to the given value hash
@zonefile_str must be the zonefile as a serialized string | [
"Verify",
"that",
"a",
"zonefile",
"hashes",
"to",
"the",
"given",
"value",
"hash"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/storage/auth.py#L50-L60 |
244,230 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_peer_table_lock | def atlas_peer_table_lock():
"""
Lock the global health info table.
Return the table.
"""
global PEER_TABLE_LOCK, PEER_TABLE, PEER_TABLE_LOCK_HOLDER, PEER_TABLE_LOCK_TRACEBACK
if PEER_TABLE_LOCK_HOLDER is not None:
assert PEER_TABLE_LOCK_HOLDER != threading.current_thread(), "DEADLOCK"
... | python | def atlas_peer_table_lock():
global PEER_TABLE_LOCK, PEER_TABLE, PEER_TABLE_LOCK_HOLDER, PEER_TABLE_LOCK_TRACEBACK
if PEER_TABLE_LOCK_HOLDER is not None:
assert PEER_TABLE_LOCK_HOLDER != threading.current_thread(), "DEADLOCK"
# log.warning("\n\nPossible contention: lock from %s (but held by %s ... | [
"def",
"atlas_peer_table_lock",
"(",
")",
":",
"global",
"PEER_TABLE_LOCK",
",",
"PEER_TABLE",
",",
"PEER_TABLE_LOCK_HOLDER",
",",
"PEER_TABLE_LOCK_TRACEBACK",
"if",
"PEER_TABLE_LOCK_HOLDER",
"is",
"not",
"None",
":",
"assert",
"PEER_TABLE_LOCK_HOLDER",
"!=",
"threading",... | Lock the global health info table.
Return the table. | [
"Lock",
"the",
"global",
"health",
"info",
"table",
".",
"Return",
"the",
"table",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L352-L368 |
244,231 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_peer_table_unlock | def atlas_peer_table_unlock():
"""
Unlock the global health info table.
"""
global PEER_TABLE_LOCK, PEER_TABLE_LOCK_HOLDER, PEER_TABLE_LOCK_TRACEBACK
try:
assert PEER_TABLE_LOCK_HOLDER == threading.current_thread()
except:
log.error("Locked by %s, unlocked by %s" % (PEER_TAB... | python | def atlas_peer_table_unlock():
global PEER_TABLE_LOCK, PEER_TABLE_LOCK_HOLDER, PEER_TABLE_LOCK_TRACEBACK
try:
assert PEER_TABLE_LOCK_HOLDER == threading.current_thread()
except:
log.error("Locked by %s, unlocked by %s" % (PEER_TABLE_LOCK_HOLDER, threading.current_thread()))
log.... | [
"def",
"atlas_peer_table_unlock",
"(",
")",
":",
"global",
"PEER_TABLE_LOCK",
",",
"PEER_TABLE_LOCK_HOLDER",
",",
"PEER_TABLE_LOCK_TRACEBACK",
"try",
":",
"assert",
"PEER_TABLE_LOCK_HOLDER",
"==",
"threading",
".",
"current_thread",
"(",
")",
"except",
":",
"log",
"."... | Unlock the global health info table. | [
"Unlock",
"the",
"global",
"health",
"info",
"table",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L387-L405 |
244,232 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_format_query | def atlasdb_format_query( query, values ):
"""
Turn a query into a string for printing.
Useful for debugging.
"""
return "".join( ["%s %s" % (frag, "'%s'" % val if type(val) in [str, unicode] else val) for (frag, val) in zip(query.split("?"), values + ("",))] ) | python | def atlasdb_format_query( query, values ):
return "".join( ["%s %s" % (frag, "'%s'" % val if type(val) in [str, unicode] else val) for (frag, val) in zip(query.split("?"), values + ("",))] ) | [
"def",
"atlasdb_format_query",
"(",
"query",
",",
"values",
")",
":",
"return",
"\"\"",
".",
"join",
"(",
"[",
"\"%s %s\"",
"%",
"(",
"frag",
",",
"\"'%s'\"",
"%",
"val",
"if",
"type",
"(",
"val",
")",
"in",
"[",
"str",
",",
"unicode",
"]",
"else",
... | Turn a query into a string for printing.
Useful for debugging. | [
"Turn",
"a",
"query",
"into",
"a",
"string",
"for",
"printing",
".",
"Useful",
"for",
"debugging",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L532-L537 |
244,233 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_open | def atlasdb_open( path ):
"""
Open the atlas db.
Return a connection.
Return None if it doesn't exist
"""
if not os.path.exists(path):
log.debug("Atlas DB doesn't exist at %s" % path)
return None
con = sqlite3.connect( path, isolation_level=None )
con.row_factory = atlas... | python | def atlasdb_open( path ):
if not os.path.exists(path):
log.debug("Atlas DB doesn't exist at %s" % path)
return None
con = sqlite3.connect( path, isolation_level=None )
con.row_factory = atlasdb_row_factory
return con | [
"def",
"atlasdb_open",
"(",
"path",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"log",
".",
"debug",
"(",
"\"Atlas DB doesn't exist at %s\"",
"%",
"path",
")",
"return",
"None",
"con",
"=",
"sqlite3",
".",
"connect",
... | Open the atlas db.
Return a connection.
Return None if it doesn't exist | [
"Open",
"the",
"atlas",
"db",
".",
"Return",
"a",
"connection",
".",
"Return",
"None",
"if",
"it",
"doesn",
"t",
"exist"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L550-L562 |
244,234 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_add_zonefile_info | def atlasdb_add_zonefile_info( name, zonefile_hash, txid, present, tried_storage, block_height, con=None, path=None ):
"""
Add a zonefile to the database.
Mark it as present or absent.
Keep our in-RAM inventory vector up-to-date
"""
global ZONEFILE_INV, NUM_ZONEFILES, ZONEFILE_INV_LOCK
with... | python | def atlasdb_add_zonefile_info( name, zonefile_hash, txid, present, tried_storage, block_height, con=None, path=None ):
global ZONEFILE_INV, NUM_ZONEFILES, ZONEFILE_INV_LOCK
with AtlasDBOpen( con=con, path=path ) as dbcon:
with ZONEFILE_INV_LOCK:
# need to lock here since someone could call ... | [
"def",
"atlasdb_add_zonefile_info",
"(",
"name",
",",
"zonefile_hash",
",",
"txid",
",",
"present",
",",
"tried_storage",
",",
"block_height",
",",
"con",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"global",
"ZONEFILE_INV",
",",
"NUM_ZONEFILES",
",",
"... | Add a zonefile to the database.
Mark it as present or absent.
Keep our in-RAM inventory vector up-to-date | [
"Add",
"a",
"zonefile",
"to",
"the",
"database",
".",
"Mark",
"it",
"as",
"present",
"or",
"absent",
".",
"Keep",
"our",
"in",
"-",
"RAM",
"inventory",
"vector",
"up",
"-",
"to",
"-",
"date"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L565-L616 |
244,235 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_get_lastblock | def atlasdb_get_lastblock( con=None, path=None ):
"""
Get the highest block height in the atlas db
"""
row = None
with AtlasDBOpen(con=con, path=path) as dbcon:
sql = "SELECT MAX(block_height) FROM zonefiles;"
args = ()
cur = dbcon.cursor()
res = atlasdb_query_execu... | python | def atlasdb_get_lastblock( con=None, path=None ):
row = None
with AtlasDBOpen(con=con, path=path) as dbcon:
sql = "SELECT MAX(block_height) FROM zonefiles;"
args = ()
cur = dbcon.cursor()
res = atlasdb_query_execute( cur, sql, args )
row = {}
for r in res:
... | [
"def",
"atlasdb_get_lastblock",
"(",
"con",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"row",
"=",
"None",
"with",
"AtlasDBOpen",
"(",
"con",
"=",
"con",
",",
"path",
"=",
"path",
")",
"as",
"dbcon",
":",
"sql",
"=",
"\"SELECT MAX(block_height) FRO... | Get the highest block height in the atlas db | [
"Get",
"the",
"highest",
"block",
"height",
"in",
"the",
"atlas",
"db"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L619-L637 |
244,236 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_get_zonefiles_missing_count_by_name | def atlasdb_get_zonefiles_missing_count_by_name(name, max_index=None, indexes_exclude=[], con=None, path=None):
"""
Get the number of missing zone files for a particular name, optionally up to a maximum
zonefile index and optionally omitting particular zone files in the count.
Returns an integer
"""... | python | def atlasdb_get_zonefiles_missing_count_by_name(name, max_index=None, indexes_exclude=[], con=None, path=None):
with AtlasDBOpen(con=con, path=path) as dbcon:
sql = 'SELECT COUNT(*) FROM zonefiles WHERE name = ? AND present = 0 {} {};'.format(
'AND inv_index <= ?' if max_index is not None el... | [
"def",
"atlasdb_get_zonefiles_missing_count_by_name",
"(",
"name",
",",
"max_index",
"=",
"None",
",",
"indexes_exclude",
"=",
"[",
"]",
",",
"con",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"with",
"AtlasDBOpen",
"(",
"con",
"=",
"con",
",",
"path"... | Get the number of missing zone files for a particular name, optionally up to a maximum
zonefile index and optionally omitting particular zone files in the count.
Returns an integer | [
"Get",
"the",
"number",
"of",
"missing",
"zone",
"files",
"for",
"a",
"particular",
"name",
"optionally",
"up",
"to",
"a",
"maximum",
"zonefile",
"index",
"and",
"optionally",
"omitting",
"particular",
"zone",
"files",
"in",
"the",
"count",
".",
"Returns",
"... | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L764-L783 |
244,237 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_get_zonefiles_by_hash | def atlasdb_get_zonefiles_by_hash(zonefile_hash, block_height=None, con=None, path=None):
"""
Find all instances of this zone file in the atlasdb.
Optionally filter on block height
Returns [{'name': ..., 'zonefile_hash': ..., 'txid': ..., 'inv_index': ..., 'block_height': ..., 'present': ..., 'tried_st... | python | def atlasdb_get_zonefiles_by_hash(zonefile_hash, block_height=None, con=None, path=None):
with AtlasDBOpen(con=con, path=path) as dbcon:
sql = 'SELECT * FROM zonefiles WHERE zonefile_hash = ?'
args = (zonefile_hash,)
if block_height:
sql += ' AND block_height = ?'
a... | [
"def",
"atlasdb_get_zonefiles_by_hash",
"(",
"zonefile_hash",
",",
"block_height",
"=",
"None",
",",
"con",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"with",
"AtlasDBOpen",
"(",
"con",
"=",
"con",
",",
"path",
"=",
"path",
")",
"as",
"dbcon",
":",... | Find all instances of this zone file in the atlasdb.
Optionally filter on block height
Returns [{'name': ..., 'zonefile_hash': ..., 'txid': ..., 'inv_index': ..., 'block_height': ..., 'present': ..., 'tried_storage': ...}], in blockchain order
Returns None if the zone file is not in the db, or if block_hei... | [
"Find",
"all",
"instances",
"of",
"this",
"zone",
"file",
"in",
"the",
"atlasdb",
".",
"Optionally",
"filter",
"on",
"block",
"height"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L786-L817 |
244,238 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_set_zonefile_tried_storage | def atlasdb_set_zonefile_tried_storage( zonefile_hash, tried_storage, con=None, path=None ):
"""
Make a note that we tried to get the zonefile from storage
"""
with AtlasDBOpen(con=con, path=path) as dbcon:
if tried_storage:
tried_storage = 1
else:
tried_storage =... | python | def atlasdb_set_zonefile_tried_storage( zonefile_hash, tried_storage, con=None, path=None ):
with AtlasDBOpen(con=con, path=path) as dbcon:
if tried_storage:
tried_storage = 1
else:
tried_storage = 0
sql = "UPDATE zonefiles SET tried_storage = ? WHERE zonefile_hash =... | [
"def",
"atlasdb_set_zonefile_tried_storage",
"(",
"zonefile_hash",
",",
"tried_storage",
",",
"con",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"with",
"AtlasDBOpen",
"(",
"con",
"=",
"con",
",",
"path",
"=",
"path",
")",
"as",
"dbcon",
":",
"if",
... | Make a note that we tried to get the zonefile from storage | [
"Make",
"a",
"note",
"that",
"we",
"tried",
"to",
"get",
"the",
"zonefile",
"from",
"storage"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L865-L882 |
244,239 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_reset_zonefile_tried_storage | def atlasdb_reset_zonefile_tried_storage( con=None, path=None ):
"""
For zonefiles that we don't have, re-attempt to fetch them from storage.
"""
with AtlasDBOpen(con=con, path=path) as dbcon:
sql = "UPDATE zonefiles SET tried_storage = ? WHERE present = ?;"
args = (0, 0)
cur ... | python | def atlasdb_reset_zonefile_tried_storage( con=None, path=None ):
with AtlasDBOpen(con=con, path=path) as dbcon:
sql = "UPDATE zonefiles SET tried_storage = ? WHERE present = ?;"
args = (0, 0)
cur = dbcon.cursor()
res = atlasdb_query_execute( cur, sql, args )
dbcon.commit()
... | [
"def",
"atlasdb_reset_zonefile_tried_storage",
"(",
"con",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"with",
"AtlasDBOpen",
"(",
"con",
"=",
"con",
",",
"path",
"=",
"path",
")",
"as",
"dbcon",
":",
"sql",
"=",
"\"UPDATE zonefiles SET tried_storage = ? ... | For zonefiles that we don't have, re-attempt to fetch them from storage. | [
"For",
"zonefiles",
"that",
"we",
"don",
"t",
"have",
"re",
"-",
"attempt",
"to",
"fetch",
"them",
"from",
"storage",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L885-L899 |
244,240 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_cache_zonefile_info | def atlasdb_cache_zonefile_info( con=None, path=None ):
"""
Load up and cache our zonefile inventory from the database
"""
global ZONEFILE_INV, NUM_ZONEFILES, ZONEFILE_INV_LOCK
inv = None
with ZONEFILE_INV_LOCK:
inv_len = atlasdb_zonefile_inv_length( con=con, path=path )
inv... | python | def atlasdb_cache_zonefile_info( con=None, path=None ):
global ZONEFILE_INV, NUM_ZONEFILES, ZONEFILE_INV_LOCK
inv = None
with ZONEFILE_INV_LOCK:
inv_len = atlasdb_zonefile_inv_length( con=con, path=path )
inv = atlas_make_zonefile_inventory( 0, inv_len, con=con, path=path )
ZON... | [
"def",
"atlasdb_cache_zonefile_info",
"(",
"con",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"global",
"ZONEFILE_INV",
",",
"NUM_ZONEFILES",
",",
"ZONEFILE_INV_LOCK",
"inv",
"=",
"None",
"with",
"ZONEFILE_INV_LOCK",
":",
"inv_len",
"=",
"atlasdb_zonefile_inv... | Load up and cache our zonefile inventory from the database | [
"Load",
"up",
"and",
"cache",
"our",
"zonefile",
"inventory",
"from",
"the",
"database"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L902-L916 |
244,241 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_queue_zonefiles | def atlasdb_queue_zonefiles( con, db, start_block, zonefile_dir, recover=False, validate=True, end_block=None ):
"""
Queue all zonefile hashes in the BlockstackDB
to the zonefile queue
NOT THREAD SAFE
Returns the list of zonefile infos queued, and whether or not they are present.
"""
# pop... | python | def atlasdb_queue_zonefiles( con, db, start_block, zonefile_dir, recover=False, validate=True, end_block=None ):
# populate zonefile queue
total = 0
if end_block is None:
end_block = db.lastblock+1
ret = [] # map zonefile hash to zfinfo
for block_height in range(start_block, end_block, ... | [
"def",
"atlasdb_queue_zonefiles",
"(",
"con",
",",
"db",
",",
"start_block",
",",
"zonefile_dir",
",",
"recover",
"=",
"False",
",",
"validate",
"=",
"True",
",",
"end_block",
"=",
"None",
")",
":",
"# populate zonefile queue",
"total",
"=",
"0",
"if",
"end_... | Queue all zonefile hashes in the BlockstackDB
to the zonefile queue
NOT THREAD SAFE
Returns the list of zonefile infos queued, and whether or not they are present. | [
"Queue",
"all",
"zonefile",
"hashes",
"in",
"the",
"BlockstackDB",
"to",
"the",
"zonefile",
"queue"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L940-L989 |
244,242 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_sync_zonefiles | def atlasdb_sync_zonefiles( db, start_block, zonefile_dir, atlas_state, validate=True, end_block=None, path=None, con=None ):
"""
Synchronize atlas DB with name db
NOT THREAD SAFE
"""
ret = None
with AtlasDBOpen(con=con, path=path) as dbcon:
ret = atlasdb_queue_zonefiles( dbcon, db, sta... | python | def atlasdb_sync_zonefiles( db, start_block, zonefile_dir, atlas_state, validate=True, end_block=None, path=None, con=None ):
ret = None
with AtlasDBOpen(con=con, path=path) as dbcon:
ret = atlasdb_queue_zonefiles( dbcon, db, start_block, zonefile_dir, validate=validate, end_block=end_block )
at... | [
"def",
"atlasdb_sync_zonefiles",
"(",
"db",
",",
"start_block",
",",
"zonefile_dir",
",",
"atlas_state",
",",
"validate",
"=",
"True",
",",
"end_block",
"=",
"None",
",",
"path",
"=",
"None",
",",
"con",
"=",
"None",
")",
":",
"ret",
"=",
"None",
"with",... | Synchronize atlas DB with name db
NOT THREAD SAFE | [
"Synchronize",
"atlas",
"DB",
"with",
"name",
"db"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L992-L1012 |
244,243 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_add_peer | def atlasdb_add_peer( peer_hostport, discovery_time=None, peer_table=None, con=None, path=None, ping_on_evict=True ):
"""
Add a peer to the peer table.
If the peer conflicts with another peer, ping it first, and only insert
the new peer if the old peer is dead.
Keep the in-RAM peer table cache-cohe... | python | def atlasdb_add_peer( peer_hostport, discovery_time=None, peer_table=None, con=None, path=None, ping_on_evict=True ):
# bound the number of peers we add to PEER_MAX_DB
assert len(peer_hostport) > 0
sk = random.randint(0, 2**32)
peer_host, peer_port = url_to_host_port( peer_hostport )
assert len(pe... | [
"def",
"atlasdb_add_peer",
"(",
"peer_hostport",
",",
"discovery_time",
"=",
"None",
",",
"peer_table",
"=",
"None",
",",
"con",
"=",
"None",
",",
"path",
"=",
"None",
",",
"ping_on_evict",
"=",
"True",
")",
":",
"# bound the number of peers we add to PEER_MAX_DB"... | Add a peer to the peer table.
If the peer conflicts with another peer, ping it first, and only insert
the new peer if the old peer is dead.
Keep the in-RAM peer table cache-coherent as well.
Return True if this peer was added to the table (or preserved)
Return False if not | [
"Add",
"a",
"peer",
"to",
"the",
"peer",
"table",
".",
"If",
"the",
"peer",
"conflicts",
"with",
"another",
"peer",
"ping",
"it",
"first",
"and",
"only",
"insert",
"the",
"new",
"peer",
"if",
"the",
"old",
"peer",
"is",
"dead",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1015-L1095 |
244,244 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_num_peers | def atlasdb_num_peers( con=None, path=None ):
"""
How many peers are there in the db?
"""
with AtlasDBOpen(con=con, path=path) as dbcon:
sql = "SELECT MAX(peer_index) FROM peers;"
args = ()
cur = dbcon.cursor()
res = atlasdb_query_execute( cur, sql, args )
ret ... | python | def atlasdb_num_peers( con=None, path=None ):
with AtlasDBOpen(con=con, path=path) as dbcon:
sql = "SELECT MAX(peer_index) FROM peers;"
args = ()
cur = dbcon.cursor()
res = atlasdb_query_execute( cur, sql, args )
ret = []
for row in res:
tmp = {}
... | [
"def",
"atlasdb_num_peers",
"(",
"con",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"with",
"AtlasDBOpen",
"(",
"con",
"=",
"con",
",",
"path",
"=",
"path",
")",
"as",
"dbcon",
":",
"sql",
"=",
"\"SELECT MAX(peer_index) FROM peers;\"",
"args",
"=",
... | How many peers are there in the db? | [
"How",
"many",
"peers",
"are",
"there",
"in",
"the",
"db?"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1124-L1144 |
244,245 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_get_peer | def atlas_get_peer( peer_hostport, peer_table=None ):
"""
Get the given peer's info
"""
ret = None
with AtlasPeerTableLocked(peer_table) as ptbl:
ret = ptbl.get(peer_hostport, None)
return ret | python | def atlas_get_peer( peer_hostport, peer_table=None ):
ret = None
with AtlasPeerTableLocked(peer_table) as ptbl:
ret = ptbl.get(peer_hostport, None)
return ret | [
"def",
"atlas_get_peer",
"(",
"peer_hostport",
",",
"peer_table",
"=",
"None",
")",
":",
"ret",
"=",
"None",
"with",
"AtlasPeerTableLocked",
"(",
"peer_table",
")",
"as",
"ptbl",
":",
"ret",
"=",
"ptbl",
".",
"get",
"(",
"peer_hostport",
",",
"None",
")",
... | Get the given peer's info | [
"Get",
"the",
"given",
"peer",
"s",
"info"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1147-L1156 |
244,246 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_get_random_peer | def atlasdb_get_random_peer( con=None, path=None ):
"""
Select a peer from the db at random
Return None if the table is empty
"""
ret = {}
with AtlasDBOpen(con=con, path=path) as dbcon:
num_peers = atlasdb_num_peers( con=con, path=path )
if num_peers is None or num_peers == 0:
... | python | def atlasdb_get_random_peer( con=None, path=None ):
ret = {}
with AtlasDBOpen(con=con, path=path) as dbcon:
num_peers = atlasdb_num_peers( con=con, path=path )
if num_peers is None or num_peers == 0:
# no peers
ret['peer_hostport'] = None
else:
r = ... | [
"def",
"atlasdb_get_random_peer",
"(",
"con",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"ret",
"=",
"{",
"}",
"with",
"AtlasDBOpen",
"(",
"con",
"=",
"con",
",",
"path",
"=",
"path",
")",
"as",
"dbcon",
":",
"num_peers",
"=",
"atlasdb_num_peers"... | Select a peer from the db at random
Return None if the table is empty | [
"Select",
"a",
"peer",
"from",
"the",
"db",
"at",
"random",
"Return",
"None",
"if",
"the",
"table",
"is",
"empty"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1159-L1188 |
244,247 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_get_old_peers | def atlasdb_get_old_peers( now, con=None, path=None ):
"""
Get peers older than now - PEER_LIFETIME
"""
with AtlasDBOpen(con=con, path=path) as dbcon:
if now is None:
now = time.time()
expire = now - atlas_peer_max_age()
sql = "SELECT * FROM peers WHERE discovery_ti... | python | def atlasdb_get_old_peers( now, con=None, path=None ):
with AtlasDBOpen(con=con, path=path) as dbcon:
if now is None:
now = time.time()
expire = now - atlas_peer_max_age()
sql = "SELECT * FROM peers WHERE discovery_time < ?";
args = (expire,)
cur = dbcon.cursor... | [
"def",
"atlasdb_get_old_peers",
"(",
"now",
",",
"con",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"with",
"AtlasDBOpen",
"(",
"con",
"=",
"con",
",",
"path",
"=",
"path",
")",
"as",
"dbcon",
":",
"if",
"now",
"is",
"None",
":",
"now",
"=",
... | Get peers older than now - PEER_LIFETIME | [
"Get",
"peers",
"older",
"than",
"now",
"-",
"PEER_LIFETIME"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1191-L1213 |
244,248 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_renew_peer | def atlasdb_renew_peer( peer_hostport, now, con=None, path=None ):
"""
Renew a peer's discovery time
"""
with AtlasDBOpen(con=con, path=path) as dbcon:
if now is None:
now = time.time()
sql = "UPDATE peers SET discovery_time = ? WHERE peer_hostport = ?;"
args = (now,... | python | def atlasdb_renew_peer( peer_hostport, now, con=None, path=None ):
with AtlasDBOpen(con=con, path=path) as dbcon:
if now is None:
now = time.time()
sql = "UPDATE peers SET discovery_time = ? WHERE peer_hostport = ?;"
args = (now, peer_hostport)
cur = dbcon.cursor()
... | [
"def",
"atlasdb_renew_peer",
"(",
"peer_hostport",
",",
"now",
",",
"con",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"with",
"AtlasDBOpen",
"(",
"con",
"=",
"con",
",",
"path",
"=",
"path",
")",
"as",
"dbcon",
":",
"if",
"now",
"is",
"None",
... | Renew a peer's discovery time | [
"Renew",
"a",
"peer",
"s",
"discovery",
"time"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1216-L1231 |
244,249 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_load_peer_table | def atlasdb_load_peer_table( con=None, path=None ):
"""
Create a peer table from the peer DB
"""
peer_table = {}
with AtlasDBOpen(con=con, path=path) as dbcon:
sql = "SELECT * FROM peers;"
args = ()
cur = dbcon.cursor()
res = atlasdb_query_execute( cur, sql, ar... | python | def atlasdb_load_peer_table( con=None, path=None ):
peer_table = {}
with AtlasDBOpen(con=con, path=path) as dbcon:
sql = "SELECT * FROM peers;"
args = ()
cur = dbcon.cursor()
res = atlasdb_query_execute( cur, sql, args )
# build it up
count = 0
fo... | [
"def",
"atlasdb_load_peer_table",
"(",
"con",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"peer_table",
"=",
"{",
"}",
"with",
"AtlasDBOpen",
"(",
"con",
"=",
"con",
",",
"path",
"=",
"path",
")",
"as",
"dbcon",
":",
"sql",
"=",
"\"SELECT * FROM p... | Create a peer table from the peer DB | [
"Create",
"a",
"peer",
"table",
"from",
"the",
"peer",
"DB"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1234-L1257 |
244,250 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlasdb_zonefile_inv_list | def atlasdb_zonefile_inv_list( bit_offset, bit_length, con=None, path=None ):
"""
Get an inventory listing.
offset and length are in bits.
Return the list of zonefile information.
The list may be less than length elements.
"""
with AtlasDBOpen(con=con, path=path) as dbcon:
sql = "S... | python | def atlasdb_zonefile_inv_list( bit_offset, bit_length, con=None, path=None ):
with AtlasDBOpen(con=con, path=path) as dbcon:
sql = "SELECT * FROM zonefiles LIMIT ? OFFSET ?;"
args = (bit_length, bit_offset)
cur = dbcon.cursor()
res = atlasdb_query_execute( cur, sql, args )
... | [
"def",
"atlasdb_zonefile_inv_list",
"(",
"bit_offset",
",",
"bit_length",
",",
"con",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"with",
"AtlasDBOpen",
"(",
"con",
"=",
"con",
",",
"path",
"=",
"path",
")",
"as",
"dbcon",
":",
"sql",
"=",
"\"SELE... | Get an inventory listing.
offset and length are in bits.
Return the list of zonefile information.
The list may be less than length elements. | [
"Get",
"an",
"inventory",
"listing",
".",
"offset",
"and",
"length",
"are",
"in",
"bits",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1364-L1386 |
244,251 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_init_peer_info | def atlas_init_peer_info( peer_table, peer_hostport, blacklisted=False, whitelisted=False ):
"""
Initialize peer info table entry
"""
peer_table[peer_hostport] = {
"time": [],
"zonefile_inv": "",
"blacklisted": blacklisted,
"whitelisted": whitelisted
} | python | def atlas_init_peer_info( peer_table, peer_hostport, blacklisted=False, whitelisted=False ):
peer_table[peer_hostport] = {
"time": [],
"zonefile_inv": "",
"blacklisted": blacklisted,
"whitelisted": whitelisted
} | [
"def",
"atlas_init_peer_info",
"(",
"peer_table",
",",
"peer_hostport",
",",
"blacklisted",
"=",
"False",
",",
"whitelisted",
"=",
"False",
")",
":",
"peer_table",
"[",
"peer_hostport",
"]",
"=",
"{",
"\"time\"",
":",
"[",
"]",
",",
"\"zonefile_inv\"",
":",
... | Initialize peer info table entry | [
"Initialize",
"peer",
"info",
"table",
"entry"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1546-L1555 |
244,252 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_log_socket_error | def atlas_log_socket_error( method_invocation, peer_hostport, se ):
"""
Log a socket exception tastefully
"""
if isinstance( se, socket.timeout ):
log.debug("%s %s: timed out (socket.timeout)" % (method_invocation, peer_hostport))
elif isinstance( se, socket.gaierror ):
log.debug("%... | python | def atlas_log_socket_error( method_invocation, peer_hostport, se ):
if isinstance( se, socket.timeout ):
log.debug("%s %s: timed out (socket.timeout)" % (method_invocation, peer_hostport))
elif isinstance( se, socket.gaierror ):
log.debug("%s %s: failed to query address or info (socket.gaierror... | [
"def",
"atlas_log_socket_error",
"(",
"method_invocation",
",",
"peer_hostport",
",",
"se",
")",
":",
"if",
"isinstance",
"(",
"se",
",",
"socket",
".",
"timeout",
")",
":",
"log",
".",
"debug",
"(",
"\"%s %s: timed out (socket.timeout)\"",
"%",
"(",
"method_inv... | Log a socket exception tastefully | [
"Log",
"a",
"socket",
"exception",
"tastefully"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1558-L1582 |
244,253 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_peer_ping | def atlas_peer_ping( peer_hostport, timeout=None, peer_table=None ):
"""
Ping a host
Return True if alive
Return False if not
"""
if timeout is None:
timeout = atlas_ping_timeout()
assert not atlas_peer_table_is_locked_by_me()
host, port = url_to_host_port( peer_hostport )... | python | def atlas_peer_ping( peer_hostport, timeout=None, peer_table=None ):
if timeout is None:
timeout = atlas_ping_timeout()
assert not atlas_peer_table_is_locked_by_me()
host, port = url_to_host_port( peer_hostport )
RPC = get_rpc_client_class()
rpc = RPC( host, port, timeout=timeout )
lo... | [
"def",
"atlas_peer_ping",
"(",
"peer_hostport",
",",
"timeout",
"=",
"None",
",",
"peer_table",
"=",
"None",
")",
":",
"if",
"timeout",
"is",
"None",
":",
"timeout",
"=",
"atlas_ping_timeout",
"(",
")",
"assert",
"not",
"atlas_peer_table_is_locked_by_me",
"(",
... | Ping a host
Return True if alive
Return False if not | [
"Ping",
"a",
"host",
"Return",
"True",
"if",
"alive",
"Return",
"False",
"if",
"not"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1585-L1621 |
244,254 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_inventory_count_missing | def atlas_inventory_count_missing( inv1, inv2 ):
"""
Find out how many bits are set in inv2
that are not set in inv1.
"""
count = 0
common = min(len(inv1), len(inv2))
for i in xrange(0, common):
for j in xrange(0, 8):
if ((1 << (7 - j)) & ord(inv2[i])) != 0 and ((1 << (7... | python | def atlas_inventory_count_missing( inv1, inv2 ):
count = 0
common = min(len(inv1), len(inv2))
for i in xrange(0, common):
for j in xrange(0, 8):
if ((1 << (7 - j)) & ord(inv2[i])) != 0 and ((1 << (7 - j)) & ord(inv1[i])) == 0:
count += 1
if len(inv1) < len(inv2):
... | [
"def",
"atlas_inventory_count_missing",
"(",
"inv1",
",",
"inv2",
")",
":",
"count",
"=",
"0",
"common",
"=",
"min",
"(",
"len",
"(",
"inv1",
")",
",",
"len",
"(",
"inv2",
")",
")",
"for",
"i",
"in",
"xrange",
"(",
"0",
",",
"common",
")",
":",
"... | Find out how many bits are set in inv2
that are not set in inv1. | [
"Find",
"out",
"how",
"many",
"bits",
"are",
"set",
"in",
"inv2",
"that",
"are",
"not",
"set",
"in",
"inv1",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1707-L1725 |
244,255 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_revalidate_peers | def atlas_revalidate_peers( con=None, path=None, now=None, peer_table=None ):
"""
Revalidate peers that are older than the maximum peer age.
Ping them, and if they don't respond, remove them.
"""
global MIN_PEER_HEALTH
if now is None:
now = time_now()
old_peer_infos = atlasdb_get_o... | python | def atlas_revalidate_peers( con=None, path=None, now=None, peer_table=None ):
global MIN_PEER_HEALTH
if now is None:
now = time_now()
old_peer_infos = atlasdb_get_old_peers( now, con=con, path=path )
for old_peer_info in old_peer_infos:
res = atlas_peer_getinfo( old_peer_info['peer_hos... | [
"def",
"atlas_revalidate_peers",
"(",
"con",
"=",
"None",
",",
"path",
"=",
"None",
",",
"now",
"=",
"None",
",",
"peer_table",
"=",
"None",
")",
":",
"global",
"MIN_PEER_HEALTH",
"if",
"now",
"is",
"None",
":",
"now",
"=",
"time_now",
"(",
")",
"old_p... | Revalidate peers that are older than the maximum peer age.
Ping them, and if they don't respond, remove them. | [
"Revalidate",
"peers",
"that",
"are",
"older",
"than",
"the",
"maximum",
"peer",
"age",
".",
"Ping",
"them",
"and",
"if",
"they",
"don",
"t",
"respond",
"remove",
"them",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1775-L1803 |
244,256 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_peer_get_request_count | def atlas_peer_get_request_count( peer_hostport, peer_table=None ):
"""
How many times have we contacted this peer?
"""
with AtlasPeerTableLocked(peer_table) as ptbl:
if peer_hostport not in ptbl.keys():
return 0
count = 0
for (t, r) in ptbl[peer_hostport]['time']:
... | python | def atlas_peer_get_request_count( peer_hostport, peer_table=None ):
with AtlasPeerTableLocked(peer_table) as ptbl:
if peer_hostport not in ptbl.keys():
return 0
count = 0
for (t, r) in ptbl[peer_hostport]['time']:
if r:
count += 1
return count | [
"def",
"atlas_peer_get_request_count",
"(",
"peer_hostport",
",",
"peer_table",
"=",
"None",
")",
":",
"with",
"AtlasPeerTableLocked",
"(",
"peer_table",
")",
"as",
"ptbl",
":",
"if",
"peer_hostport",
"not",
"in",
"ptbl",
".",
"keys",
"(",
")",
":",
"return",
... | How many times have we contacted this peer? | [
"How",
"many",
"times",
"have",
"we",
"contacted",
"this",
"peer?"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1828-L1841 |
244,257 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_peer_get_zonefile_inventory | def atlas_peer_get_zonefile_inventory( peer_hostport, peer_table=None ):
"""
What's the zonefile inventory vector for this peer?
Return None if not defined
"""
inv = None
with AtlasPeerTableLocked(peer_table) as ptbl:
if peer_hostport not in ptbl.keys():
return None
... | python | def atlas_peer_get_zonefile_inventory( peer_hostport, peer_table=None ):
inv = None
with AtlasPeerTableLocked(peer_table) as ptbl:
if peer_hostport not in ptbl.keys():
return None
inv = ptbl[peer_hostport]['zonefile_inv']
return inv | [
"def",
"atlas_peer_get_zonefile_inventory",
"(",
"peer_hostport",
",",
"peer_table",
"=",
"None",
")",
":",
"inv",
"=",
"None",
"with",
"AtlasPeerTableLocked",
"(",
"peer_table",
")",
"as",
"ptbl",
":",
"if",
"peer_hostport",
"not",
"in",
"ptbl",
".",
"keys",
... | What's the zonefile inventory vector for this peer?
Return None if not defined | [
"What",
"s",
"the",
"zonefile",
"inventory",
"vector",
"for",
"this",
"peer?",
"Return",
"None",
"if",
"not",
"defined"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1844-L1857 |
244,258 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_peer_set_zonefile_inventory | def atlas_peer_set_zonefile_inventory( peer_hostport, peer_inv, peer_table=None ):
"""
Set this peer's zonefile inventory
"""
with AtlasPeerTableLocked(peer_table) as ptbl:
if peer_hostport not in ptbl.keys():
return None
ptbl[peer_hostport]['zonefile_inv'] = peer_inv
... | python | def atlas_peer_set_zonefile_inventory( peer_hostport, peer_inv, peer_table=None ):
with AtlasPeerTableLocked(peer_table) as ptbl:
if peer_hostport not in ptbl.keys():
return None
ptbl[peer_hostport]['zonefile_inv'] = peer_inv
return peer_inv | [
"def",
"atlas_peer_set_zonefile_inventory",
"(",
"peer_hostport",
",",
"peer_inv",
",",
"peer_table",
"=",
"None",
")",
":",
"with",
"AtlasPeerTableLocked",
"(",
"peer_table",
")",
"as",
"ptbl",
":",
"if",
"peer_hostport",
"not",
"in",
"ptbl",
".",
"keys",
"(",
... | Set this peer's zonefile inventory | [
"Set",
"this",
"peer",
"s",
"zonefile",
"inventory"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1860-L1870 |
244,259 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_peer_is_whitelisted | def atlas_peer_is_whitelisted( peer_hostport, peer_table=None ):
"""
Is a peer whitelisted
"""
ret = None
with AtlasPeerTableLocked(peer_table) as ptbl:
if peer_hostport not in ptbl.keys():
return None
ret = ptbl[peer_hostport].get("whitelisted", False)
return ret | python | def atlas_peer_is_whitelisted( peer_hostport, peer_table=None ):
ret = None
with AtlasPeerTableLocked(peer_table) as ptbl:
if peer_hostport not in ptbl.keys():
return None
ret = ptbl[peer_hostport].get("whitelisted", False)
return ret | [
"def",
"atlas_peer_is_whitelisted",
"(",
"peer_hostport",
",",
"peer_table",
"=",
"None",
")",
":",
"ret",
"=",
"None",
"with",
"AtlasPeerTableLocked",
"(",
"peer_table",
")",
"as",
"ptbl",
":",
"if",
"peer_hostport",
"not",
"in",
"ptbl",
".",
"keys",
"(",
"... | Is a peer whitelisted | [
"Is",
"a",
"peer",
"whitelisted"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1888-L1899 |
244,260 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_peer_update_health | def atlas_peer_update_health( peer_hostport, received_response, peer_table=None ):
"""
Mark the given peer as alive at this time.
Update times at which we contacted it,
and update its health score.
Use the global health table by default,
or use the given health info if set.
"""
with A... | python | def atlas_peer_update_health( peer_hostport, received_response, peer_table=None ):
with AtlasPeerTableLocked(peer_table) as ptbl:
if peer_hostport not in ptbl.keys():
return False
# record that we contacted this peer, and whether or not we useful info from it
now = time_now()
... | [
"def",
"atlas_peer_update_health",
"(",
"peer_hostport",
",",
"received_response",
",",
"peer_table",
"=",
"None",
")",
":",
"with",
"AtlasPeerTableLocked",
"(",
"peer_table",
")",
"as",
"ptbl",
":",
"if",
"peer_hostport",
"not",
"in",
"ptbl",
".",
"keys",
"(",
... | Mark the given peer as alive at this time.
Update times at which we contacted it,
and update its health score.
Use the global health table by default,
or use the given health info if set. | [
"Mark",
"the",
"given",
"peer",
"as",
"alive",
"at",
"this",
"time",
".",
"Update",
"times",
"at",
"which",
"we",
"contacted",
"it",
"and",
"update",
"its",
"health",
"score",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1902-L1930 |
244,261 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_peer_download_zonefile_inventory | def atlas_peer_download_zonefile_inventory( my_hostport, peer_hostport, maxlen, bit_offset=0, timeout=None, peer_table={} ):
"""
Get the zonefile inventory from the remote peer
Start from the given bit_offset
NOTE: this doesn't update the peer table health by default;
you'll have to explicitly pass... | python | def atlas_peer_download_zonefile_inventory( my_hostport, peer_hostport, maxlen, bit_offset=0, timeout=None, peer_table={} ):
if timeout is None:
timeout = atlas_inv_timeout()
interval = 524288 # number of bits in 64KB
peer_inv = ""
log.debug("Download zonefile inventory %s-%s from %s" % ... | [
"def",
"atlas_peer_download_zonefile_inventory",
"(",
"my_hostport",
",",
"peer_hostport",
",",
"maxlen",
",",
"bit_offset",
"=",
"0",
",",
"timeout",
"=",
"None",
",",
"peer_table",
"=",
"{",
"}",
")",
":",
"if",
"timeout",
"is",
"None",
":",
"timeout",
"="... | Get the zonefile inventory from the remote peer
Start from the given bit_offset
NOTE: this doesn't update the peer table health by default;
you'll have to explicitly pass in a peer table (i.e. setting
to {} ensures that nothing happens). | [
"Get",
"the",
"zonefile",
"inventory",
"from",
"the",
"remote",
"peer",
"Start",
"from",
"the",
"given",
"bit_offset"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L1993-L2027 |
244,262 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_peer_sync_zonefile_inventory | def atlas_peer_sync_zonefile_inventory( my_hostport, peer_hostport, maxlen, timeout=None, peer_table=None ):
"""
Synchronize our knowledge of a peer's zonefiles up to a given byte length
NOT THREAD SAFE; CALL FROM ONLY ONE THREAD.
maxlen is the maximum length in bits of the expected zonefile.
Retu... | python | def atlas_peer_sync_zonefile_inventory( my_hostport, peer_hostport, maxlen, timeout=None, peer_table=None ):
if timeout is None:
timeout = atlas_inv_timeout()
peer_inv = ""
bit_offset = None
with AtlasPeerTableLocked(peer_table) as ptbl:
if peer_hostport not in ptbl.keys():
... | [
"def",
"atlas_peer_sync_zonefile_inventory",
"(",
"my_hostport",
",",
"peer_hostport",
",",
"maxlen",
",",
"timeout",
"=",
"None",
",",
"peer_table",
"=",
"None",
")",
":",
"if",
"timeout",
"is",
"None",
":",
"timeout",
"=",
"atlas_inv_timeout",
"(",
")",
"pee... | Synchronize our knowledge of a peer's zonefiles up to a given byte length
NOT THREAD SAFE; CALL FROM ONLY ONE THREAD.
maxlen is the maximum length in bits of the expected zonefile.
Return the new inv vector if we synced it (updating the peer table in the process)
Return None if not | [
"Synchronize",
"our",
"knowledge",
"of",
"a",
"peer",
"s",
"zonefiles",
"up",
"to",
"a",
"given",
"byte",
"length",
"NOT",
"THREAD",
"SAFE",
";",
"CALL",
"FROM",
"ONLY",
"ONE",
"THREAD",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L2031-L2074 |
244,263 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_peer_refresh_zonefile_inventory | def atlas_peer_refresh_zonefile_inventory( my_hostport, peer_hostport, byte_offset, timeout=None, peer_table=None, con=None, path=None, local_inv=None ):
"""
Refresh a peer's zonefile recent inventory vector entries,
by removing every bit after byte_offset and re-synchronizing them.
The intuition here ... | python | def atlas_peer_refresh_zonefile_inventory( my_hostport, peer_hostport, byte_offset, timeout=None, peer_table=None, con=None, path=None, local_inv=None ):
if timeout is None:
timeout = atlas_inv_timeout()
if local_inv is None:
# get local zonefile inv
inv_len = atlasdb_zonefile_inv_leng... | [
"def",
"atlas_peer_refresh_zonefile_inventory",
"(",
"my_hostport",
",",
"peer_hostport",
",",
"byte_offset",
",",
"timeout",
"=",
"None",
",",
"peer_table",
"=",
"None",
",",
"con",
"=",
"None",
",",
"path",
"=",
"None",
",",
"local_inv",
"=",
"None",
")",
... | Refresh a peer's zonefile recent inventory vector entries,
by removing every bit after byte_offset and re-synchronizing them.
The intuition here is that recent zonefiles are much rarer than older
zonefiles (which will have been near-100% replicated), meaning the tail
of the peer's zonefile inventory is... | [
"Refresh",
"a",
"peer",
"s",
"zonefile",
"recent",
"inventory",
"vector",
"entries",
"by",
"removing",
"every",
"bit",
"after",
"byte_offset",
"and",
"re",
"-",
"synchronizing",
"them",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L2077-L2131 |
244,264 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_peer_has_fresh_zonefile_inventory | def atlas_peer_has_fresh_zonefile_inventory( peer_hostport, peer_table=None ):
"""
Does the given atlas node have a fresh zonefile inventory?
"""
fresh = False
with AtlasPeerTableLocked(peer_table) as ptbl:
if peer_hostport not in ptbl.keys():
return False
now = time_no... | python | def atlas_peer_has_fresh_zonefile_inventory( peer_hostport, peer_table=None ):
fresh = False
with AtlasPeerTableLocked(peer_table) as ptbl:
if peer_hostport not in ptbl.keys():
return False
now = time_now()
peer_inv = atlas_peer_get_zonefile_inventory( peer_hostport, peer_ta... | [
"def",
"atlas_peer_has_fresh_zonefile_inventory",
"(",
"peer_hostport",
",",
"peer_table",
"=",
"None",
")",
":",
"fresh",
"=",
"False",
"with",
"AtlasPeerTableLocked",
"(",
"peer_table",
")",
"as",
"ptbl",
":",
"if",
"peer_hostport",
"not",
"in",
"ptbl",
".",
"... | Does the given atlas node have a fresh zonefile inventory? | [
"Does",
"the",
"given",
"atlas",
"node",
"have",
"a",
"fresh",
"zonefile",
"inventory?"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L2134-L2153 |
244,265 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_find_missing_zonefile_availability | def atlas_find_missing_zonefile_availability( peer_table=None, con=None, path=None, missing_zonefile_info=None ):
"""
Find the set of missing zonefiles, as well as their popularity amongst
our neighbors.
Only consider zonefiles that are known by at least
one peer; otherwise they're missing from
... | python | def atlas_find_missing_zonefile_availability( peer_table=None, con=None, path=None, missing_zonefile_info=None ):
# which zonefiles do we have?
bit_offset = 0
bit_count = 10000
missing = []
ret = {}
if missing_zonefile_info is None:
while True:
zfinfo = atlasdb_zonefile_find... | [
"def",
"atlas_find_missing_zonefile_availability",
"(",
"peer_table",
"=",
"None",
",",
"con",
"=",
"None",
",",
"path",
"=",
"None",
",",
"missing_zonefile_info",
"=",
"None",
")",
":",
"# which zonefiles do we have?",
"bit_offset",
"=",
"0",
"bit_count",
"=",
"1... | Find the set of missing zonefiles, as well as their popularity amongst
our neighbors.
Only consider zonefiles that are known by at least
one peer; otherwise they're missing from
our clique (and we'll re-sync our neighborss' inventories
every so often to make sure we detect when zonefiles
becom... | [
"Find",
"the",
"set",
"of",
"missing",
"zonefiles",
"as",
"well",
"as",
"their",
"popularity",
"amongst",
"our",
"neighbors",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L2177-L2266 |
244,266 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_peer_has_zonefile | def atlas_peer_has_zonefile( peer_hostport, zonefile_hash, zonefile_bits=None, con=None, path=None, peer_table=None ):
"""
Does the given peer have the given zonefile defined?
Check its inventory vector
Return True if present
Return False if not present
Return None if we don't know about the zo... | python | def atlas_peer_has_zonefile( peer_hostport, zonefile_hash, zonefile_bits=None, con=None, path=None, peer_table=None ):
bits = None
if zonefile_bits is None:
bits = atlasdb_get_zonefile_bits( zonefile_hash, con=con, path=path )
if len(bits) == 0:
return None
else:
bits = ... | [
"def",
"atlas_peer_has_zonefile",
"(",
"peer_hostport",
",",
"zonefile_hash",
",",
"zonefile_bits",
"=",
"None",
",",
"con",
"=",
"None",
",",
"path",
"=",
"None",
",",
"peer_table",
"=",
"None",
")",
":",
"bits",
"=",
"None",
"if",
"zonefile_bits",
"is",
... | Does the given peer have the given zonefile defined?
Check its inventory vector
Return True if present
Return False if not present
Return None if we don't know about the zonefile ourselves, or if we don't know about the peer | [
"Does",
"the",
"given",
"peer",
"have",
"the",
"given",
"zonefile",
"defined?",
"Check",
"its",
"inventory",
"vector"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L2269-L2297 |
244,267 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_peer_get_neighbors | def atlas_peer_get_neighbors( my_hostport, peer_hostport, timeout=None, peer_table=None, con=None, path=None ):
"""
Ask the peer server at the given URL for its neighbors.
Update the health info in peer_table
(if not given, the global peer table will be used instead)
Return the list on success
... | python | def atlas_peer_get_neighbors( my_hostport, peer_hostport, timeout=None, peer_table=None, con=None, path=None ):
if timeout is None:
timeout = atlas_neighbors_timeout()
peer_list = None
host, port = url_to_host_port( peer_hostport )
RPC = get_rpc_client_class()
rpc = RPC( host, port, timeou... | [
"def",
"atlas_peer_get_neighbors",
"(",
"my_hostport",
",",
"peer_hostport",
",",
"timeout",
"=",
"None",
",",
"peer_table",
"=",
"None",
",",
"con",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"if",
"timeout",
"is",
"None",
":",
"timeout",
"=",
"at... | Ask the peer server at the given URL for its neighbors.
Update the health info in peer_table
(if not given, the global peer table will be used instead)
Return the list on success
Return None on failure to contact
Raise on invalid URL | [
"Ask",
"the",
"peer",
"server",
"at",
"the",
"given",
"URL",
"for",
"its",
"neighbors",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L2300-L2354 |
244,268 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_get_zonefiles | def atlas_get_zonefiles( my_hostport, peer_hostport, zonefile_hashes, timeout=None, peer_table=None ):
"""
Given a list of zonefile hashes.
go and get them from the given host.
Update node health
Return the newly-fetched zonefiles on success (as a dict mapping hashes to zonefile data)
Return N... | python | def atlas_get_zonefiles( my_hostport, peer_hostport, zonefile_hashes, timeout=None, peer_table=None ):
if timeout is None:
timeout = atlas_zonefiles_timeout()
zf_payload = None
zonefile_datas = {}
host, port = url_to_host_port( peer_hostport )
RPC = get_rpc_client_class()
rpc = RPC( ho... | [
"def",
"atlas_get_zonefiles",
"(",
"my_hostport",
",",
"peer_hostport",
",",
"zonefile_hashes",
",",
"timeout",
"=",
"None",
",",
"peer_table",
"=",
"None",
")",
":",
"if",
"timeout",
"is",
"None",
":",
"timeout",
"=",
"atlas_zonefiles_timeout",
"(",
")",
"zf_... | Given a list of zonefile hashes.
go and get them from the given host.
Update node health
Return the newly-fetched zonefiles on success (as a dict mapping hashes to zonefile data)
Return None on error. | [
"Given",
"a",
"list",
"of",
"zonefile",
"hashes",
".",
"go",
"and",
"get",
"them",
"from",
"the",
"given",
"host",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L2357-L2417 |
244,269 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_rank_peers_by_data_availability | def atlas_rank_peers_by_data_availability( peer_list=None, peer_table=None, local_inv=None, con=None, path=None ):
"""
Get a ranking of peers to contact for a zonefile.
Peers are ranked by the number of zonefiles they have
which we don't have.
This is used to select neighbors.
"""
with Atl... | python | def atlas_rank_peers_by_data_availability( peer_list=None, peer_table=None, local_inv=None, con=None, path=None ):
with AtlasPeerTableLocked(peer_table) as ptbl:
if peer_list is None:
peer_list = ptbl.keys()[:]
if local_inv is None:
# what's my inventory?
inv_len... | [
"def",
"atlas_rank_peers_by_data_availability",
"(",
"peer_list",
"=",
"None",
",",
"peer_table",
"=",
"None",
",",
"local_inv",
"=",
"None",
",",
"con",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"with",
"AtlasPeerTableLocked",
"(",
"peer_table",
")",
... | Get a ranking of peers to contact for a zonefile.
Peers are ranked by the number of zonefiles they have
which we don't have.
This is used to select neighbors. | [
"Get",
"a",
"ranking",
"of",
"peers",
"to",
"contact",
"for",
"a",
"zonefile",
".",
"Peers",
"are",
"ranked",
"by",
"the",
"number",
"of",
"zonefiles",
"they",
"have",
"which",
"we",
"don",
"t",
"have",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L2453-L2488 |
244,270 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_peer_dequeue_all | def atlas_peer_dequeue_all( peer_queue=None ):
"""
Get all queued peers
"""
peers = []
with AtlasPeerQueueLocked(peer_queue) as pq:
while len(pq) > 0:
peers.append( pq.pop(0) )
return peers | python | def atlas_peer_dequeue_all( peer_queue=None ):
peers = []
with AtlasPeerQueueLocked(peer_queue) as pq:
while len(pq) > 0:
peers.append( pq.pop(0) )
return peers | [
"def",
"atlas_peer_dequeue_all",
"(",
"peer_queue",
"=",
"None",
")",
":",
"peers",
"=",
"[",
"]",
"with",
"AtlasPeerQueueLocked",
"(",
"peer_queue",
")",
"as",
"pq",
":",
"while",
"len",
"(",
"pq",
")",
">",
"0",
":",
"peers",
".",
"append",
"(",
"pq"... | Get all queued peers | [
"Get",
"all",
"queued",
"peers"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L2524-L2534 |
244,271 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_zonefile_push_enqueue | def atlas_zonefile_push_enqueue( zonefile_hash, name, txid, zonefile_data, zonefile_queue=None, con=None, path=None ):
"""
Enqueue the given zonefile into our "push" queue,
from which it will be replicated to storage and sent
out to other peers who don't have it.
Return True if we enqueued it
R... | python | def atlas_zonefile_push_enqueue( zonefile_hash, name, txid, zonefile_data, zonefile_queue=None, con=None, path=None ):
res = False
bits = atlasdb_get_zonefile_bits( zonefile_hash, path=path, con=con )
if len(bits) == 0:
# invalid hash
return
with AtlasZonefileQueueLocked(zonefile_queue... | [
"def",
"atlas_zonefile_push_enqueue",
"(",
"zonefile_hash",
",",
"name",
",",
"txid",
",",
"zonefile_data",
",",
"zonefile_queue",
"=",
"None",
",",
"con",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"res",
"=",
"False",
"bits",
"=",
"atlasdb_get_zonefi... | Enqueue the given zonefile into our "push" queue,
from which it will be replicated to storage and sent
out to other peers who don't have it.
Return True if we enqueued it
Return False if not | [
"Enqueue",
"the",
"given",
"zonefile",
"into",
"our",
"push",
"queue",
"from",
"which",
"it",
"will",
"be",
"replicated",
"to",
"storage",
"and",
"sent",
"out",
"to",
"other",
"peers",
"who",
"don",
"t",
"have",
"it",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L2560-L2589 |
244,272 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_zonefile_push_dequeue | def atlas_zonefile_push_dequeue( zonefile_queue=None ):
"""
Dequeue a zonefile's information to replicate
Return None if there are none queued
"""
ret = None
with AtlasZonefileQueueLocked(zonefile_queue) as zfq:
if len(zfq) > 0:
ret = zfq.pop(0)
return ret | python | def atlas_zonefile_push_dequeue( zonefile_queue=None ):
ret = None
with AtlasZonefileQueueLocked(zonefile_queue) as zfq:
if len(zfq) > 0:
ret = zfq.pop(0)
return ret | [
"def",
"atlas_zonefile_push_dequeue",
"(",
"zonefile_queue",
"=",
"None",
")",
":",
"ret",
"=",
"None",
"with",
"AtlasZonefileQueueLocked",
"(",
"zonefile_queue",
")",
"as",
"zfq",
":",
"if",
"len",
"(",
"zfq",
")",
">",
"0",
":",
"ret",
"=",
"zfq",
".",
... | Dequeue a zonefile's information to replicate
Return None if there are none queued | [
"Dequeue",
"a",
"zonefile",
"s",
"information",
"to",
"replicate",
"Return",
"None",
"if",
"there",
"are",
"none",
"queued"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L2592-L2602 |
244,273 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_zonefile_push | def atlas_zonefile_push( my_hostport, peer_hostport, zonefile_data, timeout=None, peer_table=None ):
"""
Push the given zonefile to the given peer
Return True on success
Return False on failure
"""
if timeout is None:
timeout = atlas_push_zonefiles_timeout()
zonefile_hash = get_z... | python | def atlas_zonefile_push( my_hostport, peer_hostport, zonefile_data, timeout=None, peer_table=None ):
if timeout is None:
timeout = atlas_push_zonefiles_timeout()
zonefile_hash = get_zonefile_data_hash(zonefile_data)
zonefile_data_b64 = base64.b64encode( zonefile_data )
host, port = url_to_h... | [
"def",
"atlas_zonefile_push",
"(",
"my_hostport",
",",
"peer_hostport",
",",
"zonefile_data",
",",
"timeout",
"=",
"None",
",",
"peer_table",
"=",
"None",
")",
":",
"if",
"timeout",
"is",
"None",
":",
"timeout",
"=",
"atlas_push_zonefiles_timeout",
"(",
")",
"... | Push the given zonefile to the given peer
Return True on success
Return False on failure | [
"Push",
"the",
"given",
"zonefile",
"to",
"the",
"given",
"peer",
"Return",
"True",
"on",
"success",
"Return",
"False",
"on",
"failure"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L2605-L2646 |
244,274 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_node_init | def atlas_node_init(my_hostname, my_portnum, atlasdb_path, zonefile_dir, working_dir):
"""
Start up the atlas node.
Return a bundle of atlas state
"""
atlas_state = {}
atlas_state['peer_crawler'] = AtlasPeerCrawler(my_hostname, my_portnum, atlasdb_path, working_dir)
atlas_state['health_check... | python | def atlas_node_init(my_hostname, my_portnum, atlasdb_path, zonefile_dir, working_dir):
atlas_state = {}
atlas_state['peer_crawler'] = AtlasPeerCrawler(my_hostname, my_portnum, atlasdb_path, working_dir)
atlas_state['health_checker'] = AtlasHealthChecker(my_hostname, my_portnum, atlasdb_path)
atlas_state... | [
"def",
"atlas_node_init",
"(",
"my_hostname",
",",
"my_portnum",
",",
"atlasdb_path",
",",
"zonefile_dir",
",",
"working_dir",
")",
":",
"atlas_state",
"=",
"{",
"}",
"atlas_state",
"[",
"'peer_crawler'",
"]",
"=",
"AtlasPeerCrawler",
"(",
"my_hostname",
",",
"m... | Start up the atlas node.
Return a bundle of atlas state | [
"Start",
"up",
"the",
"atlas",
"node",
".",
"Return",
"a",
"bundle",
"of",
"atlas",
"state"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L3584-L3595 |
244,275 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_node_start | def atlas_node_start(atlas_state):
"""
Start up atlas threads
"""
for component in atlas_state.keys():
log.debug("Starting Atlas component '%s'" % component)
atlas_state[component].start() | python | def atlas_node_start(atlas_state):
for component in atlas_state.keys():
log.debug("Starting Atlas component '%s'" % component)
atlas_state[component].start() | [
"def",
"atlas_node_start",
"(",
"atlas_state",
")",
":",
"for",
"component",
"in",
"atlas_state",
".",
"keys",
"(",
")",
":",
"log",
".",
"debug",
"(",
"\"Starting Atlas component '%s'\"",
"%",
"component",
")",
"atlas_state",
"[",
"component",
"]",
".",
"star... | Start up atlas threads | [
"Start",
"up",
"atlas",
"threads"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L3597-L3603 |
244,276 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_node_add_callback | def atlas_node_add_callback(atlas_state, callback_name, callback):
"""
Add a callback to the initialized atlas state
"""
if callback_name == 'store_zonefile':
atlas_state['zonefile_crawler'].set_store_zonefile_callback(callback)
else:
raise ValueError("Unrecognized callback {}".form... | python | def atlas_node_add_callback(atlas_state, callback_name, callback):
if callback_name == 'store_zonefile':
atlas_state['zonefile_crawler'].set_store_zonefile_callback(callback)
else:
raise ValueError("Unrecognized callback {}".format(callback_name)) | [
"def",
"atlas_node_add_callback",
"(",
"atlas_state",
",",
"callback_name",
",",
"callback",
")",
":",
"if",
"callback_name",
"==",
"'store_zonefile'",
":",
"atlas_state",
"[",
"'zonefile_crawler'",
"]",
".",
"set_store_zonefile_callback",
"(",
"callback",
")",
"else"... | Add a callback to the initialized atlas state | [
"Add",
"a",
"callback",
"to",
"the",
"initialized",
"atlas",
"state"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L3606-L3614 |
244,277 | blockstack/blockstack-core | blockstack/lib/atlas.py | atlas_node_stop | def atlas_node_stop( atlas_state ):
"""
Stop the atlas node threads
"""
for component in atlas_state.keys():
log.debug("Stopping Atlas component '%s'" % component)
atlas_state[component].ask_join()
atlas_state[component].join()
return True | python | def atlas_node_stop( atlas_state ):
for component in atlas_state.keys():
log.debug("Stopping Atlas component '%s'" % component)
atlas_state[component].ask_join()
atlas_state[component].join()
return True | [
"def",
"atlas_node_stop",
"(",
"atlas_state",
")",
":",
"for",
"component",
"in",
"atlas_state",
".",
"keys",
"(",
")",
":",
"log",
".",
"debug",
"(",
"\"Stopping Atlas component '%s'\"",
"%",
"component",
")",
"atlas_state",
"[",
"component",
"]",
".",
"ask_j... | Stop the atlas node threads | [
"Stop",
"the",
"atlas",
"node",
"threads"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L3617-L3626 |
244,278 | blockstack/blockstack-core | blockstack/lib/atlas.py | AtlasPeerCrawler.canonical_peer | def canonical_peer( self, peer ):
"""
Get the canonical peer name
"""
their_host, their_port = url_to_host_port( peer )
if their_host in ['127.0.0.1', '::1']:
their_host = 'localhost'
return "%s:%s" % (their_host, their_port) | python | def canonical_peer( self, peer ):
their_host, their_port = url_to_host_port( peer )
if their_host in ['127.0.0.1', '::1']:
their_host = 'localhost'
return "%s:%s" % (their_host, their_port) | [
"def",
"canonical_peer",
"(",
"self",
",",
"peer",
")",
":",
"their_host",
",",
"their_port",
"=",
"url_to_host_port",
"(",
"peer",
")",
"if",
"their_host",
"in",
"[",
"'127.0.0.1'",
",",
"'::1'",
"]",
":",
"their_host",
"=",
"'localhost'",
"return",
"\"%s:%... | Get the canonical peer name | [
"Get",
"the",
"canonical",
"peer",
"name"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L2713-L2722 |
244,279 | blockstack/blockstack-core | blockstack/lib/atlas.py | AtlasPeerCrawler.remove_unhealthy_peers | def remove_unhealthy_peers( self, count, con=None, path=None, peer_table=None, min_request_count=10, min_health=MIN_PEER_HEALTH ):
"""
Remove up to @count unhealthy peers
Return the list of peers we removed
"""
if path is None:
path = self.atlasdb_path
... | python | def remove_unhealthy_peers( self, count, con=None, path=None, peer_table=None, min_request_count=10, min_health=MIN_PEER_HEALTH ):
if path is None:
path = self.atlasdb_path
removed = []
rank_peer_list = atlas_rank_peers_by_health( peer_table=peer_table, with_rank=True )
for ... | [
"def",
"remove_unhealthy_peers",
"(",
"self",
",",
"count",
",",
"con",
"=",
"None",
",",
"path",
"=",
"None",
",",
"peer_table",
"=",
"None",
",",
"min_request_count",
"=",
"10",
",",
"min_health",
"=",
"MIN_PEER_HEALTH",
")",
":",
"if",
"path",
"is",
"... | Remove up to @count unhealthy peers
Return the list of peers we removed | [
"Remove",
"up",
"to"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L2836-L2860 |
244,280 | blockstack/blockstack-core | blockstack/lib/atlas.py | AtlasPeerCrawler.get_current_peers | def get_current_peers( self, peer_table=None ):
"""
Get the current set of peers
"""
# get current peers
current_peers = None
with AtlasPeerTableLocked(peer_table) as ptbl:
current_peers = ptbl.keys()[:]
return current_peers | python | def get_current_peers( self, peer_table=None ):
# get current peers
current_peers = None
with AtlasPeerTableLocked(peer_table) as ptbl:
current_peers = ptbl.keys()[:]
return current_peers | [
"def",
"get_current_peers",
"(",
"self",
",",
"peer_table",
"=",
"None",
")",
":",
"# get current peers",
"current_peers",
"=",
"None",
"with",
"AtlasPeerTableLocked",
"(",
"peer_table",
")",
"as",
"ptbl",
":",
"current_peers",
"=",
"ptbl",
".",
"keys",
"(",
"... | Get the current set of peers | [
"Get",
"the",
"current",
"set",
"of",
"peers"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L2945-L2955 |
244,281 | blockstack/blockstack-core | blockstack/lib/atlas.py | AtlasPeerCrawler.canonical_new_peer_list | def canonical_new_peer_list( self, peers_to_add ):
"""
Make a list of canonical new peers, using the
self.new_peers and the given peers to add
Return a shuffled list of canonicalized host:port
strings.
"""
new_peers = list(set(self.new_peers + peers_to_add))
... | python | def canonical_new_peer_list( self, peers_to_add ):
new_peers = list(set(self.new_peers + peers_to_add))
random.shuffle( new_peers )
# canonicalize
tmp = []
for peer in new_peers:
tmp.append( self.canonical_peer(peer) )
new_peers = tmp
# don'... | [
"def",
"canonical_new_peer_list",
"(",
"self",
",",
"peers_to_add",
")",
":",
"new_peers",
"=",
"list",
"(",
"set",
"(",
"self",
".",
"new_peers",
"+",
"peers_to_add",
")",
")",
"random",
".",
"shuffle",
"(",
"new_peers",
")",
"# canonicalize",
"tmp",
"=",
... | Make a list of canonical new peers, using the
self.new_peers and the given peers to add
Return a shuffled list of canonicalized host:port
strings. | [
"Make",
"a",
"list",
"of",
"canonical",
"new",
"peers",
"using",
"the",
"self",
".",
"new_peers",
"and",
"the",
"given",
"peers",
"to",
"add"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L2958-L2980 |
244,282 | blockstack/blockstack-core | blockstack/lib/atlas.py | AtlasHealthChecker.step | def step(self, con=None, path=None, peer_table=None, local_inv=None):
"""
Find peers with stale zonefile inventory data,
and refresh them.
Return True on success
Return False on error
"""
if path is None:
path = self.atlasdb_path
peer_hostpor... | python | def step(self, con=None, path=None, peer_table=None, local_inv=None):
if path is None:
path = self.atlasdb_path
peer_hostports = []
stale_peers = []
num_peers = None
peer_hostports = None
with AtlasPeerTableLocked(peer_table) as ptbl:
num_peers ... | [
"def",
"step",
"(",
"self",
",",
"con",
"=",
"None",
",",
"path",
"=",
"None",
",",
"peer_table",
"=",
"None",
",",
"local_inv",
"=",
"None",
")",
":",
"if",
"path",
"is",
"None",
":",
"path",
"=",
"self",
".",
"atlasdb_path",
"peer_hostports",
"=",
... | Find peers with stale zonefile inventory data,
and refresh them.
Return True on success
Return False on error | [
"Find",
"peers",
"with",
"stale",
"zonefile",
"inventory",
"data",
"and",
"refresh",
"them",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L3171-L3210 |
244,283 | blockstack/blockstack-core | blockstack/lib/atlas.py | AtlasHealthChecker.run | def run(self, peer_table=None):
"""
Loop forever, pinging someone every pass.
"""
self.running = True
while self.running:
local_inv = atlas_get_zonefile_inventory()
t1 = time_now()
self.step( peer_table=peer_table, local_inv=local_inv, path=sel... | python | def run(self, peer_table=None):
self.running = True
while self.running:
local_inv = atlas_get_zonefile_inventory()
t1 = time_now()
self.step( peer_table=peer_table, local_inv=local_inv, path=self.atlasdb_path )
t2 = time_now()
# don't go too f... | [
"def",
"run",
"(",
"self",
",",
"peer_table",
"=",
"None",
")",
":",
"self",
".",
"running",
"=",
"True",
"while",
"self",
".",
"running",
":",
"local_inv",
"=",
"atlas_get_zonefile_inventory",
"(",
")",
"t1",
"=",
"time_now",
"(",
")",
"self",
".",
"s... | Loop forever, pinging someone every pass. | [
"Loop",
"forever",
"pinging",
"someone",
"every",
"pass",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L3213-L3231 |
244,284 | blockstack/blockstack-core | blockstack/lib/atlas.py | AtlasZonefileCrawler.set_zonefile_present | def set_zonefile_present(self, zfhash, block_height, con=None, path=None):
"""
Set a zonefile as present, and if it was previously absent, inform the storage listener
"""
was_present = atlasdb_set_zonefile_present( zfhash, True, con=con, path=path )
# tell anyone who cares that ... | python | def set_zonefile_present(self, zfhash, block_height, con=None, path=None):
was_present = atlasdb_set_zonefile_present( zfhash, True, con=con, path=path )
# tell anyone who cares that we got this zone file, if it was new
if not was_present and self.store_zonefile_cb:
log.debug('{} w... | [
"def",
"set_zonefile_present",
"(",
"self",
",",
"zfhash",
",",
"block_height",
",",
"con",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"was_present",
"=",
"atlasdb_set_zonefile_present",
"(",
"zfhash",
",",
"True",
",",
"con",
"=",
"con",
",",
"path"... | Set a zonefile as present, and if it was previously absent, inform the storage listener | [
"Set",
"a",
"zonefile",
"as",
"present",
"and",
"if",
"it",
"was",
"previously",
"absent",
"inform",
"the",
"storage",
"listener"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L3257-L3268 |
244,285 | blockstack/blockstack-core | blockstack/lib/atlas.py | AtlasZonefileCrawler.find_zonefile_origins | def find_zonefile_origins( self, missing_zfinfo, peer_hostports ):
"""
Find out which peers can serve which zonefiles
"""
zonefile_origins = {} # map peer hostport to list of zonefile hashes
# which peers can serve each zonefile?
for zfhash in missing_zfinfo.keys():
... | python | def find_zonefile_origins( self, missing_zfinfo, peer_hostports ):
zonefile_origins = {} # map peer hostport to list of zonefile hashes
# which peers can serve each zonefile?
for zfhash in missing_zfinfo.keys():
for peer_hostport in peer_hostports:
if not zonefile_... | [
"def",
"find_zonefile_origins",
"(",
"self",
",",
"missing_zfinfo",
",",
"peer_hostports",
")",
":",
"zonefile_origins",
"=",
"{",
"}",
"# map peer hostport to list of zonefile hashes",
"# which peers can serve each zonefile?",
"for",
"zfhash",
"in",
"missing_zfinfo",
".",
... | Find out which peers can serve which zonefiles | [
"Find",
"out",
"which",
"peers",
"can",
"serve",
"which",
"zonefiles"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L3316-L3331 |
244,286 | blockstack/blockstack-core | blockstack/lib/atlas.py | AtlasZonefilePusher.step | def step( self, peer_table=None, zonefile_queue=None, path=None ):
"""
Run one step of this algorithm.
Push the zonefile to all the peers that need it.
Return the number of peers we sent to
"""
if path is None:
path = self.atlasdb_path
if BLOCKSTACK_T... | python | def step( self, peer_table=None, zonefile_queue=None, path=None ):
if path is None:
path = self.atlasdb_path
if BLOCKSTACK_TEST:
log.debug("%s: %s step" % (self.hostport, self.__class__.__name__))
if self.push_timeout is None:
self.push_timeout = atlas_push_... | [
"def",
"step",
"(",
"self",
",",
"peer_table",
"=",
"None",
",",
"zonefile_queue",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"if",
"path",
"is",
"None",
":",
"path",
"=",
"self",
".",
"atlasdb_path",
"if",
"BLOCKSTACK_TEST",
":",
"log",
".",
"... | Run one step of this algorithm.
Push the zonefile to all the peers that need it.
Return the number of peers we sent to | [
"Run",
"one",
"step",
"of",
"this",
"algorithm",
".",
"Push",
"the",
"zonefile",
"to",
"all",
"the",
"peers",
"that",
"need",
"it",
".",
"Return",
"the",
"number",
"of",
"peers",
"we",
"sent",
"to"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/atlas.py#L3509-L3561 |
244,287 | blockstack/blockstack-core | blockstack/lib/queue.py | queuedb_create | def queuedb_create(path):
"""
Create a sqlite3 db at the given path.
Create all the tables and indexes we need.
Raises if the table already exists
"""
global QUEUE_SQL, ERROR_SQL
lines = [l + ";" for l in QUEUE_SQL.split(";")]
con = sqlite3.connect( path, isolation_level=None )
db_... | python | def queuedb_create(path):
global QUEUE_SQL, ERROR_SQL
lines = [l + ";" for l in QUEUE_SQL.split(";")]
con = sqlite3.connect( path, isolation_level=None )
db_query_execute(con, 'pragma mmap_size=536870912', ())
for line in lines:
db_query_execute(con, line, ())
con.commit()
con.row_... | [
"def",
"queuedb_create",
"(",
"path",
")",
":",
"global",
"QUEUE_SQL",
",",
"ERROR_SQL",
"lines",
"=",
"[",
"l",
"+",
"\";\"",
"for",
"l",
"in",
"QUEUE_SQL",
".",
"split",
"(",
"\";\"",
")",
"]",
"con",
"=",
"sqlite3",
".",
"connect",
"(",
"path",
",... | Create a sqlite3 db at the given path.
Create all the tables and indexes we need.
Raises if the table already exists | [
"Create",
"a",
"sqlite3",
"db",
"at",
"the",
"given",
"path",
".",
"Create",
"all",
"the",
"tables",
"and",
"indexes",
"we",
"need",
".",
"Raises",
"if",
"the",
"table",
"already",
"exists"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/queue.py#L46-L63 |
244,288 | blockstack/blockstack-core | blockstack/lib/queue.py | queuedb_row_factory | def queuedb_row_factory(cursor, row):
"""
Dict row factory
"""
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d | python | def queuedb_row_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d | [
"def",
"queuedb_row_factory",
"(",
"cursor",
",",
"row",
")",
":",
"d",
"=",
"{",
"}",
"for",
"idx",
",",
"col",
"in",
"enumerate",
"(",
"cursor",
".",
"description",
")",
":",
"d",
"[",
"col",
"[",
"0",
"]",
"]",
"=",
"row",
"[",
"idx",
"]",
"... | Dict row factory | [
"Dict",
"row",
"factory"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/queue.py#L75-L83 |
244,289 | blockstack/blockstack-core | blockstack/lib/queue.py | queuedb_findall | def queuedb_findall(path, queue_id, name=None, offset=None, limit=None):
"""
Get all queued entries for a queue and a name.
If name is None, then find all queue entries
Return the rows on success (empty list if not found)
Raise on error
"""
sql = "SELECT * FROM queue WHERE queue_id = ? ORDE... | python | def queuedb_findall(path, queue_id, name=None, offset=None, limit=None):
sql = "SELECT * FROM queue WHERE queue_id = ? ORDER BY rowid ASC"
args = (queue_id,)
if name:
sql += ' AND name = ?'
args += (name,)
if limit:
sql += ' LIMIT ?'
args += (limit,)
if off... | [
"def",
"queuedb_findall",
"(",
"path",
",",
"queue_id",
",",
"name",
"=",
"None",
",",
"offset",
"=",
"None",
",",
"limit",
"=",
"None",
")",
":",
"sql",
"=",
"\"SELECT * FROM queue WHERE queue_id = ? ORDER BY rowid ASC\"",
"args",
"=",
"(",
"queue_id",
",",
"... | Get all queued entries for a queue and a name.
If name is None, then find all queue entries
Return the rows on success (empty list if not found)
Raise on error | [
"Get",
"all",
"queued",
"entries",
"for",
"a",
"queue",
"and",
"a",
"name",
".",
"If",
"name",
"is",
"None",
"then",
"find",
"all",
"queue",
"entries"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/queue.py#L103-L143 |
244,290 | blockstack/blockstack-core | blockstack/lib/queue.py | queuedb_append | def queuedb_append(path, queue_id, name, data):
"""
Append an element to the back of the queue.
Return True on success
Raise on error
"""
sql = "INSERT INTO queue VALUES (?,?,?);"
args = (name, queue_id, data)
db = queuedb_open(path)
if db is None:
raise Exception("Failed to... | python | def queuedb_append(path, queue_id, name, data):
sql = "INSERT INTO queue VALUES (?,?,?);"
args = (name, queue_id, data)
db = queuedb_open(path)
if db is None:
raise Exception("Failed to open %s" % path)
cur = db.cursor()
res = queuedb_query_execute(cur, sql, args)
db.commit()
... | [
"def",
"queuedb_append",
"(",
"path",
",",
"queue_id",
",",
"name",
",",
"data",
")",
":",
"sql",
"=",
"\"INSERT INTO queue VALUES (?,?,?);\"",
"args",
"=",
"(",
"name",
",",
"queue_id",
",",
"data",
")",
"db",
"=",
"queuedb_open",
"(",
"path",
")",
"if",
... | Append an element to the back of the queue.
Return True on success
Raise on error | [
"Append",
"an",
"element",
"to",
"the",
"back",
"of",
"the",
"queue",
".",
"Return",
"True",
"on",
"success",
"Raise",
"on",
"error"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/queue.py#L146-L164 |
244,291 | blockstack/blockstack-core | blockstack/lib/queue.py | queuedb_remove | def queuedb_remove(path, entry, cur=None):
"""
Remove an element from a queue.
Return True on success
Raise on error
"""
sql = "DELETE FROM queue WHERE queue_id = ? AND name = ?;"
args = (entry['queue_id'], entry['name'])
cursor = None
if cur:
cursor = cur
else:
... | python | def queuedb_remove(path, entry, cur=None):
sql = "DELETE FROM queue WHERE queue_id = ? AND name = ?;"
args = (entry['queue_id'], entry['name'])
cursor = None
if cur:
cursor = cur
else:
db = queuedb_open(path)
if db is None:
raise Exception("Failed to open %s" % p... | [
"def",
"queuedb_remove",
"(",
"path",
",",
"entry",
",",
"cur",
"=",
"None",
")",
":",
"sql",
"=",
"\"DELETE FROM queue WHERE queue_id = ? AND name = ?;\"",
"args",
"=",
"(",
"entry",
"[",
"'queue_id'",
"]",
",",
"entry",
"[",
"'name'",
"]",
")",
"cursor",
"... | Remove an element from a queue.
Return True on success
Raise on error | [
"Remove",
"an",
"element",
"from",
"a",
"queue",
".",
"Return",
"True",
"on",
"success",
"Raise",
"on",
"error"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/queue.py#L167-L192 |
244,292 | blockstack/blockstack-core | blockstack/lib/queue.py | queuedb_removeall | def queuedb_removeall(path, entries):
"""
Remove all entries from a queue
"""
db = queuedb_open(path)
if db is None:
raise Exception("Failed to open %s" % path)
cursor = db.cursor()
queuedb_query_execute(cursor, 'BEGIN', ())
for entry in entries:
queuedb_remove(path, en... | python | def queuedb_removeall(path, entries):
db = queuedb_open(path)
if db is None:
raise Exception("Failed to open %s" % path)
cursor = db.cursor()
queuedb_query_execute(cursor, 'BEGIN', ())
for entry in entries:
queuedb_remove(path, entry, cur=cursor)
queuedb_query_execute(cursor, ... | [
"def",
"queuedb_removeall",
"(",
"path",
",",
"entries",
")",
":",
"db",
"=",
"queuedb_open",
"(",
"path",
")",
"if",
"db",
"is",
"None",
":",
"raise",
"Exception",
"(",
"\"Failed to open %s\"",
"%",
"path",
")",
"cursor",
"=",
"db",
".",
"cursor",
"(",
... | Remove all entries from a queue | [
"Remove",
"all",
"entries",
"from",
"a",
"queue"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/queue.py#L195-L213 |
244,293 | blockstack/blockstack-core | blockstack/lib/operations/register.py | check_payment_in_stacks | def check_payment_in_stacks(state_engine, nameop, state_op_type, fee_block_id):
"""
Verify that if tokens were paid for a name priced in BTC, that enough were paid.
Does not check account balances or namespace types; it only inspects the transaction data.
Returns {'status': True, 'tokens_paid': ..., 't... | python | def check_payment_in_stacks(state_engine, nameop, state_op_type, fee_block_id):
name = nameop['name']
namespace_id = get_namespace_from_name(name)
name_without_namespace = get_name_from_fq_name(name)
namespace = state_engine.get_namespace( namespace_id )
stacks_payment_info = get_stacks_payment(sta... | [
"def",
"check_payment_in_stacks",
"(",
"state_engine",
",",
"nameop",
",",
"state_op_type",
",",
"fee_block_id",
")",
":",
"name",
"=",
"nameop",
"[",
"'name'",
"]",
"namespace_id",
"=",
"get_namespace_from_name",
"(",
"name",
")",
"name_without_namespace",
"=",
"... | Verify that if tokens were paid for a name priced in BTC, that enough were paid.
Does not check account balances or namespace types; it only inspects the transaction data.
Returns {'status': True, 'tokens_paid': ..., 'token_units': ...} on success
Returns {'status': False} on error | [
"Verify",
"that",
"if",
"tokens",
"were",
"paid",
"for",
"a",
"name",
"priced",
"in",
"BTC",
"that",
"enough",
"were",
"paid",
".",
"Does",
"not",
"check",
"account",
"balances",
"or",
"namespace",
"types",
";",
"it",
"only",
"inspects",
"the",
"transactio... | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/operations/register.py#L201-L228 |
244,294 | blockstack/blockstack-core | blockstack/lib/operations/register.py | check_payment | def check_payment(state_engine, state_op_type, nameop, fee_block_id, token_address, burn_address, name_fee, block_id):
"""
Verify that the right payment was made, in the right cryptocurrency units.
Does not check any accounts or modify the nameop in any way; it only checks that the name was paid for by the ... | python | def check_payment(state_engine, state_op_type, nameop, fee_block_id, token_address, burn_address, name_fee, block_id):
assert state_op_type in ['NAME_REGISTRATION', 'NAME_RENEWAL'], 'Invalid op type {}'.format(state_op_type)
assert name_fee is not None
assert isinstance(name_fee, (int,long))
name = na... | [
"def",
"check_payment",
"(",
"state_engine",
",",
"state_op_type",
",",
"nameop",
",",
"fee_block_id",
",",
"token_address",
",",
"burn_address",
",",
"name_fee",
",",
"block_id",
")",
":",
"assert",
"state_op_type",
"in",
"[",
"'NAME_REGISTRATION'",
",",
"'NAME_R... | Verify that the right payment was made, in the right cryptocurrency units.
Does not check any accounts or modify the nameop in any way; it only checks that the name was paid for by the transaction.
NOTE: if state_op_type is NAME_REGISTRATION, you will need to have called state_create_put_preorder() before call... | [
"Verify",
"that",
"the",
"right",
"payment",
"was",
"made",
"in",
"the",
"right",
"cryptocurrency",
"units",
".",
"Does",
"not",
"check",
"any",
"accounts",
"or",
"modify",
"the",
"nameop",
"in",
"any",
"way",
";",
"it",
"only",
"checks",
"that",
"the",
... | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/operations/register.py#L405-L448 |
244,295 | blockstack/blockstack-core | blockstack/lib/operations/namespacepreorder.py | check | def check( state_engine, nameop, block_id, checked_ops ):
"""
Given a NAMESPACE_PREORDER nameop, see if we can preorder it.
It must be unqiue.
Return True if accepted.
Return False if not.
"""
namespace_id_hash = nameop['preorder_hash']
consensus_hash = nameop['consensus_hash']
tok... | python | def check( state_engine, nameop, block_id, checked_ops ):
namespace_id_hash = nameop['preorder_hash']
consensus_hash = nameop['consensus_hash']
token_fee = nameop['token_fee']
# cannot be preordered already
if not state_engine.is_new_namespace_preorder( namespace_id_hash ):
log.warning("Nam... | [
"def",
"check",
"(",
"state_engine",
",",
"nameop",
",",
"block_id",
",",
"checked_ops",
")",
":",
"namespace_id_hash",
"=",
"nameop",
"[",
"'preorder_hash'",
"]",
"consensus_hash",
"=",
"nameop",
"[",
"'consensus_hash'",
"]",
"token_fee",
"=",
"nameop",
"[",
... | Given a NAMESPACE_PREORDER nameop, see if we can preorder it.
It must be unqiue.
Return True if accepted.
Return False if not. | [
"Given",
"a",
"NAMESPACE_PREORDER",
"nameop",
"see",
"if",
"we",
"can",
"preorder",
"it",
".",
"It",
"must",
"be",
"unqiue",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/operations/namespacepreorder.py#L53-L134 |
244,296 | blockstack/blockstack-core | blockstack/lib/fast_sync.py | snapshot_peek_number | def snapshot_peek_number( fd, off ):
"""
Read the last 8 bytes of fd
and interpret it as an int.
"""
# read number of 8 bytes
fd.seek( off - 8, os.SEEK_SET )
value_hex = fd.read(8)
if len(value_hex) != 8:
return None
try:
value = int(value_hex, 16)
except ValueEr... | python | def snapshot_peek_number( fd, off ):
# read number of 8 bytes
fd.seek( off - 8, os.SEEK_SET )
value_hex = fd.read(8)
if len(value_hex) != 8:
return None
try:
value = int(value_hex, 16)
except ValueError:
return None
return value | [
"def",
"snapshot_peek_number",
"(",
"fd",
",",
"off",
")",
":",
"# read number of 8 bytes ",
"fd",
".",
"seek",
"(",
"off",
"-",
"8",
",",
"os",
".",
"SEEK_SET",
")",
"value_hex",
"=",
"fd",
".",
"read",
"(",
"8",
")",
"if",
"len",
"(",
"value_hex",
... | Read the last 8 bytes of fd
and interpret it as an int. | [
"Read",
"the",
"last",
"8",
"bytes",
"of",
"fd",
"and",
"interpret",
"it",
"as",
"an",
"int",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/fast_sync.py#L52-L67 |
244,297 | blockstack/blockstack-core | blockstack/lib/fast_sync.py | get_file_hash | def get_file_hash( fd, hashfunc, fd_len=None ):
"""
Get the hex-encoded hash of the fd's data
"""
h = hashfunc()
fd.seek(0, os.SEEK_SET)
count = 0
while True:
buf = fd.read(65536)
if len(buf) == 0:
break
if fd_len is not None:
if count + len... | python | def get_file_hash( fd, hashfunc, fd_len=None ):
h = hashfunc()
fd.seek(0, os.SEEK_SET)
count = 0
while True:
buf = fd.read(65536)
if len(buf) == 0:
break
if fd_len is not None:
if count + len(buf) > fd_len:
buf = buf[:fd_len - count]
... | [
"def",
"get_file_hash",
"(",
"fd",
",",
"hashfunc",
",",
"fd_len",
"=",
"None",
")",
":",
"h",
"=",
"hashfunc",
"(",
")",
"fd",
".",
"seek",
"(",
"0",
",",
"os",
".",
"SEEK_SET",
")",
"count",
"=",
"0",
"while",
"True",
":",
"buf",
"=",
"fd",
"... | Get the hex-encoded hash of the fd's data | [
"Get",
"the",
"hex",
"-",
"encoded",
"hash",
"of",
"the",
"fd",
"s",
"data"
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/fast_sync.py#L89-L111 |
244,298 | blockstack/blockstack-core | blockstack/lib/fast_sync.py | fast_sync_sign_snapshot | def fast_sync_sign_snapshot( snapshot_path, private_key, first=False ):
"""
Append a signature to the end of a snapshot path
with the given private key.
If first is True, then don't expect the signature trailer.
Return True on success
Return False on error
"""
if not os.path.exists... | python | def fast_sync_sign_snapshot( snapshot_path, private_key, first=False ):
if not os.path.exists(snapshot_path):
log.error("No such file or directory: {}".format(snapshot_path))
return False
file_size = 0
payload_size = 0
write_offset = 0
try:
sb = os.stat(snapshot_path)
... | [
"def",
"fast_sync_sign_snapshot",
"(",
"snapshot_path",
",",
"private_key",
",",
"first",
"=",
"False",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"snapshot_path",
")",
":",
"log",
".",
"error",
"(",
"\"No such file or directory: {}\"",
".",... | Append a signature to the end of a snapshot path
with the given private key.
If first is True, then don't expect the signature trailer.
Return True on success
Return False on error | [
"Append",
"a",
"signature",
"to",
"the",
"end",
"of",
"a",
"snapshot",
"path",
"with",
"the",
"given",
"private",
"key",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/fast_sync.py#L114-L180 |
244,299 | blockstack/blockstack-core | blockstack/lib/fast_sync.py | fast_sync_snapshot_compress | def fast_sync_snapshot_compress( snapshot_dir, export_path ):
"""
Given the path to a directory, compress it and export it to the
given path.
Return {'status': True} on success
Return {'error': ...} on failure
"""
snapshot_dir = os.path.abspath(snapshot_dir)
export_path = os.path.abspa... | python | def fast_sync_snapshot_compress( snapshot_dir, export_path ):
snapshot_dir = os.path.abspath(snapshot_dir)
export_path = os.path.abspath(export_path)
if os.path.exists(export_path):
return {'error': 'Snapshot path exists: {}'.format(export_path)}
old_dir = os.getcwd()
count_ref = [0]
... | [
"def",
"fast_sync_snapshot_compress",
"(",
"snapshot_dir",
",",
"export_path",
")",
":",
"snapshot_dir",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"snapshot_dir",
")",
"export_path",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"export_path",
")",
"if",
"... | Given the path to a directory, compress it and export it to the
given path.
Return {'status': True} on success
Return {'error': ...} on failure | [
"Given",
"the",
"path",
"to",
"a",
"directory",
"compress",
"it",
"and",
"export",
"it",
"to",
"the",
"given",
"path",
"."
] | 1dcfdd39b152d29ce13e736a6a1a0981401a0505 | https://github.com/blockstack/blockstack-core/blob/1dcfdd39b152d29ce13e736a6a1a0981401a0505/blockstack/lib/fast_sync.py#L183-L220 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.